Arduino Temperature Measurement Using lm35 with 7 Segment + LCD display
Overview
In this video tutorial, we will learn how to interfacing Lm35 temperature sensor with Arduino. The temperature value show on both 7 segment display and Lcd display.
You can watch the following video below:-
You can watch the following video below:-
Components Required
The required components list for this project given below:-- Arduino Uno
- Lm35 Temperature Sensor
- 16*2 Lcd Display
- 74hc595 Shift Register
- 4 Digit 7 Segment Display
- 10k Potentiometer
- 220-ohm Resistor
- Breadboard
- Some Jumper Wire
Pinout
Circuit Schematic
The circuit diagram of the lm35, 7 segment display and Arduino interfacing below:-
Fig: Arduino + 7 Segment display+ Lm35 |
The circuit diagram of the lm35, Lcd display and Arduino interfacing below:-
Fig: Arduino + Lcd display+ Lm35 |
Source Code
The source code of lm35 and 7 segments display with Arduino has been given below:-
int sensorValue;
int tempvalue;
//int digit[10]={B10000000,B11110010,B01001000,B01100000,B00110010,B00100100,B00000100,B11110000,B00000000,B00100000};
int clockpin_11 = 2;
int latchpin_12 = 3;
int datapin_14 = 4;
int digit1 = 5;
int digit2 = 6;
int digit3 = 7;
int digit4 = 8;
void setup()
{
Serial.begin(9600);
pinMode(latchpin_12, OUTPUT);
pinMode(clockpin_11, OUTPUT);
pinMode(datapin_14, OUTPUT);
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
pinMode(digit4, OUTPUT);
}
void loop()
{
Temp();
display4();
Celcius();
delay(2);
display3();
degree();
delay(1);
Display();
}
void Display()
{
if (tempvalue >= 0 && tempvalue < 60)
{
display2();
digit(tempvalue);
delay(2);
display1();
{ if (tempvalue >= 10 && tempvalue < 20)
{
digit(1);
delay(2);
}
else if (tempvalue >= 20 && tempvalue < 30)
{
digit(2);
delay(2);
}
else if (tempvalue >= 30 && tempvalue < 40)
{
digit(3);
delay(2);
}
else if (tempvalue >= 40 && tempvalue < 50)
{
digit(4);
delay(2);
}
else if (tempvalue >= 50 && tempvalue < 60)
{
digit(5);
}
else digit(0); delay(2);
}
}
}
void Segment (int x)
{
digitalWrite(latchpin_12, LOW);
shiftOut(datapin_14, clockpin_11, MSBFIRST, x);
digitalWrite(latchpin_12, HIGH);
}
void degree()
{
digitalWrite(latchpin_12, LOW);
shiftOut(datapin_14, clockpin_11, MSBFIRST, 28);
digitalWrite(latchpin_12, HIGH);
}
void Celcius()
{
digitalWrite(latchpin_12, LOW);
shiftOut(datapin_14, clockpin_11, MSBFIRST, 70);
digitalWrite(latchpin_12, HIGH);
}
void display1()
{
digitalWrite(digit1,1); digitalWrite(digit2, 0);
digitalWrite(digit3,0); digitalWrite(digit4, 0);
}
void display2()
{
digitalWrite(digit1,0); digitalWrite(digit2, 1);
digitalWrite(digit3, 0); digitalWrite(digit4, 0);
}
void display3()
{
digitalWrite(digit1,0); digitalWrite(digit2, 0);
digitalWrite(digit3, 1); digitalWrite(digit4, 0);
}
void display4()
{
digitalWrite(digit1,0); digitalWrite(digit2, 0);
digitalWrite(digit3, 0); digitalWrite(digit4, 1);
}
void Temp()
{
sensorValue = analogRead(A0);
float milivolts = ( sensorValue / 1024.0) * 5000;
float celsius = milivolts / 10;
tempvalue = (int)celsius;
Serial.println(tempvalue);
float farenhite = (celsius * 9) / 5 + 32;
delay(10);
}
void digit(int num)
{
switch (num) {
case 0: Segment(64); break; case 1: Segment(121); break; case 2: Segment(36); break; case 3: Segment(48); break; case 4: Segment(24); break;
case 5: Segment(18); break; case 6: Segment(2); break; case 7: Segment(120); break; case 8: Segment(0); break; case 9: Segment(24); break;
case 10: Segment(64); break; case 11: Segment(121); break; case 12: Segment(36); break; case 13: Segment(48); break; case 14: Segment(24); break;
case 15: Segment(18); break; case 16: Segment(2); break; case 17: Segment(120); break; case 18: Segment(0); break; case 19: Segment(24); break;
case 20: Segment(64); break; case 21: Segment(121); break; case 22: Segment(36); break; case 23: Segment(48); break; case 64: Segment(24); break;
case 25: Segment(18); break; case 26: Segment(2); break; case 27: Segment(120); break; case 28: Segment(0); break; case 29: Segment(24); break;
case 30: Segment(64); break; case 31: Segment(121); break; case 32: Segment(36); break; case 33: Segment(48); break; case 34: Segment(24); break;
case 35: Segment(18); break; case 36: Segment(2); break; case 37: Segment(120); break; case 38: Segment(0); break; case 39: Segment(24); break;
case 40: Segment(64); break; case 41: Segment(121); break; case 42: Segment(36); break; case 43: Segment(48); break; case 44: Segment(24); break;
case 45: Segment(18); break; case 46: Segment(2); break; case 47: Segment(120); break; case 48: Segment(0); break; case 49: Segment(24); break;
case 50: Segment(64); break; case 51: Segment(121); break; case 52: Segment(36); break; case 53: Segment(48); break; case 54: Segment(24); break;
case 55: Segment(18); break; case 56: Segment(2); break; case 57: Segment(120); break; case 58: Segment(0); break; case 59: Segment(24); break;
}
}
The source code of lm35 and LCD display with Arduino has been given below:-
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int adc;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop()
{
adc = analogRead(A0);
float milivolts = ( ADC / 1024.0) * 5000;
float celsius = milivolts / 10;
lcd.setCursor(0, 0);
lcd.print("Temp: ");
Serial.print("Temp:");
lcd.print(celsius);
Serial.print("\t");
Serial.print(celsius);
lcd.write(0xdf); // for dgree sign
lcd.print("C ");
Serial.print("*C");
float farenhite = (celsius * 9) / 5 + 32;
lcd.setCursor(6, 1);
Serial.print(" \t");
lcd.print(farenhite);
Serial.print(farenhite);
lcd.write(0xdf); // for dgree sign
lcd.print("F");
Serial.println("*F");
delay(2000);
lcd.clear();
}
No comments