Showing posts with label lm35. Show all posts
Showing posts with label lm35. 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,

Tuesday, June 17, 2014

First project - Arduino Binary Thermometer with LM35

Hello folks! 

   As a first project post I will show you the steps I take to develop a binary thermometer with a LM35 temperature sensor. It is a bit similar to this one from instructables, but mine is arduino-powered. My intention on this project was simply to test the power of arduino (UNO R3) on handling one of its ports (6 bits) at a time, and also the efficacy of the LM35 digital temperature sensor.

The prototype schematic

   The schematic I created was drawn in Fritzing. My code (also available below) can be found in GitHub ( here). It is important to notice that the limits of temperatures that can be read are NOT the ones of the LM35, instead they are limited by the Arduino power supply voltage (0 +5V): so you are able to read  temperatures between +2 and +150 degrees Celsius.

// Arduino timer CTC interrupt example (timer), from www.engblaze.com
// This example is a binary meter - shows a analog value in a binary (6-bit) output
// Modified by Clovis Fritzen, to fit as a binary thermomter (in may/2014)
 
// avr-libc library includes
#include < avr/io.h >
#include < avr/interrupt.h >
 
int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor (LM35)
byte binaryValue= B00000000; // initialize port value as zeros

void setup()
{
    DDRB = DDRB | B00111111; // set 6 pins in port B as outputs
    
    // initialize Timer1
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B
 
    // set compare match register to desired timer count:
    OCR1A = 15624; // for temperature
    // turn on CTC mode:
    TCCR1B |= (1 << WGM12);
    // Set CS10 and CS12 bits for 1024 prescaler:
    TCCR1B |= (1 << CS10);
    TCCR1B |= (1 << CS12);
    // enable timer compare interrupt:
    TIMSK1 |= (1 << OCIE1A);
    // enable global interrupts:
    sei();
}
 
void loop()
{
    // You would put another stuff program here
}
 
ISR(TIMER1_COMPA_vect)
{
  // read the value from the sensor  :
  sensorValue = analogRead(sensorPin);
  //digitalValue= sensorValue;
  binaryValue= byte(sensorValue/2);
  PORTB = binaryValue; 
}




   Some notes:
- The LM35 sensor is connected to the analog input A0;
- I put three colors of leds only to give an impression of "the warmer the color, the warmer the ambient (since the MSB is a red led, connected to pin 13 of arduino);
- I have only tested it indoors so far, and it showed to be accurate enough for a sensor like that, when compared to a DTH11 temperature sensor. 

I hope you have liked it, and I promised I will try to put some videos of the actual circuits working, for the next experiments.