Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views2 pages

Lab 4

The document contains two code snippets for temperature measurement using Arduino. The first code reads temperature from a sensor and prints it to the Serial Monitor, while the second code displays the temperature on an LCD and categorizes it into 'Cold', 'Fair', or 'Warm' based on predefined ranges. Both codes utilize analog reading and conversion to Celsius for temperature calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Lab 4

The document contains two code snippets for temperature measurement using Arduino. The first code reads temperature from a sensor and prints it to the Serial Monitor, while the second code displays the temperature on an LCD and categorizes it into 'Cold', 'Fair', or 'Warm' based on predefined ranges. Both codes utilize analog reading and conversion to Celsius for temperature calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Habib-12209

Lab # 3
Code 1:

float temp;

int reading;

int temppin = 0;

void setup() {

analogReference(INTERNAL);

Serial.begin(9600);

void loop (){

reading = analogRead(temppin);

temp = (reading *5.0/1023) * 100.0;

Serial.print("temperature = ");

Serial.println(temp);

delay(1000);

Code 2:
#include <LiquidCrystal.h>

const int temperaturePin = A0, rs = 12, en = 11, d4 = 5, d5 = 4, d6


= 3, d7 = 2;

LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup() {

Serial.begin(9600);

void loop() {

int sensorValue = analogRead(temperaturePin);

float temperatureC = (sensorValue*5.0/1023) * 100.0;

lcd.begin(16,2);

lcd.print("Temp: ");

lcd.print(temperatureC);

lcd.setCursor(0, 1);
lcd.print("Status: ");

// Determine the status message based on the temperature range

String status;

if (temperatureC >= 0 && temperatureC <= 100) {

status = "Cold";

} else if (temperatureC >= 150 && temperatureC <= 200) {

status = "Fair";

} else {

status = "Warm";

lcd.setCursor(8, 1);

lcd.print(status);

delay(1000);

You might also like