ESP32 C3 Super Mini - Light Sensor

Learn how to connect a light sensor (photoresistor/LDR) to your ESP32 C3 Super Mini and read light levels in your Arduino projects. This beginner-friendly guide covers everything from wiring to code.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Light Sensor

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Light Sensor
1×10 kΩ Resistor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Component Options:

The LDR light sensor is very affordable, but it requires a resistor for wiring, which can make the setup more complex. To simplify the wiring, you can use an LDR light sensor module as an alternative.

Overview of Light Sensor

A light sensor (photoresistor) is an analog component that changes its resistance based on the amount of light hitting its surface.

Key Features:

  • Also called photocell, light-dependent resistor (LDR)
  • Detects presence and brightness of ambient light
  • Resistance decreases when exposed to more light
  • Resistance increases in darker conditions
  • Affordable and easy to use for beginners
  • Perfect for automatic lighting projects and light-level monitoring

Technical Specifications:

  • Analog output (variable resistance)
  • Typical resistance range: 200Ω (bright light) to 10MΩ (darkness)
  • Response time: 20-30ms
  • Works with voltage divider circuits

Light Sensor Pinout

The photoresistor has two non-polarized pins.

  • Pin 1: Connect to either voltage divider side
  • Pin 2: Connect to either voltage divider side

Note: Unlike LEDs or diodes, light sensor pins are interchangeable—you don't need to worry about polarity.

Light Sensor Pinout

How Light Sensor Works

The photoresistor's resistance changes inversely with light intensity—more light means less resistance.

Operating Principle:

  • Bright light → Low resistance → Higher voltage at ESP32 analog pin
  • Dim light → High resistance → Lower voltage at ESP32 analog pin
  • ESP32 reads voltage and converts it to a digital value (0-4095)
  • Higher analog values indicate brighter conditions
How Light Sensor Works

WARNING

The value measured by photoresistor reflects the approximated tendency of the light's intensity, it does NOT represent exactly the luminous flux. Therefore, the photoresistor should not be used in an application that requires high accuracy. calibration is also required for some kind application.

ESP32 C3 Super Mini - Light Sensor

The ESP32 C3 Super Mini reads light sensor values through its analog input pins.

How It Works:

  • ESP32 analog pins convert voltage (0V to 3.3V) into integer values (0 to 4095)
  • This digital value is called the ADC (Analog-to-Digital Converter) value
  • Use the analogRead() function to read the sensor value
  • Higher ADC values = brighter light conditions
  • Lower ADC values = darker conditions

Wiring Diagram between Light Sensor and ESP32 C3 Super Mini

Connect the light sensor to your ESP32 C3 Super Mini using a voltage divider circuit with a 10kΩ resistor.

Safety Notes:

  • Note: Double-check connections before powering on
  • Note: Ensure the resistor is 10kΩ for proper voltage division
The wiring diagram between ESP32 C3 Super Mini Light Sensor

This image is created using Fritzing. Click to enlarge image

Wiring Connections:

Light Sensor Pin 1 3.3V
Light Sensor Pin 2 GPIO4 (Analog Pin) + 10kΩ Resistor
10kΩ Resistor (Other End) GND

ESP32 C3 Super Mini Code

Here's how to program your ESP32 C3 Super Mini to read light sensor values and determine brightness levels.

What This Code Does:

  • Reads analog values from the light sensor on GPIO4
  • Converts ADC values into brightness categories
  • Displays light level on Serial Monitor
  • Updates readings every 500 milliseconds
  • Categorizes light as: Dark, Dim, Medium, or Very Bright
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-light-sensor */ #define LIGHT_SENSOR_PIN A0 // The ESP32 C3 SuperMini pin connect to the light sensor void setup() { // Initialize the Serial to communicate with the Serial Monitor. Serial.begin(9600); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); } void loop() { // reads the input on analog pin (value between 0 and 4095) int analog_value = analogRead(LIGHT_SENSOR_PIN); Serial.print("Analog Value = "); Serial.print(analog_value); // The raw analog reading // We'll have a few threshholds, qualitatively determined if (analog_value < 40) { Serial.println(" => Dark"); } else if (analog_value < 800) { Serial.println(" => Dim"); } else if (analog_value < 2000) { Serial.println(" => Light"); } else if (analog_value < 3200) { Serial.println(" => Bright"); } else { Serial.println(" => Very bright"); } delay(500); }

Detailed Instructions

  • New to ESP32 C3 Mini? Complete our Getting Started with ESP32 C3 Mini tutorial first to set up your development environment.
  • Copy the Code: Copy the code above and paste it into Arduino IDE.
  • Select Board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Connect ESP32: Plug your ESP32 C3 Super Mini into your computer via USB Type-C cable.
  • Upload Code: Click the Upload button in Arduino IDE.
  • Open Serial Monitor: Click the Serial Monitor icon or press Ctrl+Shift+M.
  • Set Baud Rate: Set Serial Monitor to 9600 baud.
  • Test the Sensor: Cover the light sensor with your hand, then expose it to bright light.
  • Observe Results: Watch the analog values and light level descriptions change in real-time.
  • Pro Tip: The threshold values (1000, 2000, 3000) can be adjusted based on your ambient light conditions for more accurate readings.
How to open serial monitor on Arduino IDE

Expected Serial Monitor Output:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Analog Value = 3845 => Very bright Analog Value = 3921 => Very bright Analog Value = 3887 => Very bright Analog Value = 2456 => Medium Analog Value = 2398 => Medium Analog Value = 892 => Dim Analog Value = 845 => Dim Analog Value = 312 => Dark Analog Value = 289 => Dark
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

Light Sensor and LED

Now let's create an automatic lighting system that turns on an LED when it gets dark.

Wiring Diagram

Add an LED to your circuit to create a light-activated switch.

The wiring diagram between ESP32 C3 Super Mini Light Sensor LED

This image is created using Fritzing. Click to enlarge image

Additional Connections:

LED Anode (Long Leg) GPIO8 (through 220Ω resistor)
LED Cathode (Short Leg) GND

ESP32 C3 Super Mini Code

This code automatically controls an LED based on ambient light levels—perfect for automatic night lights.

What This Code Does:

  • Reads light sensor values continuously
  • Compares readings to a threshold value (1000)
  • Turns LED ON when it's dark (value < 1000)
  • Turns LED OFF when it's bright (value ≥ 1000)
  • Creates an automatic lighting system
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-light-sensor */ #define LIGHT_SENSOR_PIN A0 // The ESP32 C3 SuperMini pin connect to the light sensor #define LED_PIN D2 // The Arduino NanO ESP32 pin connected to LED #define ANALOG_THRESHOLD 500 void setup() { // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); pinMode(LED_PIN, OUTPUT); // set ESP32 pin to output mode } void loop() { int analog_value = analogRead(LIGHT_SENSOR_PIN); // read the value on analog pin if (analog_value < ANALOG_THRESHOLD) digitalWrite(LED_PIN, HIGH); // turn on LED else digitalWrite(LED_PIN, LOW); // turn off LED }

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a sensor or component. The ESP32 C3 Super Mini's ADC is suitable for projects that do not require high accuracy. However, for projects needing precise measurements, keep the following in mind:

  • The ESP32 C3 Super Mini's ADC is not perfectly accurate and might require calibration for correct results. Each ESP32 C3 Super Mini board can vary slightly, so calibration is necessary for each individual board.
  • Calibration can be challenging, especially for beginners, and might not always yield the exact results you want.

For projects requiring high precision, consider using an external ADC (e.g ADS1115) with the ESP32 C3 Super Mini or using another Arduino, such as the Arduino Uno R4 WiFi, which has a more reliable ADC. If you still want to calibrate the ESP32 C3 Super Mini's ADC, refer to the ESP32 ADC Calibration Driver.

Application and Project Ideas

Now that you know how to use a light sensor with ESP32 C3 Super Mini, here are some practical project ideas:

  • Automatic Night Light: LED turns on automatically when room gets dark
  • Smart Plant Monitor: Track sunlight exposure for your indoor plants
  • Security System: Detect when lights turn on/off in a room
  • Weather Station: Monitor daylight hours and cloud coverage
  • Energy Saver: Automatically control window blinds based on sunlight
  • Photography Light Meter: Measure ambient light for camera settings

Video Tutorial

Watch the video below for a visual walkthrough of this project.

Challenge Yourself

Take your light sensor skills to the next level with these challenges:

  • Easy: Add a buzzer that beeps when light level changes from bright to dark
  • Easy: Display "Good morning!" when light is detected and "Good night!" when it's dark
  • Medium: Create a data logger that records light levels every minute to an SD card
  • Medium: Build a smart curtain controller that opens/closes based on sunrise and sunset
  • Advanced: Implement a solar panel tracker that monitors light intensity from multiple sensors
  • Advanced: Create a greenhouse automation system with light-based watering and ventilation control

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!