Showing posts with label humidity. Show all posts
Showing posts with label humidity. Show all posts

Friday, July 4, 2014

Weather datalogger with ARM cortex-M4 - part1

   So, after blinking LED's and reading buttons I want to go further and deeper inside my ARM Cortex-M4 board: I am developing a data-logger for Temperature, Humidity and light level; It will store its data inside a micro-SD card, available on-board the FRDM-K64F I have.
   The sensors I have in my hands right now are the linear LM35 temperature sensor, the DHT11 digital temperature/humidity sensor and a LDR(light dependent resistor) for visible light level measurement. In the picture below you can see the setup of my experiment; it is  possible to see the big light-blue component (DHT11) aside with LM35 (the TO-92 case) and my Freescale development board with a microSD card connected to it. The LDR is missing in the picture, but is present in the actual prototype.


   Besides the sensors and microSD my board also features a Timekeeping chip, a Maxim DS1302 in a breakout board with a battery mounted on it; That chip makes my data-logging look more "professional" by keeping track of the time of every reading (or event). My code can be download from here and the schematic diagram is seeing below. 

Schematics- click the image to enlarge

   One reading is made every 10 seconds and the data is stored in the microSD card. I have tested the setup for several days, for as long as 21 hours every time. Turns out the system is very reliable: it can be seen below in the temperature plot that both sensors feature a similar behavior, validating the reading of both (analog for the LM35 and digital-serial for the DHT11).






Click in the images to enlarge

   I selected that specific period of time (5AM- 5PM) because it is the most interesting in terms of temperature and light level; There are some considerations to be done in here:

1) The temperature and the light level increase when 5PM gets closer, and that is because my room is facing northwest, so it starts getting a huge amount of sunlight around that time.
2) My light sensor (LDR) is not calibrated and I also don't know its characteristics, so I simply put a series resistor (1Kohm) with it; As a post processing I scale it to fit into a 0-5 arbitrary scale. Around 7:30PM (not on the pictures above) it reaches almost 4.5 with direct sunlight over it.
3) Some noise is expected to appear in the pictures above (as is possible to observe), as the system takes one measurement every 10 seconds. These pictures feature around 12 hours of data!.

   That was the part 1 of a series of improvements I am planning to make on that project; My next step will be using the network hardware available on-board (Ethernet) to send all that data in real-time for a web page I will create. Another piece of future work will also be powering the module with a solar panel (which I have bought already). And finally adding a rain sensor to it, so I can have a complete meteorological station in my house!. All of that was powered by this amazing Freescale development board (FRDM-K64F). 

Thank you guys and see you soon,

Monday, June 23, 2014

Second project - Temperature + humidity + LCD!

Hello coders, hackers, makers and curious visitors!

   The second project I worked on is a "temperature and humidity sensor with a LCD display" based on Arduino, the DHT11 serial temperature/humidity sensor, the LM35 linear temperature sensor and a 16x2 LCD screen. The project is similar to this one and features readings of temperature and humidity that are shown in a LCD display and sent via Arduino (USB- serial) to any PC terminal. Below I show a picture of the project working:

The prototype, when compared to Google Weather (upper right corner)

   The serial console (on arduino IDE) can be seen below, capturing successive readings from Arduino serial:

Screenshot of data captured through serial

   The complete schematic of this prototype is in the picture below; it was developed using Fritzing; You can download the schematic here



   The project was coded inside the Arduino IDE using some third-part codes, which I put together and made it work. The original codes are: DHT11 Library and LiquidCrystal . My code is available in the box below, as well as in this Github link.

/*
 Modified by Clovis Fritzen in June 11th, 2014:
 - The original program read the serial temperature/humidity sensor DHT11 (which is still part of this program); 
 - "Delay" function substituted by a counter (when the counter overflows the program enters the serial routine)
 - Added the LM35 (10mV/C temperature sensor) reading via serial, to compare both sensors
 */
/*
  Board           int.0   int.1   int.2   int.3   int.4   int.5
 Uno, Ethernet   2   3
 Mega2560   2   3   21   20   19   18
 Leonardo   3   2   0   1
 Due           (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
 
 This example, as difference to the other, make use of the new method acquireAndWait()
 */
 
#include 
#include 

int idDHT11pin = 2; //Digital pin for comunications
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
long count= 0; // counter for spacing the serial writings
long AcqPeriod= 0;
int sensorPin = A5; // input pin for LM35 (10mV/C)
int sensorValue = 0; // variable to store the LM35 temperature
int led= 13;


//declaration
void dht11_wrapper(); // must be declared before the lib initialization

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 5, 4, 3, 6);

// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);

void setup()
{
  pinMode(led, OUTPUT);   
  Serial.begin(9600);
  Serial.println("DHT11 temp/humidity sensor - Example program");
  Serial.print("Lib version: ");
  Serial.println(IDDHT11LIB_VERSION);
  Serial.println("modified by Clovis Fritzen");
  Serial.println("---------------");
  
   // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print(" DHT:|LM35:|HUM:");
}
// This wrapper is in charge of calling 
// mus be defined like this for the lib work
void dht11_wrapper() {
  DHT11.isrCallback();
}
void loop()
{
  
  AcqPeriod= 400000; // set here the interval in which data is sent into serial 
  
  if (count < AcqPeriod) // Still need to make sure what this number represents in terms of
                      // seconds or cycles of clock
  {
  count= count++;
  
  if (count < (AcqPeriod/2)) // just a routine to blink a led :)
  {
    digitalWrite(led, HIGH);
  } else{
    digitalWrite(led, LOW);
  }
 }
else
{
  
  //Serial.print("\nRetrieving information from sensor: ");
  Serial.print("\nRead sensor: ");
  //delay(100);
 count= '0';
 
 sensorValue = analogRead(sensorPin);
 sensorValue= sensorValue/2;
  
  int result = DHT11.acquireAndWait();
  switch (result)
  {
  case IDDHTLIB_OK: 
    Serial.println("done"); 
    break;
  case IDDHTLIB_ERROR_CHECKSUM: 
    Serial.println("Error\n\r\tChecksum error"); 
    break;
  case IDDHTLIB_ERROR_ISR_TIMEOUT: 
    Serial.println("Error\n\r\tISR time out error"); 
    break;
  case IDDHTLIB_ERROR_RESPONSE_TIMEOUT: 
    Serial.println("Error\n\r\tResponse time out error"); 
    break;
  case IDDHTLIB_ERROR_DATA_TIMEOUT: 
    Serial.println("Error\n\r\tData time out error"); 
    break;
  case IDDHTLIB_ERROR_ACQUIRING: 
    Serial.println("Error\n\r\tAcquiring"); 
    break;
  case IDDHTLIB_ERROR_DELTA: 
    Serial.println("Error\n\r\tDelta time to small"); 
    break;
  case IDDHTLIB_ERROR_NOTSTARTED: 
    Serial.println("Error\n\r\tNot started"); 
    break;
  default: 
    Serial.println("Unknown error"); 
    break;
  }
  
  lcd.setCursor(7, 1);
  // print the number of seconds since reset:
  lcd.print(sensorValue);
  
  Serial.print("Humidity (%): ");
  Serial.println(DHT11.getHumidity(), 0); // ", 0" represents the number of decimal positions after the comma

  Serial.print("DHT11 Temp (oC): ");
  Serial.println(DHT11.getCelsius(), 0); // ", 0" represents the number of decimal positions after the comma
  
  lcd.setCursor(13, 1);
  // print the number of seconds since reset:
  lcd.print(DHT11.getHumidity(), 0);
  
  Serial.print("LM35 Temp (oC): ");
  Serial.println(sensorValue);
  

  //Serial.print("Temperature (oF): ");
  //Serial.println(DHT11.getFahrenheit(), 2);

  //Serial.print("Temperature (K): ");
  //Serial.println(DHT11.getKelvin(), 2);

  //Serial.print("Dew Point (oC): ");
  //Serial.println(DHT11.getDewPoint());

  //Serial.print("Dew Point Slow (oC): ");
  //Serial.println(DHT11.getDewPointSlow());
  
   // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(1, 1);
  // print the number of seconds since reset:
  lcd.print(DHT11.getCelsius(),0);
  
   }
  
  }

   I just want to share some notes with you:
- Both the DHT11 and LM35 have a "step" (or resolution) of one degree Celsius, meaning they cannot read something like "26.3"; They a only capable of reading numbers with no decimal (e.g: "26").
- The contrast of the LCD screen can be adjusted by means of the potentiometer; Its backlight is always on (last two pins of the LCD on the schematic above).
- The circuit works independently on the presence of the USB cable on Arduino; it means that it will work on batteries for example!. in this case only the serial readings will be missing.
- The is a blinking led on pin 13 of Arduino (which is assemble on the board); That one is there just for fun.

   I hope you guys are enjoying my posts so far, and trying to validate my projects by doing it yourselves. If you have any suggestions/ recommendations or critics, please feel free to talk to me on Twitter, Google Plus and Facebook, as well as in the comments below. See you all next time!.