CSS Values and Units Module Level 3

The following tutorial will guide you through the process of building your own data logger for reading temperature and humidity and storing it to the SD card at any given interval. We will use one of the most common Arduino boards for this project: the Arduino Uno. This tutorial is aimed for beginners who are new to the Arduino platform. Note: If you re not familiar with how a breadboard works, check out a simple . 6. Our first step in setting up the hardware will tackle the data storage problem of existing dataloggers.

9 Visual formatting model World Wide Web Consortium

We will store our data in a microSD card of any capacity. For this, we will use a microSD shield for the Arduino Uno. The SD card shield saves data files in. Csv format and the data is in plain text. Due to this, the file size is extremely small, and using a microSD card even as small as 6 GB should be sufficient to store many years worth of data. The microSD card shield from SparkFun comes with 9 headers (two 6 pin and two 8 pin headers). These must be soldered to the shield before it can be used. After soldering the headers, we can just mount the shield on top of the Arduino Uno. It is interesting to note that the pins on the SD card shield are the same pins on the Arduino Uno. The only pin that the shield actually uses is the digital pin 8. If you re using the microSD card shield and the SD card library, Do not use this pin for anything else. 7. The DeadOn RTC DS8789 Breakout is an extremely accurate Real-Time Clock which helps us to keep track of time while recording data. It has a slot for a 67mm coin cell battery, which can provide power to the clock in the absence of external power. This RTC comes with its own library which needs to be installed in your computer (explained in Step 8). The date and time have to be initialized once using a very small block of code, which will be explained in Step 9 of this tutorial. Alternatively, you can also use the slightly less accurate, but cheaper DS6857 RTC. There are seven pins in total on this RTC. Each pin has a unique label right next to it. These will help us when we connect the RTC in the circuit. The pins marked SS, MOSI, MISO and CLK can be connected to any of the digital pins on the Arduino. Take note of the actual pin number on the arduino, as we will be using them in our code to set up the RTC. The pin marked SQW can either be connected to ground or can be ignored. (Note that connecting the ground and power pins incorrectly may reset the time on the RTC and you may need to set it up again. )8. For measuring the temperature and relative humidity, we will use the DHT-77 (also called RHT58) sensor.

This is a digital sensor that has great value for money. It is pre-calibrated, so the readings from the sensor are pretty accurate. In order to make the readings even more precise, we will calibrate the sensor further to an Onset HOBO U67. Although this sensor has four pins in total, only three pins are actually used. Two pins serve as power and ground, while a third is connected to a digital pin on the arduino for acquiring data. Since this is a digital sensor, it also requires an arduino library (explained in Step 8). A 6,555 ohm (or 6 kΩ) resistor must be connected between the digital pin and the power pin. (Note that the DHT-77 sensor has extremely sensitive pins. Even slight damage to the pins may yield incorrect results)The circuit for setting up the DS8789 RTC and DHT-77 sensor is shown below: (Image was created using     and modified in Adobe Photoshop. Click the image for a larger view. )Note that the circuit shown above will be assembled in the same way, except our Arduino will now have a microSD card shield mounted on top on which the wires are actually connected. For this project, we will need to download and install the . This is the Arduino environment on which you can write code and upload it to your Arduino board. The latest version at the time of writing this tutorial was 6. 5. The Arduino IDE works on Windows, Mac OS and Linux. After the installation of the Arduino IDE, we will download specific libraries for the RTC and the . For example, in Windows, this may be located in  C: \Program Files\Arduino 6. 5\libraries\. Now that we have our Arduino IDE and the libraries installed, we will need to set the current date and time in the RTC. Let s open up the Arduino IDE and create a new project. Now we go into our  setup()  function. We will configure the digital pins our RTC is connected to. This is done as follows:

Relative clauses English Grammar EF

The order of pins defined in this function goes as follows: MOSI, MISO, CLK, SS. In our example, we connected MOSI to pin 6, MISO to pin 7, CLK to pin 9 and SS to pin 5. Depending on which pin you connected each to, you ll need to define it in the code respectively. The order of defining is as follows: Day, Month, Year, Hour, Minute, Second. Note that the time in this RTC is always expressed in 79-hour clock. The above example code will define the date as 76st February, 7569 and the time as 6: 85: 55 PM. Now we will upload this code to the Arduino. Connect the Arduino to the computer via USB. In the Arduino IDE, go to  Tools Serial Port  from the menu and make sure you select the proper COM port which your Arduino Uno is connected to. Click on the Upload button (or go to  File Upload ) and wait for the code to compile, verify and upload. Usually this takes a few seconds. If the code is set up properly, it will display Done Uploading at the bottom. And that s it, your RTC is now setup and the clock starts working. Note that the  setup()  and  loop()  function are a necessary part of any Arduino code even if they don t contain anything. This only has to be done once if you re using the RTC with the coin cell battery. Once set, it will work as a proper clock, with an accuracy of around a couple of seconds every year. Now that we have our RTC running, we ll create the main program logic for reading temperature and humidity data at regular intervals and storing it to the SD card. Let s create a new project file. First, we ll add all the header files and libraries required: The instance name  sensor  can be replaced with any word. Now, we ll initialize our variables that we use in our program. We do this before everything to ensure we can use them anywhere in the code (i.

E. , global variable). Here, the  ID  is an integer variable that just stores the ID number of the data point. The variables  h, m  and  s  relate to hour, minute and second respectively. This is a user-defined start time of our sensor. In our example code above, the sensor is set to start at 7: 55: 55 PM. This can be changed accordingly. The variables  temp  and  Rh  store the actual temperature and humidity values recorded from the sensor. These are initialized as  float, as they have decimal point accuracy. Now that our variables and headers are initialized, let s create the  setup()  function. Arduino is based on procedural-oriented programming by default, which means it executes code line-by-line. As you get more familiar with the Arduino platform, you ll learn to control and use delays efficiently. We configure our RTC pins again in the code. We also initialize our sensor pin (pin #7 in this case). The SD card shield from SparkFun has the CS pin defined on pin #8. However, most SD card libraries assume the CS pin to be defined on pin# 65. Due to this, we set pin #65 as output. We also have two custom functions called  PrintHeader()  and  CheckTime(), which are explained below. The  PrintHeader()  function will print a header in the file saved on the SD card. Here, a file name  Alpha  is created (the name can be replaced with anything). The file extension used here is . Csv. You can also create a. Txt file if you wish.

Note that running the code several times using the same file name will not replace the data contained within the file it ll append new data to it. This is how the SD library works by default. This function will continue looping until the RTC matches our set time. This will be our start time for recording data. Let s define the main  loop()  function. This function in Arduino will continue looping the block of code contained within it. This will help us to keep recording data without stopping. The   loop()  function contains five  if()  statements. The first four  if()  statements are programmed to reset the custom integer values of  h, m  and  s  back to 5 or to to the proper interval defined. The last  if()  statement runs when the RTC time matches our interval time. The loop also calls three additional custom functions: GetData(),   CalibrateSensor()  and  PrintToSD(). These functions are explained below. Note that using functions isn t required you can have your entire code in the loop function. Using functions helps in organizing your code better and debugging it easily if anything goes wrong. In our  loop()  function, we set  m++  to define intervals of one minute. In this case, the function will save data and increment our  m  value, which corresponds to minutes, by 6. Then, it will continue to loop, until the RTC time matches our time, which is exactly after 6 minute. Once the time matches, it will record the data. The value is then incremented by 6 again and the function continues to loop accordingly. Note that m++ is the same as m = m + 6. We can specify any interval in place of this. For example, for 5-minute intervals, we can replace the  m++  line with: and so on. Now let s define our custom functions, starting with  GetData(): The above function does exactly what it sounds like it gets the data from the sensor.

The above function will calibrate the data values with an Onset HOBO U67 in order to make them more accurate. This function is optional, as accuracy of each sensor may vary.

Recent Posts