RGB LED Overview
The system uses a common anode RGB LED, which has special wiring and logic requirements:- Common Anode: The longest pin connects to 3.3V (positive voltage)
- Three Cathodes: Separate pins for Red, Green, and Blue connect to GPIO pins
- Inverted Logic:
LOWturns LED ON,HIGHturns LED OFF
Why Common Anode?
Common anode LEDs are used because:- Can drive higher brightness with GPIO sinking current
- More stable voltage reference (tied to 3.3V rail)
- Better compatibility with ESP32 output characteristics
Wiring Diagram
Pin Connections
Component List
- RGB LED: Common anode type (4-pin)
- Resistors: 220Ω - 330Ω for each color channel
- Jumper wires: To connect ESP32 to breadboard
Pin Configuration
FromS-Parking.ino:9-11, the default GPIO pins are:
GPIO pin for red LED channel. Active LOW (0V = ON).
GPIO pin for green LED channel. Active LOW (0V = ON).
GPIO pin for blue LED channel. Reserved for future use. Amber is created using red + green.
Alternative GPIO Pins
If you need to use different pins, you can safely reassign to these ESP32 GPIOs: Safe GPIO pins for output:- GPIO 2, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33
- GPIO 0, 1, 3 (boot and serial)
- GPIO 6-11 (connected to flash)
- GPIO 34-39 (input-only, no output capability)
Setup and Initialization
The firmware initializes LED pins insetup() from S-Parking.ino:36-40:
Color States
The system uses three distinct colors to indicate parking space status:Red - Space Occupied
Meaning: A vehicle is physically present in the space Priority: Highest (overrides all other states)- Sensor detects distance < 400mm (or your calibrated threshold)
- Immediate response (within 500ms of car entering)
- State sent to cloud immediately
Green - Space Available
Meaning: Space is empty and not reserved Priority: Lowest (default state)- No vehicle detected by sensor
- Cloud status shows available (status = 1)
- No active reservation
Amber - Space Reserved
Meaning: Space is reserved but not yet occupied Priority: Medium (shown when no physical car present) Created by mixing red + green:- No vehicle detected by sensor
- Cloud status shows reserved (status = 2)
- User has active reservation but hasn’t arrived yet
Common Anode Logic
ThesetColor() function handles the inverted logic required for common anode LEDs from S-Parking.ino:196-203:
Understanding the Inversion
Common Anode Wiring:- Anode (long pin) → Connected to +3.3V
- Cathodes (R/G/B pins) → Connected to GPIO pins
- Current flows from anode to cathode
- To turn LED ON: GPIO must be LOW (0V) → Creates voltage difference → Current flows
- To turn LED OFF: GPIO must be HIGH (3.3V) → No voltage difference → No current
Common Cathode Alternative
If you’re using a common cathode LED instead:- Connect cathode (long pin) to GND
- Logic is NOT inverted:
HIGH= ON,LOW= OFF - Modify
setColor()function:
State Priority Logic
The LED update logic follows a strict priority hierarchy fromS-Parking.ino:173-191:
Priority Explanation
Priority 1: Physical Sensor
Red always wins if the sensor detects a car.Even if cloud shows “available” or “reserved”, the physical presence overrides everything. This ensures accurate real-time feedback.Example: User parks without reservation → Immediate red light
Priority 2: Cloud Reservation
Amber shows when space is reserved but empty.Only applies when sensor shows no car. Alerts other drivers that space is claimed.Example: User reserves spot 10 minutes in advance → Amber light until they arrive
Self-Healing & Synchronization
The LED state automatically corrects itself if cloud and local sensor disagree. FromS-Parking.ino:120-136:
- Lost messages are automatically retried
- LED always reflects true state within 15 seconds
- No manual intervention needed
- System self-corrects network glitches
Testing LED Functionality
Visual Inspection
Power on the ESP32 and verify:
- All three colors can light individually
- No flickering or dim lights (check resistor values)
- Colors are correct (not swapped pins)
- Amber is actually amber (not orange or yellow)
State Transitions
Test all state changes:
- Boot → Green: System starts with green LED
- Green → Red: Place hand over sensor, LED turns red immediately
- Red → Green: Remove hand, LED turns green within 1 second
- Green → Amber: Create reservation via app, LED turns amber within 15 seconds
- Amber → Red: Park car while reserved, LED turns red immediately
Troubleshooting
LED doesn't light up
LED doesn't light up
Possible causes:
- Wrong LED type (common cathode instead of anode)
- Reversed polarity
- Missing resistors causing overcurrent protection
- Bad connection or wrong GPIO pin
- Verify LED type (measure with multimeter)
- Check resistors are in place (220Ω each)
- Test GPIO pins individually with
digitalWrite(pin, LOW) - Verify wiring matches pin definitions
Wrong colors showing
Wrong colors showing
Possible causes:
- Swapped wire connections
- Wrong pin definitions in code
- RGB LED has different pinout than expected
- Verify LED pinout (datasheet or test each pin)
- Swap pin definitions in code to match actual wiring
- Test each color individually with manual
setColor()calls
LED is very dim
LED is very dim
Possible causes:
- Resistors too high (>330Ω)
- Power supply insufficient
- Wrong logic (common cathode code on common anode LED)
- Use 220Ω resistors for brighter output
- Power ESP32 from USB 3.0 port or powered hub
- Verify
setColor()logic matches LED type
LED flickers randomly
LED flickers randomly
Possible causes:
- Loose connections
- Power supply noise
- GPIO conflict with other peripherals
- Secure all connections (solder if possible)
- Add decoupling capacitor (100µF) near LED
- Move to different GPIO pins if conflict exists
Amber looks too red or too green
Amber looks too red or too green
Possible causes:
- Unbalanced resistor values
- LED characteristics (red/green have different brightness)
- Use higher resistor on brighter color (e.g., 330Ω on green, 220Ω on red)
- Use PWM for precise color mixing (advanced)
- Accept slight color variation (most LEDs have natural differences)
Breadboard Wiring Example
For prototyping, here’s the complete wiring:Advanced: PWM Brightness Control
For variable brightness or precise color mixing, you can use PWM (Pulse Width Modulation):Next Steps
Sensor Calibration
Calibrate VL53L0X sensor thresholds
ESP32 Setup
Configure WiFi and flash firmware