Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here
Tips & Pointers

Building a Continuous Temperature Logger with the EnviroDIY Mayfly

This post and all related materials are also available on GitHub.
[toc]

Introduction

This document outlines what you will need to build a Continuous Temperature Logger with the EnviroDIY Mayfly Data Logger. This is a great EnviroDIY starter project and utilizes the Mayfly Data Logger and a OneWire Temperature Sensor.

Many of the instructions used in this document are based on the EnviroDIY Monitoring Station Manual but you can adjust your set up based on your comfort level or budget. It is meant to be simple and clear for new users but those with more experience can adapt and improve on the set up and installation.

It does not utilize the XBee cellular module which means that it will not offer real-time data via the Monitor My Watershed portal. All data is saved to the on-board micro-SD card and can be uploaded manually if you choose to do so.

Hardware

Starter Kit

The Mayfly Starter Kit supplies you with the essential components for building your own data logger. Stroud Water Research Center offers this kit through Amazon for about $90 plus shipping cost.

The Starter Kit includes the following items:

  • EnviroDIY Mayfly Data Logger Board
  • Waterproof enclosure with clear lid
  • microUSB programming cable (1-meter long)
  • Grove cables (20 cm long)
  • 4 GB micro SD memory card with SD card size adapter
  • 0.5 watt solar panel with JST connector
  • Mayfly micro SD vertical adapter board

Some additional items will need to be purchased separately from the Starter Kit to make this example logger fully operational:

Real-Time Clock Battery

The real-time clock battery is a small 3 volt button cell battery (like a watch battery) that helps the Mayfly retain the data and time when external power (Li-Po battery or USB) has been removed from the board.

You will need to install a CR1220 battery for the real-time clock on your Mayfly board by sliding it into the circular metal battery holder located on the board. Make sure that the orientation of the polarity (+ and -) is correct so the board is not damaged.

3.7 Volt Lithium Polymer Battery

If you plan to use your Mayfly while only attached to a computer, you will not need to have an external battery. You can simply power your Mayfly through the built in USB connection.

If you plan to install your Mayfly out in the field, it is important to select a battery with enough storage capacity to operate for a period of time without being charged or with very little opportunity to charge). This is important for installation sites that are well shaded or receive partial sunlight during the day (forests, shaded slopes, or valleys).

The battery will need to have a two-pin JST-PH connector. This is a small (2 mm) connector with a key or ridge on one side that mates with the connector on the Mayfly (see Assembling the Mayfly Data Logger).

It is important to look at the polarity (positive & negative) of the wires coming from the battery in relation to the polarity on the Mayfly board.

  • Each battery connector on the Mayfly will have a plus (+) and minus (-) symbol printed on the circuit board.
  • The battery will have two wires attached to the connector, a positive (red) and a negative (black).
  • These must match up when connecting the battery to the Mayfly (red + & black -) .
  • If your battery does not match up you will need to change the wires in the connector so they do.

CONNECTING A BATTERY WITH INCORRECT POLARITY CAN BE HAZARDOUS TO YOUR WELL BEING AND TO THE MAYFLY

It is also a good measure to purchase some additional JST connectors. Having a few extra will help with changing the wiring on your Li-Po batteries if you received them with the polarity reversed. They are very fragile and will become loose-fitting if care is not taken when disconnecting them from the wiring.

OneWire Temperature Sensor

Seeed Studio offers a OneWire temperature sensor that comes complete with a Grove connector, making it very simple to connect and use the sensor with little to no modification. The only downside to have a sensor pre-wired with a connector is routing it through the waterproof enclosure.

You will also need a cable gland or silicone sealant if you plan to deploy your logger in the field.

Additional Hardware

The following items are helpful but not essential to the completion of the Mayfly setup:

  • Micro SD card: If you plan to deploy the logger in the field, you may want to buy an additional micro SD card so that you can swap cards when retrieving your data.
  • Larger solar panel: Voltaic Systems sells larger solar panels if you need more power for your logger. This will also need to have a JST connector or an adapter to connect with the logger.
  • Cable glands/silicone sealer: Needed to keep the sensor cable in place and to keep moisture from entering the enclosure.

Putting It All Together

Once you have gotten this far, you can start putting the pieces together to get an idea what your set up will look like.

  • Plug the Li-Po battery into the connector marked LIPO BATTERY. There are two of them and it does not matter which one you use. The second is for supplying additional power to the XBee cellular module, which is not used in this example.
  • Plug the solar panel into the connector marked SOLAR on the Mayfly board.
  • Plug the OneWire Temperature Sensor into the Grove connector marked D4-5 on the Mayfly.
  • Insert the micro-SD card into the slot provided or into the vertical SD card adapter.

These are the basic connections you will have to make when deploying your logger. If you are not using the Mayfly in a field location and only plan to have it connected to a computer, the solar panel and Li-Po battery will not be needed.

Setting up the Arduino Desktop IDE Software

Use of the Arduino Desktop IDE will be needed to compile and upload the sketches to the Mayfly. While the process is fairly straight-forward and all of the sketches are provided for you to use and modify, you may want to take some time to explore the Arduino website to better understand the concepts explained in this document.

Detailed information on installing the Arduino software can be found on the Arduino website. There is an introduction on what Arduino is and why you would want to use it as well as many other resources available to help you get started.

Here is also the link to the EnviroDIY Monitoring Station Manual for more information regarding the Arduino Desktop IDE.

Download the Arduino IDE

You will need to download version 1.6.5 or greater. Please read the installation instructions for the corresponding operating system you are using:

Adding the EnviroDIY board to Arduino

Before getting started in the section, you should have the following items ready:

  • Arduino IDE software (installed)
  • Mayfly board (clock battery installed)
  • USB cable

First, we need to add some information to the Arduino software to tell it a little about the specifics of the board we are using. Start the Arduino software, then click on File > Preferences and paste the following URL into the text box labeled Additional Boards Manager URLs:

https://raw.githubusercontent.com/EnviroDIY/Arduino_boards/master/package_EnviroDIY_index.json

Click the “OK” button to close this window and return to the main screen when finished.

You will need to make the Mayfly the active board in the IDE by going to Tools > Board > Boards Manager from the menu of the main screen.

  • A new window will open and in the drop-down list on the top left of the screen Type > Contributed” and then type in EnviroDIY In the search bar.
  • You should see a search result for the EnviroDIY ATmega Boards. Click the “Install” button to complete your selection and click the “Close” button when it has finished.
  • Now, from the Tools > Board menu in the main window of the IDE, select the EnviroDIY Mayfly 1284P from the list of available boards.

Connecting to a Computer

Additional instructions for connecting the Mayfly to your computer can be found in the EnviroDIY Monitoring Station Manual.

  • Attach the USB cable to the Mayfly and to the computer.
  • Turn on the Mayfly using the off/on switch.
  • Select the COM Port in the Arduino software under the menu Tools > Port. You may have to wait a moment while your computer recognizes the new hardware.

Open the Serial Monitor to view the pre-loaded sketch that comes with the Mayfly by pressing the Serial Monitor button, hold Ctrl+Shift+M or select Tools > Serial Monitor from the menu. Make sure the “baud” rate option at the bottom right side of the window is set to “57600“.

Compiling and Uploading Code

This section will help you get your Mayfly set up for the temperature logging code that will run once the unit has been deployed in the field. These sketches are provided with the libraries that will be installed in each example.

Setting the Date and Time on the Real-Time Clock

One of the most important first steps that needs to be done is setting up the real-time clock (RTC) so that your timestamps in your logger data are correct. Make sure you have installed the clock battery before continuing with this section.

In the Arduino software:

  • Open up the Library Manager: Tools > Manage Libraries
  • Type “Sodaq_DS3231” in the search bar
  • Select the library named “Sodaq_DS3231
  • Click the “Install” button
  • Close this window when finished

From the menu, select File > Examples > Sodaq_DS3231 > adjust to open the example code from this library.

Look at the following line of code in the setup() function. This is where the sketch sets the time:

DateTime dt(2011, 11, 10, 15, 18, 0, 5);

This line of code translates to year, month, date, hour, min, sec and week-day(starts from 0-Sunday and goes to 6-Saturday)

  • Change the time in this line of code to be a time in the near future (about a minute or two). We will call this the “target time.”.
  • Compile and upload the sketch, by clicking the Upload button, hold Crtl+U or select Sketch > Upload from the menu.
  • Use a “reference” point like like Time.gov to view the current time. When the reference is about 3 seconds from the “target time” we set in the code, press the Reset button on the Mayfly (this gives the Mayfly a few seconds to reset itself).
  • Open the Serial Monitor by pressing the Serial Monitor button, hold Ctrl+Shift+M or select Tools > Serial Monitor from the menu. Make sure the “baud” rate option at the bottom right side of the window is set to “57600“.

  • The Serial Monitor should output the current date-time set on the Mayfly. If you are unsatisfied with the results or you missed the reference time, change the “target time” (DateTime dt()) in the code, upload the sketch to the Mayfly and try again.

At this point, the RTC is set but if you were to turn the Mayfly off and back on or press the Reset button a second time, the time would revert to the time we set in rtc.SetDateTime(dt). We want to change that line of code so that the time is NOT SET AGAIN in the setup() function.

Close the Serial Monitor and return the the line where we set the date-time (rtc.setDateTime(dt);). Use two slashes in front of the line of code so it looks like the following:

// rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above

  • Compile and upload again by clicking the Upload button, hold Crtl+U or select Sketch > Upload from then menu.
  • Open the Serial Monitor by pressing the Serial Monitor button, hold Ctrl+Shift+M or select Tools > Serial Monitor from the menu. Make sure the “baud” rate option at the bottom right side of the window is set to “57600“.
  • The Serial Monitor should continue to output the correct date and time currently set on the real-time clock.
  • When you are finished, you can close the Arduino window and select No when asked to save the file.

Testing the OneWire Temperature Sensor

If you purchased the Seeed Studio or similar OneWire temperature sensor, the following section will help you to verify that your sensor is functioning correctly.

In the Arduino software:

  • Open up the Library Manager: Tools > Manage Libraries
  • Type “DallasTemperature” in the search bar
  • Select the library named “DallasTemperature
  • Click the “Install” button
  • Close this window when finished

Plug the OneWire Temperature Sensor into the Grove port marked D4-5 on the Mayfly board.

  • From the menu select File > Examples > Dallas Temperature > tester
  • Search for the line: #define ONE_WIRE_BUS 2 in the code for the tester sketch.
  • Change this line to: #define ONE_WIRE_BUS 4
  • Upload the sketch to the Mayfly by clicking the Upload button, hold Crtl+U or select Sketch > Upload from the menu
  • Open the Serial Monitor by pressing the Serial Monitor button, hold Ctrl+Shift+M or select Tools > Serial Monitor from the menu
  • Make sure the “baud” rate option at the bottom right side of the window is set to “9600

The Serial Monitor should output the current temperature that the sensor is reading. This is also helpful in conducting QC tests to determine how accurate your sensor is.

Extra Credit
The output from the Serial Monitor scrolls by pretty quick but if you are comfortable with with making some changes, you can insert a delay(); statement in the code to slow it down.

In the first line of the loop() function, right after the first opening brace {, insert the following line of code: delay(500);. This will make the sketch wait briefly before printing the next temperature reading and make it easier to read.

  • Upload the sketch to the Mayfly by clicking the Upload button, hold Crtl+U or select Sketch > Upload from the menu
  • Open the Serial Monitor by pressing the Serial Monitor button, hold Ctrl+Shift+M or select Tools > Serial Monitor from the menu
  • Make sure the “baud” rate option at the bottom right side of the window is set to “9600

When you are finished, you can close the Arduino window and select No when asked to save the file.

Continuous Temperature Logging Code

Finally, this is the part where we get to the real world application of the Continuous Temperature Logger. Make sure that you have followed the steps for setting the real-time clock and have inserted the micro-SD card into the slot provided.

NOTE: While it may appear to be a lot more code and more complex, there is very little you will have to change to get this running. The hard part has been done and you only need to configure the data header if you plan to upload your data to MonitorMyWatershed.org.

The sketch for the Continuous Temperature Logger is currently set up to cycle through the following operations at one minute intervals:

  • Wake up the Mayfly board
  • Get the current temperature from the sensor
  • Read the current voltage of the battery
  • Read the current temperature of the Mayfly
  • Write the information to the SD card
  • Go back to sleep (to conserve power)

Go to GitHub and download the Continuous Temperature Logging code. There will be a button on the page to “Clone or Download” the repository. Click on “Download ZIP” and save the file to your computer.

You will need to extract these files to your computer before using them. If you are unsure how do this, check this link for extracting files in Windows 10. If you are using something other than Windows (MacOS or Linux), the basic concept is the same. You can do a quick Google search to find out more.

Open the file (Mayfly_ContinuousTemperatureLogger.ino) in the Arduino IDE and search for the line of code that looks like this:

This is the header information for the values that will be written to the SD card. For now, we will keep it as it is, but you will need to change the UUID codes in (and including) the braces [ ] when adding your sensors to Monitor My Watershed.

If you do not plan to upload your data to MonitorMyWatershed.org, you can leave these values as they are, but the must stay in this order unless you make further changes to the sketch.

The following libraries will need to be installed via the library manager found under Tools > Manage Libraries.

  • OneWire
  • Sodaq_DS3231
  • Sodaq_PcInt
  • RTC_Timer
  • DallasTemperature

For each library you will need to do the following:

  • In the Arduino IDE, go to Tools > Manage Libraries and type the name of the library in the search bar and press “Enter” on your keyboard.
  • Select the library found and click the “Install” button.
  • Click the Close button when you have finished installing all of the libraries.

If you want to change the interval that the Mayfly wakes up to record data, search for the following line (in the loop() function):

if(currentminute % 1 == 0) {

You can change currentminute % 1 to whatever value suits your needs. For testing purposes, it is convenient to have the time set low so you do not have to wait long for each reading. In the field you may want to increase the time to 5 or 15 minutes, depending on how precise you want your data to be.

  • Plug the OneWire Temperature Sensor into the Grove port marked D4-5 on the Mayfly board.
  • Upload the sketch to the Mayfly by clicking the Upload button, hold Crtl+U or select Sketch > Upload from the menu.
  • Open the Serial Monitor by pressing the Serial Monitor button, hold Ctrl+Shift+M or select Tools > Serial Monitor from the menu. Make sure the “baud” rate option at the bottom right side of the window is set to “9600“.

The logger will start off by printing the data header that will be written to the micro-SD card followed by an initial sensor reading. The time set above (currentminute) will dictate how often the logger will wake up and take an new reading.

At this point you have set up your logger and you can begin to experiment with the temperature sensor, taking various reading or doing some initial quality control.

If your intent is to deploy the Mayfly in the field, continue on to the Field Installation section to set up a location and your MonitorMyWatershed information.

Quality Control

The Maxim DS18B20 sensor chip that is used in the OneWire temperature sensor has the following specifications:

We can see that the sensor has an accuracy of ±0.5°C so that is the acceptable difference in readings we are looking at. The chart below lists the QC readings taken from March 24th through April 25th.

With the exception of the reading on April 6th, the majority of the readings are within the acceptable range. There was an issue with the battery connector on that date and the battery needed to be swapped out. This may or may not have had an effect on the data.

These QC checks were done using a digital thermometer close to the sensor on the station as possible. It also helps to try and time your measurement to the same time as the loggers sampling time (i.e. 15 minute or whatever time interval you set in your code) to get an accurate comparison.

By performing a QC check every time the logger is visited or each time the SD card is changed, a clearer record of the accuracy of the sensor can be obtained.

Monitor My Watershed

This section will briefly cover some of the basic tasks you will need to do in order to get your data to the Monitor My Watershed data portal. For more in-depth information, you should read through the Monitor My Watershed Sensor Data Manual.

Getting started with Monitor My Watershed is (almost) as easy as one-two-three.

Creating an account

The very first step to getting your data online is to register a new account. Like many other websites, some basic information is required to sign up:

  • First name
  • Last name
  • Email address
  • Username
  • Password
  • Organization (optional)

Once you have enter this information, you can proceed to the next section to register your site.

Registering a Site

Once you have logged in, click on My Sites at the top of the page. This will open a new page where you can register a new site or display the sites you have already created.

Click the button on this page that reads Register a New Site and a page will open where you can enter the physical information about your site such as location and type.

Adding Sensors

Once your site is set up, you can proceed to adding sensor information. Look for the button MANAGE SENSORS on your site page and click on it.

The page will open to show which sensors have been added to the site. If this is a new site there will be no sensors listed. This example shows the list for the logger on Stillwater Run.

It is important to note that anything you want to record and display data for is considered a sensor. Even the Mayfly and the battery are sensors in this context.

Click on the plus sign + to create a new sensor entry and fill out the required fields for each sensor you wish to add. If you are building a duplicate of the logger used in the document, you should have a total of three when you are finished:

  • DS18B20 Waterproof Digital temperature sensor (Maxim_DS18B20_Temp)
  • Mayfly Data Logger (EnviroDIY_Mayfly_Batt)
  • Mayfly Data Logger (EnviroDIY_Mayfly_Temp)

You will also need to edit the header information (DATA_HEADER) in the Continuous Temperature Logger code to match your individual site (or manually do it after retrieving your data from the logger.

For reference, here is the Stroud Center Example File which shows the basic format.

In the code for the Continuous Data Logger, find the following line:

This data header provides you with a template for formatting your data to be usable with MonitorMyWatershed. You will need to replace the entries between (and including) the braces [ ] with the values that your are given with your sensor setup.

Go to your site on MonitorMyWatershed.org. At the top, next to the map, you will find the Sampling Feature UUID. Paste this code into your data header.

Next, click on Manage Sensors, choose the sensor you want to find the UUID for and click Edit. At the top of the window that opens, your UUID for the sensor will appear. This is the ID you will need to paste into the data header for the continuous Temperature Logging code.

Do the same for all of your sensors that you have added.

If you decide to add more sensors in the future, you will need to edit your header to match the new data you are sampling.

Uploading Data

Once you have collected some data and are ready to upload it to MonitorMyWatershed, return to your site page and click the MANAGE SENSORS button. Look for the paper clip icon in the Upload a data file (.csv) section and click on it.

From here you can select your data file and then click the Upload button. If you formatted your data correctly you should receive an Data was uploaded successfully message.

Viewing Your Data

Once you have uploaded your first batch of data, you can view it by simply going to your site page. For an expanded view, you can look at the Time Series Analysis for each or all of the sensors at once. Click the link to read more about View Site Data.

Field Installation

This section will guide you through some of the tasks you will need to perform in order to set up your Mayfly in the field. Because this was a low cost experiment using as few components as needed and paying attention to overall cost, some of this information has been altered from the methods used in the EnviroDIY Monitoring Station Manual, but feel free to experiment or come up with solutions that work best for your situation and location.

Location

Ideally, you would like an open location that receives plenty of sunlight and is also close to the water source you wish to monitor. Remember that your sensor cable is limited in its length and so, your sensor should be close to the water while still being positioned in a stable location.

The height of the mounting device you choose will also determine how close to the source you will have to be and still have enough sensor cable to reach it.

Mounting Hardware and Installation

Some basic hardware and preparation will be required to install your logger in the field:

Hardware:

  • Mounting pole for the data logger and enclosure (Many hardware stores sell an inexpensive fence post that works well).
  • Tie wraps to secure any slack on the sensor cable.
  • Landscaping pins to hold down the sensor cable leading from the pole to the water.
  • 3′ or 4′ Rebar stake for sensor support in the water.
  • PVC pipe to protect the sensor installation.
  • Nuts, bolts, washers and any other hardware to mount the logger to the mounting pole (This example uses 1/4″ hardware).

Preparation:

  • You will need to drill at least two holes in the enclosure provided with the Mayfly Starter Kit: One for mounting to the pole you choose and one for the sensor to exit the enclosure.
  • Place one rubber washer on the bolt and insert it into the hole for the mounting pole. Secure it with a washer and a nut for mounting later.
  • Place the strain relief around the sensor cable, close it, and then insert it into the hole for the sensor. You will also need to apply some silicone sealant or plumbers putty around the relief to keep it waterproof once it is assembled in the case.
  • If you have the skill or experience, you can also use a cable gland in place of the strain relief but you will need to remove the Grove connector before running the cable though the gland.
  • Place the Mayfly into the enclosure. You may need to angle it slightly to clear the bolt and strain relief. Use the screws provided with the kit to secure the board in the enclosure (strain relief shown without sensor cable for clarity).

Tools:

  • A hammer or mallet to drive the mounting pole into the ground at your chosen location. A block of wood is also useful so that the mounting pole does not get damaged when hammering.
  • You will also need the hammer or mallet to drive the rebar stake into the stream for your sensor mounting.
  • Wire cutters or scissors, if you plan to trim the ties wraps after securing the sensor cable.
  • A saw for cutting the PVC pipe, if you choose to use it. For the example installation, a section of PVC (1″ diameter) was cut to 10″. This slides over the rebar and sensor cable to protect it from debris that might run into it and snag the cable. Additional holes (1/8″) were drilled into the PVC to allow securing it with tie wraps.

Installation:

  • Drive the mounting pole into the ground with the hammer or mallet at the desired location.
  • Drive the rebar stake into the stream at the desired location.
  • Secure the enclosure for the Mayfly to the mounting pole. This image shows the cable routed through the bottom of the case instead of the side but getting the Mayfly in or out of the enclosure is difficult.
  • Plug in your battery, solar panel and sensor cable (the image shows a reflective insert to help reduce the effects of heating in the enclosure).
  • Run the sensor cable down the length of the mounting pole and through the piece of cut PVC pipe. Make sure you have enough cable and some slack to reach the rebar stake in the stream and to secure the cable to the ground.

  • Slide the PVC with the sensor cable inside, over the rebar stake in the stream.
  • Set your sensor height in the water and secure it near the end with a tie wrap. If you leave a little extra tie wrap hanging out (not cut flush) the PVC pipe can rest on top of this and it will not slide down cover the tip of the sensor.

  • Use additional tie wraps to secure the PVC pipe to the rebar stake using the 1/8″ holes drilled previously.
  • Secure the sensor cable to the mounting pole with tie wraps.

  • Use the landscaping pins to secure the length of sensor cable running from the mounting pole to the water’s edge.

When you have finished setting up your site, don’t forget to insert the SD card, turn the Mayfly on, and secure the lid on the enclosure.

Conclusion

Now all you have to do is wait until some data is collected. How long you wait is up to you but it is a good first step to check on your setup frequently at the beginning to ensure that you are collecting data and that everything is functioning properly:

  • Is the battery charging properly?
  • Is your sensor cable secure?
  • Have there been storms recently that may cause damage or instability to your setup?
  • Are animals chewing on your cables?
  • Did you turn your Mayfly on?
  • Is your micro-SD card inserted?
  • Did you do a QC check?

Once you have some time under your belt, you can think about ways to improve your current installation or what you can do better on your next one.

  • Maybe you want a more powerful solar panel? The 0.5W panel with the Starter Kit could be a little more powerful, especially if you are in an area that doesn’t receive a lot of direct sunlight.
  • How about a longer cable? Some quick Internet searching might give you some ideas for building your own custom temperature cable.
  • Or you might want to experiment with networking your monitoring station with other stations close by. There are inexpensive XBee modules that utilize WiFi to talk to each other.

The EnviroDIY website is also a great place to start getting ideas and reaching out to other users for help and inspiration. Or, you can look at the EnviroDIY GitHub site for coding examples and learn how to use VSCode and PlatformIO.

Hopefully this document has set you on the right path for setting up your own monitoring station or just for getting familiar with the EnviroDIY Mayfly. If you feel something could be improved upon, made clearer or is a downright error, please feel free to comment and help make it better for the next reader.

Happy Logging,
Robert S

4.5 2 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Click to jump to comments section.x