Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based IR Object Detection with I2C LCD Display

View and Edit Project In Cirkit DesignerImage of ESP32-Based IR Object Detection with I2C LCD Display

Circuit Documentation

Summary of the Circuit

This circuit integrates an ESP32 microcontroller with a 16x2 I2C LCD screen and an infrared (IR) sensor. The ESP32 is responsible for controlling the operation of the circuit, including reading the status of the IR sensor and displaying the status on the LCD screen. The IR sensor detects the presence of objects, and the LCD provides a visual output of the sensor's status. The circuit is powered by a 5V battery.

Component List

ESP32 (30 pin)

I2C LCD 16x2 Screen

5V Battery

IR Sensor

Wiring Details

ESP32 (30 pin)

I2C LCD 16x2 Screen

5V Battery

IR Sensor

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);
}

Filename: sketch.ino

Description: The code initializes the I2C LCD and configures the IR sensor pin as an input. In the main loop, it reads the IR sensor value and updates the LCD with the status of object detection. If an object is detected, it displays "Object Detected"; otherwise, it shows "No Object". A small delay is included to prevent display flickering.