Created
January 14, 2021 05:27
-
-
Save abdul-rehman-2050/29dcea4cc334cf1fa34ba017e81892bb to your computer and use it in GitHub Desktop.
Arduino LM35 based Temperature Meter with Celcius and Farnheight temperature output on Serial Terminal and 16x2 LCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
for compelete blog | |
http://www.fypsolutions.com/arduino/lm35-temperature-sensor-arduino | |
*/ | |
#include <LiquidCrystal.h> | |
// Pin Definitions | |
#define LCD_PIN_RS 7 | |
#define LCD_PIN_E 6 | |
#define LCD_PIN_DB4 2 | |
#define LCD_PIN_DB5 3 | |
#define LCD_PIN_DB6 4 | |
#define LCD_PIN_DB7 5 | |
#define LM35_PIN_VOUT A3 | |
LiquidCrystal lcd(LCD_PIN_RS, LCD_PIN_E, LCD_PIN_DB4, LCD_PIN_DB5, LCD_PIN_DB6, LCD_PIN_DB7); | |
float getTempC(byte nSamples) | |
{ | |
int val = 0; | |
for (byte i =0 ; i < nSamples ; i++ ){ | |
val += analogRead(LM35_PIN_VOUT); | |
delay(1); | |
} | |
return (5.0 * val * 100.0) / 1024.0 / nSamples; | |
} | |
float convertToF(float tempInC){ | |
return ((tempInC*1.8)+32); // Converting Celcius to Fahrenheit | |
} | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial) ; // wait for serial port to connect. Needed for native USB | |
Serial.println("start"); | |
// set up the LCD's number of columns and rows | |
lcd.begin(16, 2); | |
lcd.setCursor(0,0); | |
lcd.print(F("LM35 Reading")); | |
} | |
void loop() { | |
float lm35TempC = getTempC(10); | |
float lm35TempF = convertToF(lm35TempC); | |
Serial.print(F("Temp: ")); | |
Serial.print(lm35TempC); | |
Serial.print(F("C, ")); | |
Serial.print(lm35TempF); | |
Serial.println(F("F, ")); | |
lcd.setCursor(2,1); | |
lcd.print(lm35TempC); | |
lcd.print(F("C, ")); | |
lcd.print(lm35TempF); | |
lcd.print("F" ); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment