21BCP406 LAB7 (1)
21BCP406 LAB7 (1)
21BCP406 LAB7 (1)
Part A
th
Class B Tech CSE 4 Year Sub: Internet of Things
Lab
Aim: LCD will be used with Arduino / ESP32 with various sensors.
Prerequisite: Basics of programming, microcontrollers and basic electronics
Outcome:
1. Study and work of LCD.
2. Connecting microcontroller board with LCD.
3. Display of sensor data over the 16X2 LCD.
Theory:
1. Study and work of LCD.
2. Connection of 16X2 LCD with Arduino and ESP 32 microcontroller boards.
3. Display the values sensed by various sensors, such as ultrasonic sensors,
photosensitive resistance, and potentiometers.
4. Use a DHT sensor to display the temperature and humidity of the atmosphere.
Steps:
#include <Wire.h>
#include<LiquidCrystal_I2C.h>
void loop() {
// put your main code here, to run repeatedly: lcd.setCursor(1, 0);
lcd.print("Hello World"); delay(3000);
lcd.clear();
Output:
Steps:
#include <Wire.h>
#include<LiquidCrystal_I2C.h>
long duration;
int distance;
void setup() {
// put your setup code here, to run once:
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.init();
lcd.backlight();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
lcd.clear(); lcd.setCursor(0,
0); lcd.print("Distance: ");
lcd.print(distance);
lcd.print(" cm");
delay(3000);
}
Output:
#define POT_PIN 34
lcd.setCursor(0, 1);
lcd.print("Percent: "); lcd.print(potPercent);
lcd.print("%");
delay(500);
}
21BCP406 G12 TEJAS MISTRY
Output:
Steps:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define DHTPIN 2
#define DHTTYPE DHT22
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
dht.begin();
lcd.setCursor(0, 0);
lcd.print("Temp & Humidity");
delay(2000); lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
float humidity = dht.readHumidity(); float temperature
= dht.readTemperature();
if(isnan(humidity) || isnan(temperature)){
lcd.setCursor(0, 0); lcd.print("Sensor
Error!");
Serial.println("Failed to read from DHT Sensor!"); return;
}
delay(2000);
}
21BCP406 G12 TEJAS MISTRY
Output: