Circuit Documentation
Summary of the Circuit
The circuit is designed to interface an ESP32 microcontroller with an I2C LCD screen and an IR sensor. The ESP32 reads the status of the IR sensor and displays whether an object is detected on the LCD screen. The ESP32 is powered by a 5V battery, and the IR sensor is powered by the 3.3V output from the ESP32. The LCD and the IR sensor are connected to the ESP32 via I2C and digital input pins, respectively.
Component List
ESP32 (30 pin)
- Description: A microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
I2C LCD 16x2 Screen
- Description: A 16x2 character LCD display with an I2C interface.
- Pins: SCL, SDA, VCC (5V), GND, VDD, VO, RS, RW, E, D0, D1, D2, D3, D4, D5, D6, D7, BLA, BLK
5v Battery
- Description: A power source for the circuit.
- Pins: Positive, Negative
IR Sensor
- Description: A sensor that detects infrared light to sense the presence of objects.
- Pins: Out, GND, VCC
Wiring Details
ESP32 (30 pin)
- GND connected to the negative terminal of the 5v battery and GND of the IR sensor.
- Vin connected to the positive terminal of the 5v battery.
- D22 (SCL) connected to SCL of the I2C LCD Screen.
- D21 (SDA) connected to SDA of the I2C LCD Screen.
- D2 connected to the Out pin of the IR sensor.
- 3V3 connected to VCC of the IR sensor.
I2C LCD 16x2 Screen
- SCL connected to D22 (SCL) of the ESP32.
- SDA connected to D21 (SDA) of the ESP32.
- GND connected to the negative terminal of the 5v battery.
5v Battery
- Positive terminal connected to Vin of the ESP32.
- Negative terminal connected to GND of the ESP32 and the I2C LCD Screen.
IR Sensor
- Out connected to D2 of the ESP32.
- GND connected to GND of the ESP32.
- VCC connected to 3V3 of the ESP32.
Documented Code
/*
* ESP32 Interface with I2C LCD and IR Sensor
* This code reads the status of an IR sensor and displays it on an I2C LCD.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define the I2C address for the LCD
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_ROWS 2
// Initialize the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_ROWS);
// Define the IR sensor pin
const int irSensorPin = 2;
void setup() {
// Initialize the LCD
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("IR Sensor Status:");
// Initialize the IR sensor pin
pinMode(irSensorPin, INPUT);
}
void loop() {
// Read the IR sensor value
int irValue = digitalRead(irSensorPin);
// Display the IR sensor status on the LCD
lcd.setCursor(0, 1);
if (irValue == HIGH) {
lcd.print("Object Detected ");
} else {
lcd.print("No Object ");
}
// Small delay to avoid flickering
delay(200);
}
This code is designed to run on the ESP32 microcontroller. It initializes the I2C LCD screen and the IR sensor pin. In the main loop, it reads the IR sensor and updates the LCD with the sensor status. If an object is detected, it displays "Object Detected"; otherwise, it shows "No Object".
