Projects / Light level dashboard

Light level dashboard

Beginner35 minGuided buildReviewed
ESP32 DevKit3V3GPIO34GPIO21GPIO22GNDLDR + 10 kΩDark (raw 210)raw 2240OLEDLevel
Serial at 115200 baud

Tap a part to see what it does.

Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.

Build it step by step

0 of 4 done
  1. ESP32581 lux

    Build the divider

    LDR from 3V3 to a row, 10 kΩ from that row to GND, and the row to GPIO34.

  2. ESP3214.9 mASSD1306

    Add the OLED

    SDA GPIO21, SCL GPIO22.

  3. ESP32

    Upload

    Open the Serial Plotter to watch the raw value.

  4. ESP32583 lux

    Set your thresholds

    Cover, shade and light the LDR; adjust the numbers in label() to suit your room.

In short

How do you build a light level dashboard?

An LDR and a 10 kΩ resistor make a light sensor; the ESP32 shows the level as a bar on an OLED and names it Dark, Dim, Room or Bright. You need ESP32 DevKit V1, LDR Photoresistor, Resistor 10 kΩ, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 4 steps and about 35 minutes.

Level
Beginner
Time
About 35 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
LDR one legESP32 3V3Top of the divider
LDR other legGPIO34 and 10 kΩ to GNDDivider middle to ADC
OLED SDA / SCLGPIO21 / GPIO22I2C
OLED VCC / GND3V3 / GNDPower

Code

Library: Adafruit SSD1306. GPIO34 is input-only and on ADC1, so it keeps working with Wi-Fi on. Thresholds are a starting point: note your own readings.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const char* label(int raw) {
  if (raw < 400) return "Dark";
  if (raw < 1500) return "Dim";
  if (raw < 3000) return "Room";
  return "Bright";
}

void setup() {
  Serial.begin(115200);
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  oled.setTextColor(SSD1306_WHITE);
}

void loop() {
  long sum = 0;
  for (int i = 0; i < 16; i++) sum += analogRead(34);
  int raw = sum / 16;
  oled.clearDisplay();
  oled.setTextSize(2); oled.setCursor(0, 0); oled.print(label(raw));
  oled.drawRect(0, 30, 128, 14, SSD1306_WHITE);
  oled.fillRect(2, 32, map(raw, 0, 4095, 0, 124), 10, SSD1306_WHITE);
  oled.setTextSize(1); oled.setCursor(0, 52); oled.print("raw "); oled.print(raw);
  oled.display();
  Serial.println(raw);
  delay(250);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

2047
2048
2047
2048
2047
2048

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Cover the LDRShows Dark, raw below about 400
Phone torch on itShows Bright, bar nearly full
Room lightSteady reading, wobbling only a few counts thanks to averaging

If it does not work

Always 0

The divider middle is not on GPIO34, or the 10 kΩ goes to 3V3 instead of GND.

Always 4095

LDR and resistor swapped is fine (inverted), but 4095 means a short to 3V3.

Readings jump

Average more samples, and keep wires short.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the light level dashboard?

ESP32 DevKit V1, LDR Photoresistor, Resistor 10 kΩ, SSD1306 OLED Display and Breadboard 830 Tie Points.

How long does the light level dashboard take to build?

About 35 minutes for a beginner maker, in 4 steps.

How do I know the light level dashboard works?

Cover the LDR: Shows Dark, raw below about 400. Phone torch on it: Shows Bright, bar nearly full. Room light: Steady reading, wobbling only a few counts thanks to averaging.

Always 0: what should I check?

The divider middle is not on GPIO34, or the 10 kΩ goes to 3V3 instead of GND.

Always 4095: what should I check?

LDR and resistor swapped is fine (inverted), but 4095 means a short to 3V3.

Readings jump: what should I check?

Average more samples, and keep wires short.