0% found this document useful (0 votes)
2 views

temp sensor

The document contains two Arduino code examples for reading temperature from a sensor. The first example outputs the temperature to the Serial Monitor without using an LCD, while the second example provides two options that display the temperature on an LCD screen in both Celsius and Fahrenheit. Each option includes setup and loop functions to handle sensor readings and display outputs at regular intervals.

Uploaded by

Mahima
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

temp sensor

The document contains two Arduino code examples for reading temperature from a sensor. The first example outputs the temperature to the Serial Monitor without using an LCD, while the second example provides two options that display the temperature on an LCD screen in both Celsius and Fahrenheit. Each option includes setup and loop functions to handle sensor readings and display outputs at regular intervals.

Uploaded by

Mahima
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

without lcd

int sensor_value=0; //variable intialization


void setup()
{
Serial.begin(9600); //
pinMode(A0,INPUT);
}

void loop()
{
sensor_value=analogRead(A0); //
Serial.print("sensor value="); //to print as it is
Serial.println(sensor_value); //ln for next line
int voltage=sensor_value*(5000/1024.0); //
int temperature=(voltage-500)/10;
Serial.print(temperature);
Serial.print(" degree celsius\n");
delay(1000);

With LCD

option 1
#define sensorPin A0
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {

Serial.begin(9600);
lcd.begin();
lcd.backlight();
}

void loop() {
lcd.clear();
int reading = analogRead(sensorPin);

float voltage = reading * (5.0 / 1024.0);

float temperatureC = voltage * 100;


Serial.print("Temperature: ");

lcd.setCursor(0,0);
lcd.print("Temperature:");
lcd.setCursor(0,1);
lcd.print(temperatureC);
lcd.setCursor(6,1);
lcd.print("C");

float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;


lcd.setCursor(8,1);
lcd.print(temperatureF);
lcd.setCursor(14,1);
lcd.print("F");

delay(1000);

option 2

int t=0;
int sensor = A0;
float temp;
float tempc;
float tempf;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//const int rs= 12, en=11, d4=5, d5=4, d6=3, d7=2;
LiquidCrystal_I2C lcd(0x27, 2, 16);
void setup() {
pinMode(sensor,INPUT);
lcd.begin();
lcd.backlight();
lcd.setCursor (0,0);
lcd.print (" ARDUINO ");
lcd.setCursor (0,1);
lcd.print ("TEMPRETURE METER");
delay (3000);
Serial.begin(9600);
} void loop() {
delay(2000);
t=t+2;
temp=analogRead(sensor);
tempc=(temp*5)/10;
tempf=(tempc*1.8)+32;
Serial.println("_______");
Serial.println("Temperature Logger");
Serial.print("Time in Seconds= ");
Serial.println(t);
Serial.print("Temp in deg Celcius = ");
Serial.println(tempc);
Serial.print("Temp in deg Fahrenheit = ");
Serial.println(tempf);
lcd.setCursor(0,0);
lcd.print("Temp in C = ");
lcd.println(tempc);
lcd.setCursor(0,1);
lcd.print("Temp in F = ");
lcd.println(tempf);
}

You might also like