If you want to store data from sensors you don't necessarily need an SD-card. Most Arduino boards have an EEPROM where we can permanently save data without loosing it when turning off the board.
In this project we will only be using an Arduino board and a temperature and humidity sensor to collect and store weather data. After the data is collected the Arduino board can be connected to a computer and we can read and plot the data to the serial monitor/plotter.
We start by connecting the DHT11 sensor to the Arduino board as shown in the schematics. The installation is very easy because we only have to connect the three connections from the sensor to PIN4, 5V and GND on the Arduino board.
The codeFirst of all we need two libraries for this project:
#include <dht11.h>
#include <EEPROM.h>
For the EEPROM library we don't have to install anything but for the dht11 library we need to download the zip-file (dht11.h) found on this website:
https://github.com/adidax/dht11#readme
After you downloaded the zip-file you have to add it to your library (Sketch --> Include Library --> Add.ZIP Library).
Before the setup function two variables are defined:
unsigned int address = 0; //variable to iterate through the addresses //of the EEPROM
unsigned int delaytime = 10; //delay between readings in seconds
The "address" variable is used to know in which EEPROM-address the next value from the sensor will be stored. "delaytime" sets the delay between the readings from the sensor in seconds.
In the setup function there are two while loops. One should always be commented out. You have to use the first one if you want to print the data on the EEPROM to the serial monitor (as text). Therefore when reading the data you have to open the serial monitor as shown in the video. If you want to have a plot of the temperature and humidity readings you have to comment out the first while loop and uncomment the second one. To see the plot you have to open the serial plotter (Tools --> Serial Plotter).
Note: After the the data is plotted and the loop-function is executed once, the value EEPROM.read(1023) will be overwritten. The value stored in EEPROM.read(1023) determines until which address the data will be plotted in the setup function. So if you reset the Arduino board after the loop-function is executed the old data will not be plotted again.
The loop-function is very simple. It waits until the delay is over then the temperature and humidity is read from the sensor and written to the EEPROM.
Comments
Please log in or sign up to comment.