A binary thermometer with Arduino and LM35

Posted by

  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;

– There are 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. 

One response

Leave a Reply

Your email address will not be published. Required fields are marked *