This project presents a low-cost smart streetlight solution designed for rural areas with limited infrastructure. It uses an ESP32 microcontroller, light sensors (LDRs), and ThingSpeak cloud to control a streetlight that turns on only at night and when a vehicle passes by.
- π¦ Streetlight control based on ambient light and car headlights detection
- π§ Multithreaded operation using ESP32 dual-core (LED logic on Core 1, cloud communication on Core 0)
- βοΈ Real-time data upload to ThingSpeak
- π‘ Adjustable light-on time read from ThingSpeak field 3
- π Sends day/night status to field 1
- π Sends car detection log to field 2 (after 20s delay to avoid API flooding)
- π Clear Serial Monitor messages with sensor readings and state
| Component | Quantity | Description |
|---|---|---|
| ESP32 Dev Module | 1 | Microcontroller with dual-core support |
| LDR (photoresistor) | 2 | One for ambient light, one for car detection |
| Resistors (10kΞ©) | 2 | Voltage dividers for LDRs |
| LED (White) | 1 | Simulated streetlight |
| Function | ESP32 Pin |
|---|---|
| Ambient Light Sensor | GPIO 35 |
| Car Detection Sensor | GPIO 32 |
| Streetlight (LED) | GPIO 4 |
| Field | Purpose |
|---|---|
| 1 | Day (1) / Night (0) status |
| 2 | Sends 1 when car is detected |
| 3 | Light on-time in seconds |
β οΈ Note: ThingSpeak limits update frequency to ~15s. This project respects this by only sending car detections 20s after the LED turns on.
- During the day, the streetlight remains OFF.
- At night, the system waits for car headlights to be detected.
- When detected:
- The LED turns ON
- A 20-second timer starts to send a signal to ThingSpeak (Field 2)
- If the car remains near the sensor:
- The LED stays ON and the delay timer resets
- The off-time is configurable via Field 3 in the ThingSpeak channel.
This section shows examples of how the Serial Monitor displays sensor values and system status in real time:
When ambient light is high (above the nightThreshold), the system recognizes it is daytime. The LED remains off, and car detection is ignored:
Ambient Sensor: 1120 | Car Sensor: 850 | Day Ambient Sensor: 1090 | Car Sensor: 950 | Day
When ambient light is low but no car headlights are detected: Ambient Sensor: 820 | Car Sensor: 740 | Night | No Car Ambient Sensor: 790 | Car Sensor: 820 | Night | No Car
If it is night and the carβs headlights are detected (car sensor value exceeds the threshold): Ambient Sensor: 780 | Car Sensor: 1120 | Night | Car Detected LED turned ON - waiting 20s to send to field 2...
If the car remains in place and its headlights continue to be detected after the initial delay: Car still detected β keeping LED ON.
When the car moves away, and the timeout is reached: LED turned OFF β no car detected.
Developed by Group 12, as part of a project for intelligent and sustainable systems using IoT and embedded platforms.
List of authors: ALLISSON SILVA RAYMUNDO, CARLOS AUGUSTO DAVID NETO, DOUGLAS ALESSANDRO DE ALCANTARA, FELIPE BELLO GRIGOLATO, GABRIEL AUGUSTO DAVID, GABRIEL MISTRONI RAMOS SOUZA, GUSTAVO HENRIQUE LOPES CARDOSO, JHUAN CAMARGO, THAIS DE MORAES SOUZA & VITOR TOLEDO.