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

ESP32-Based Ambient Light Monitoring System with I2C LCD Display and Keypad Interface

View and Edit Project In Cirkit DesignerImage of ESP32-Based Ambient Light Monitoring System with I2C LCD Display and Keypad Interface

Circuit Documentation

Summary

This circuit is designed to interface an ESP32 microcontroller with several peripherals including an ambient light sensor, a 4x4 membrane matrix keypad, an I2C LCD 16x2 screen, an I2C module, and a KY-008 laser emitter. The ESP32 reads ambient light intensity and displays the value on the LCD screen. The keypad allows user interaction to retrieve stored light intensity values from memory. The circuit is powered through the ESP32's Vin pin, and common ground connections are established across the components.

Component List

ESP32 (30 pin)

4X4 Membrane Matrix Keypad

I2C LCD 16x2 Screen

I2C Module

KY-008 Laser Emitter

Ambient Light Sensor

Wiring Details

ESP32 (30 pin)

4X4 Membrane Matrix Keypad

I2C LCD 16x2 Screen

I2C Module

KY-008 Laser Emitter

Ambient Light Sensor

Documented Code

/*
 * This Arduino Sketch is designed for an ESP32 microcontroller. It reads the 
 * ambient light intensity using an ambient light sensor and displays the 
 * value in lux on an I2C LCD screen. The values are also saved in memory. 
 * A 4x4 membrane keypad is used to read the saved values from memory.
 */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <EEPROM.h>

// Pin definitions
#define LIGHT_SENSOR_PIN 36 // VP pin
#define KEYPAD_ROWS 4
#define KEYPAD_COLS 4

// I2C LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Keypad setup
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[KEYPAD_ROWS] = {13, 12, 14, 27}; // R1, R2, R3, R4
byte colPins[KEYPAD_COLS] = {26, 25, 33, 32}; // C1, C2, C3, C4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);

// Variables
int addr = 0;

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  pinMode(LIGHT_SENSOR_PIN, INPUT);
}

void loop() {
  // Read light intensity
  int sensorValue = analogRead(LIGHT_SENSOR_PIN);
  float voltage = sensorValue * (3.3 / 4095.0);
  float lux = voltage * 1000; // Assuming a linear relationship for simplicity

  // Display on LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Light Intensity:");
  lcd.setCursor(0, 1);
  lcd.print(lux);
  lcd.print(" lux");

  // Save to EEPROM
  EEPROM.put(addr, lux);
  addr += sizeof(float);
  if (addr >= EEPROM.length()) addr = 0;

  // Check keypad input
  char key = keypad.getKey();
  if (key) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Key Pressed:");
    lcd.setCursor(0, 1);
    lcd.print(key);
    delay(1000);
    if (key == 'A') {
      // Read from EEPROM
      float storedLux;
      EEPROM.get(addr, storedLux);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Stored