Digital thermometer using arduino and LM35.

This article is about a simple three digit digital thermometer using arduino. Range of this thermometer is from 0°C to 99.9°C. There is also a provision for displaying the temperature in °F scale. Three terminal analog temperature sensor LM35 is used as the sensor here. LM35 can measure temperatures between -55°C to +155°C. The supply voltage range is from 4V to 30V DC and the current drain is 60uA. The LM35 is available in TO-92 package and it is very easy to use. The output voltage of the arduino increases 10mV per °C rise in temperature. That means if 25 °C is the temperature, then output  voltage of the sensor will be 250mV. Circuit diagram of the digital thermometer using arduino and LM35 is shown in the figure below.

Circuit diagram.

digital thermometer using arduino

Temperature sensor LM35 is connected to the arduino through the analog input pins. A0 pin of the arduino serves as the supply voltage source for LM35 and A2 pin of the arduino serves as the ground. Arduino reads the voltage output of the LM35 through the analog input pin A1. Digital  pin 4 is used for interfacing the °C/°F selector switch to the arduino. Digit driver transistors Q1, Q2 and Q3 are interfaced to the digital pins 1, 2 and 3 of the arduino respectively. Multiplexed segment lines  a to dp are interfaced to the digital pins 5 to 12 of the arduino respectively. Resistors R9, R10 and R11 limits the base current of the corresponding transistors. Resistors R1 to R8 limits the current through the corresponding segments.

 

 

Program.

int i;
int backup;
int a;
int unit;
int value;
int vcc=A0;
int sensor=A1;
int gnd=A2;
int select=4;
int disp1=1;
int disp2=2;
int disp3=3;
int segA=5;
int segB=6;
int segC=7;
int segD=8;
int segE=9;
int segF=10;
int segG=11;
int segDP=12;
void setup()
{
  pinMode(disp1, OUTPUT);
  pinMode(disp2, OUTPUT);
  pinMode(disp3, OUTPUT);
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);
  pinMode(sensor, INPUT);
  pinMode(vcc, OUTPUT);
  pinMode(gnd, OUTPUT);
  pinMode(select, INPUT);
  digitalWrite(vcc, HIGH);
  digitalWrite(gnd, LOW);

}
  void loop()
 {
  value=analogRead(sensor); //Reads the sensor LM35
  value=value*5;
  unit=digitalRead(select); //Reads the selector switch
  if(unit==1)
  {value=value;}  // Output in celcius
  else
  {value=(value*1.8)+320;} //Output in Fahrenheit
  backup=value; //Backs up the content in variable value

 for(i=0;i<100;i++) //Loops the display loop 100 times(steadies the display)
 {value=backup;
  a=value%10;
  digitalWrite(disp1,LOW);
  digitalWrite(disp2,LOW);
  digitalWrite(disp3, HIGH);
  digitalWrite(segDP,HIGH);
  display(a);
  delay(4);
  value = value/10;
  a = value%10;
  digitalWrite(disp3,LOW);
  digitalWrite(disp2,HIGH);
  digitalWrite(segDP,LOW);
  display(a);
  delay(4);
  value=value/10;
  a=value;
  digitalWrite(disp2,LOW);
  digitalWrite(disp1,HIGH);
  digitalWrite(segDP,HIGH);
  display(a);
  delay(4);
 }
  }
  int display (int a)
  {
  switch (a)
  {
    case 0:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, HIGH);
     break;

    case 1:
    digitalWrite(segA, HIGH);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    break;

    case 2:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, HIGH);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, LOW);
    break;

    case 3:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, LOW);
    break;

    case 4:
    digitalWrite(segA, HIGH);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;

    case 5:
    digitalWrite(segA, LOW);
    digitalWrite(segB, HIGH);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;

    case 6:
    digitalWrite(segA, LOW);
    digitalWrite(segB, HIGH);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;

    case 7:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    break;

    case 8:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
     break;

    case 9:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;
  }}

About the program.

The voltage output of the LM35 is scanned using the analogRead function. The analogRead function will read the voltage at a particular analog input pin and converts it into a digital value between 0 and 1023. If 30°C is the temperature, the LM35 output will be 300mV. The code value=digitalRead(sensor) will read this voltage, convert it into a digital value and stores it in the variable “value”. So, for 30°C the number stored in variable “value” will be 3oomV/(5/1023)=61. This number is multiplied by 5 to get 305 a decimal point is place before the last digit while displaying on the seven segment display.The result will be 30.5°C.

The program also checks the status of the unit selector switch by reading the digital pin 4. If this pin is held high the temperature is displayed in °Celsius and if this pin is low the temperature in °Celsius scale is converted to °Fahrenheit and then displayed. The method used for displaying the number on the three digit seven segment display is same as that of used in Voltmeter using arduino.

Author

9 Comments

  1. May i ask does this circuit have a filter in it? if so where can i find the filtrated signal for oscilloscope thanks in advance 🙂

    • @Waleed – You can get +5V from Laptops USB Port. However you can’t get a 9V from laptop. You will have to connect an external power supply for that.

  2. LEKSHMANAN.N

    sir i need some projects for bio medical areas using microcontroller ,gsm rfid based if the circuits or kits are available send its topic and ur tems and conditions for purcshng it
    thanking u

  3. Can this project be modified to switch on a appliance like a cooler when the temperature reaches a certain point above a standard of eg. 25 and switch it off when 25 is reached again and switching on another appliance like a heater when the temp drops below 25 ? I’m specifically refering to water temp and the temp is measured with a temperature probe ? What would the circuit diagram look like and the software ?
    Thanx in advance

  4. in which program this code is assembled. can’t we use 8051 or any other microcontroller inplace of arduino.. plz reply..

    • Seetharaman

      This is a series on arduino application. You can use other type of hardware also.

  5. Yash Patil

    What is the price of arduino uno in mumbai??