Light and Color Sensors
Light and color sensors detect the amount, intensity, wavelength, or color of light.
They are used in:
- Automatic street lights
- Smart homes
- Mobile phones
- Display brightness control
- Robotics
- Line-following robots
- Color detection
- Industrial automation
- Agriculture
- Cameras and imaging systems
- IoT projects
The basic idea is:
Light ↓ Light Sensor ↓ Electrical Signal ↓ Arduino / ESP32 ↓ Processing ↓ Action / Display
1. What is a Light Sensor?
A light sensor is a device that detects the intensity or presence of light and converts it into an electrical signal.
For example:
Dark ↓ Low light detected Bright ↓ High light detected
A microcontroller can use this information to make decisions.
2. What is Light Intensity?
Light intensity describes how much light is present in a particular area or received by a sensor.
For practical lighting measurements, lux (lx) is commonly used.
For example:
Dark room → Low lux Normal room → Moderate lux Bright sunlight → Very high lux
The exact lux level depends on the environment and measurement location.
3. Light Sensor vs Color Sensor
These are related but different.
Light Sensor
Primarily measures:
How much light is present?
Example:
LDR BH1750
Color Sensor
Attempts to determine:
What color or spectral composition is present?
Example:
TCS3200 TCS34725
So:
Light Sensor → Amount of light Color Sensor → Color / RGB information
4. LDR
One of the simplest light sensors is an LDR.
LDR = Light Dependent Resistor
It is also called a photoresistor.
Its resistance changes depending on the amount of light falling on it.
Generally:
More Light ↓ LDR Resistance ↓ Less Light ↓ LDR Resistance ↑
The exact resistance depends on the particular LDR and lighting conditions.
5. LDR Working
An LDR does not directly produce a digital value.
Its resistance changes.
Therefore, we commonly combine it with a resistor to create a voltage divider.
VCC │ LDR │ ├────── Analog Input │ Resistor │ GND
The voltage at the middle point changes with light.
Light changes ↓ LDR resistance changes ↓ Voltage changes ↓ ADC reads voltage
6. LDR with Arduino
A typical Arduino connection:
LDR Circuit │ └──────── A0
Arduino code:
#define LDR_PIN A0 void setup() { Serial.begin(9600); } void loop() { int value = analogRead(LDR_PIN); Serial.println(value); delay(500); }
The value changes as the light level changes.
7. LDR with ESP32
For an ESP32:
#define LDR_PIN 34 void setup() { Serial.begin(115200); } void loop() { int value = analogRead(LDR_PIN); Serial.println(value); delay(500); }
The exact ADC characteristics depend on the ESP32 variant and board configuration.
8. Automatic Street Light
One of the most common LDR projects is an automatic light.
LDR ↓ ESP32/Arduino ↓ Light Level Check ↓ ┌─────┴─────┐ ↓ ↓ Dark Bright ↓ ↓ Light ON Light OFF
Example:
If light level is low ↓ DARK ↓ LED ON
This is a simple example of light-based automation.
9. Photodiode
A photodiode is a semiconductor device that converts incident light into an electrical current.
Basic operation:
Light ↓ Photodiode ↓ Photocurrent ↓ Circuit ↓ Measurement
Photodiodes are generally much faster and more controlled than simple LDRs.
They are used in:
- Optical communication
- Light measurement
- Remote controls
- Encoders
- Barcode readers
- Industrial systems
10. Phototransistor
A phototransistor is a light-sensitive transistor.
It provides higher electrical gain than a basic photodiode in many configurations.
Conceptually:
Light ↓ Phototransistor ↓ Amplified electrical response
Applications include:
- Object detection
- Optical switches
- Line sensors
- Encoders
- IR detection
11. LDR vs Photodiode vs Phototransistor
| Feature | LDR | Photodiode | Phototransistor |
|---|---|---|---|
| Principle | Resistance changes | Photocurrent | Light-controlled transistor |
| Speed | Slow | Fast | Fast |
| Complexity | Low | Medium | Medium |
| Typical use | Light level | Precise/fast light detection | Optical switching |
| Common in beginner projects | Very common | Moderate | Moderate |
12. BH1750
The BH1750 is a digital ambient light sensor.
It is commonly used to measure illuminance in lux.
Unlike an LDR:
LDR ↓ Resistance ↓ Voltage divider ↓ ADC
BH1750:
Light ↓ BH1750 ↓ Digital measurement ↓ I²C ↓ ESP32
This makes it convenient for projects where you want an actual light-level reading.
13. BH1750 Applications
It can be used in:
- Automatic brightness control
- Smart lighting
- Room monitoring
- IoT
- Display brightness adjustment
- Energy-saving systems
Example:
Room gets darker ↓ BH1750 measures lower lux ↓ ESP32 ↓ Increase LED brightness
14. I²C Connection of BH1750
Typical connection to an ESP32:
BH1750 ESP32 VCC ───────── 3.3V GND ───────── GND SDA ───────── GPIO 21 SCL ───────── GPIO 22
Again, the ESP32 I²C pins can be configured differently in software depending on the board.
15. TSL2561
The TSL2561 is another digital light sensor.
It measures ambient light and can provide a more useful light-level measurement than a simple LDR.
It communicates digitally, commonly using:
- I²C
It can be used for:
- Ambient light monitoring
- Automatic lighting
- IoT
- Display control
16. Lux
Lux (lx) is a unit of illuminance.
It describes how much visible light is received per unit area.
Conceptually:
Low lux → Less illumination High lux → More illumination
This is different from simply measuring the electrical resistance of an LDR.
Therefore:
LDR reading ≠ Direct lux measurement
An LDR can be calibrated to estimate light level, but it does not inherently provide a standardized lux measurement.
17. Why Use BH1750 Instead of LDR?
LDR
Advantages:
- Very cheap
- Simple
- Easy to use
- Good for basic projects
Disadvantages:
- Nonlinear response
- Requires an external circuit
- Not inherently calibrated in lux
- Characteristics vary between devices
BH1750
Advantages:
- Digital output
- Convenient lux measurement
- Simple I²C interface
- Better suited to quantitative ambient-light monitoring
So:
Basic project → LDR Actual light-level monitoring → BH1750
18. Color Sensors
A color sensor detects characteristics of reflected or emitted light and estimates color.
Most color sensors use multiple photodetectors with different spectral responses.
A common approach is:
Light ↓ RGB sensing ↓ Red component Green component Blue component ↓ Processing ↓ Color estimation
19. RGB
RGB stands for:
R → Red G → Green B → Blue
Many color sensors measure the relative intensity of these components.
For example:
Red object: R = High G = Low B = Low
Green:
R = Low G = High B = Low
Blue:
R = Low G = Low B = High
The actual measured values depend on illumination and sensor characteristics.
20. TCS3200
The TCS3200 is a popular color-sensing module.
It contains an array of photodiodes with different color filters.
It can provide information corresponding to:
- Red
- Green
- Blue
The sensor uses selectable photodiode filters and outputs a frequency related to the detected light intensity.
Conceptually:
Object ↓ Reflected Light ↓ TCS3200 ↓ RGB-related measurement ↓ Microcontroller
21. TCS34725
The TCS34725 is another popular RGB color sensor.
It provides:
- Red
- Green
- Blue
- Clear/light channel
It commonly communicates using:
I²C
The clear channel helps provide additional information about overall light intensity.
22. Color Detection System
A typical color detection project works like this:
Colored Object ↓ Reflected Light ↓ Color Sensor ↓ RGB Data ↓ ESP32 ↓ Color Algorithm ↓ Detected Color
Example:
R = High G = Low B = Low ↓ RED
23. Important: Ambient Light
Color sensors can be affected significantly by the surrounding light.
For example:
Same Object ↓ Indoor light → One reading Sunlight → Different reading
Therefore, accurate color detection often uses:
- Controlled illumination
- Fixed sensor distance
- Calibration
- Consistent background
24. Color Detection with LED
A practical color sensor can use a white LED to illuminate the object.
White LED ↓ Object ↓ Reflected Light ↓ Color Sensor ↓ ESP32
This makes measurements more consistent because the sensor is less dependent on changing room lighting.
25. RGB LED vs RGB Sensor
These are completely different.
RGB LED
Produces light.
Electrical Signal ↓ RGB LED ↓ Light
RGB Sensor
Detects light.
Light ↓ RGB Sensor ↓ Electrical Signal
Remember:
LED = output of light; sensor = input/detection of light.
26. Color Sensor Applications
Color sensors are used in:
Sorting Machines
Object ↓ Color Sensor ↓ Identify Color ↓ Servo / Motor ↓ Sort Object
For example:
RED → Bin A GREEN → Bin B BLUE → Bin C
Robotics
Robots can use color sensors to:
- Follow colored paths
- Identify objects
- Detect markers
Industrial Automation
Color sensors can check:
- Product color
- Labels
- Packaging
- Manufacturing defects
27. Line-Following Robot
Line-following robots often use infrared reflectance sensors rather than full RGB color sensors.
Basic concept:
IR LED ↓ Floor ↓ Reflected IR ↓ Photodetector ↓ Microcontroller ↓ Motor Control
Typically:
White surface → More reflection Black line → Less reflection
The robot uses this difference to follow the line.
28. Infrared Light Sensors
Infrared sensors detect infrared radiation, which is outside the visible range.
A common IR obstacle sensor contains:
IR LED → Emits IR Photodetector → Receives reflected IR
Basic operation:
IR LED ↓ Object ↓ Reflected IR ↓ Photodetector ↓ Output
These are commonly used for:
- Obstacle detection
- Line following
- Object counting
- Remote-control receivers
29. Light Sensor in Smart Home
A smart home can use a light sensor to automatically control lighting.
BH1750 ↓ ESP32 ↓ Light Level Check ↓ ┌──────┴──────┐ ↓ ↓ Dark Bright ↓ ↓ Light ON Light OFF
A more advanced system can gradually adjust brightness.
Low ambient light ↓ Increase LED brightness High ambient light ↓ Decrease LED brightness
This is called automatic brightness control.
30. Automatic Display Brightness
Smartphones and other devices commonly use ambient-light sensing to adjust screen brightness.
Conceptually:
Ambient Light Sensor ↓ Light Level ↓ Controller ↓ Display Brightness
Example:
Dark room ↓ Reduce brightness Bright outdoor environment ↓ Increase brightness
31. Solar Tracking
Light sensors can also be used in a basic solar-tracking system.
For example, two LDRs can be positioned on opposite sides.
Sun ↓ ┌───┴───┐ LDR1 LDR2
If:
LDR1 > LDR2
the controller can rotate the panel toward one direction.
LDR difference ↓ ESP32 / Arduino ↓ Servo / Motor ↓ Solar panel rotates
This is a simple educational tracking system.
32. Light Sensor + ESP32 IoT
A complete system can be:
Light Sensor ↓ ESP32 ↓ Wi-Fi ↓ Web Dashboard
Example:
------------------------ LIGHT MONITOR ------------------------ Light: 425 lux Status: NORMAL ------------------------
The ESP32 can also automatically control a relay or LED.
33. Comparison of Common Light Sensors
| Sensor | Output | Main Purpose |
|---|---|---|
| LDR | Resistance / Analog | Basic light detection |
| Photodiode | Current | Fast/precise light detection |
| Phototransistor | Electrical output | Optical switching |
| BH1750 | Digital/I²C | Ambient light/lux |
| TSL2561 | Digital/I²C | Ambient light |
| TCS3200 | Frequency | Color sensing |
| TCS34725 | Digital/I²C | RGB + clear sensing |
34. Common Mistakes
Mistake 1: Treating LDR Reading as Lux
An ADC value such as:
750
does not automatically mean:
750 lux
Calibration is required.
Mistake 2: Expecting Accurate Color Detection Without Calibration
Color readings depend on:
- Distance
- Light source
- Object surface
- Background
- Sensor angle
- Sensor characteristics
Mistake 3: Connecting Sensors Without Checking Voltage
Always check:
VCC Logic level Output voltage
especially when connecting modules to ESP32.
Mistake 4: Ignoring Ambient Light
A color sensor can give different results under different lighting conditions.
35. Practical Smart Lighting Project
A good ESP32 project combines:
- BH1750
- ESP32
- LED
- MOSFET or suitable LED driver
Architecture:
ROOM │ ┌──────┴──────┐ ↓ ↓ BH1750 LED │ ↑ ↓ │ ESP32──────────┘ │ Wi-Fi ↓ Web Dashboard
The system measures room brightness and automatically adjusts the LED.
Key Points to Remember
Light sensors
Detect or measure light intensity.
Color sensors
Analyze the characteristics of light, commonly using RGB channels, to estimate color.
Important devices
LDR → Simple light sensing Photodiode → Fast light detection Phototransistor → Light-controlled switching BH1750 → Digital lux measurement TSL2561 → Digital ambient light sensing TCS3200 → RGB color sensing TCS34725 → RGB + clear color sensing
Important units
Lux (lx) → Illuminance RGB → Red, Green, Blue
Basic architecture
Light ↓ Light / Color Sensor ↓ Electrical / Digital Signal ↓ Arduino / ESP32 ↓ Processing ↓ Display / LED / Motor / IoT