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

ESP32-Based IR Object Detection with I2C LCD Feedback

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

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)

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

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".