A photo resistor (LDR) is a simple and easy component to measure the light in your environment. The LDR is usually used in a voltage divider circuit with an additional resistor.
The voltage U is according the current light situation.
Low voltage = dark (Night)
High voltage = bright (Day)
In order to read the LDR light sensor value you need a microcontroller circuit or microcontroller board with an onboard Analog/Digital Converter (ADC). Arduino Boards, like the Arduino Uno, have analog inputs to read analog sensor data (A0-A5).
But if you already have used all analog pins in your Arduino project you need an other solution for your light sensor.
The solution is the Grove Photo Resistor with I2C interface.
Seeedstudio Grove SystemThe Grove system with standard connectors are designed by the chinese maker company Seeedstudio (https://www.seeedstudio.com/).
Grove is a modular, standardized connector prototyping system. As a user you can connect blocks to you base system without soldering wires or jumper wires on a breadboard.
In the meantime Seeedstudio provides a large number of boards and sensor modules. The system is an ideal plattform for education or prototyping.
Seeedstudio is currently running a co-invent campaign and supports the makers of the world with their own Grove Sensor Module Design.https://www.seeedstudio.com/blog/2022/07/15/ignite-your-passion-fire-your-thoughts-develop-your-grove-sensor-with-seeed-fusion-for-a-chance-to-win-over-300usd-cash-prize%EF%BF%BC/
Grove Photo Resistor with I2C interfaceThis Photo Resistor Board Design is taking part in this Seeedstudio campaign.
CircuitThe idea of the circuit is simple. An Analog-Digital converter converts the analog sensor signal into a digital, serial signal. The Grove system is based on the I2C interface. Therefore an ADC with I2C interface is used.
The following image shows the final circuit diagram.
IC1 (MCP3421) is a 6-pin ADC with I2C interface.
R1 and R1 are the pullup resistors for the I2C interface.
The LDR and R3 are working as a voltage divider. The sensor signal goes to pin 1 of the ADC.
TechnicalPower Supply: 3.3-5V
Interface:I2C with Grove Connector
Sensor:Photo resistor LDR
Analog-Digital-Converter:MCP3421
Resolution:Up to 18 bits
Input Channel:1
I2C Address:0x68
PCBThe finished PCB has the standard size of a Grove Module. All components are SMD, except the photo resistor (LDR).
The Arduino code for this project is pretty simple and it is based on the Arduino Library MXP342X
https://github.com/uChip/MCP342X
The latest code is available on my Github account
https://github.com/arduinopraxis/Grove_Photo_Resistor/tree/main/Code
Arduino Sketch:
//
// Grove I2C LDR mit MCP342x - Read Analog Value
// Datei: 555_grove_ldr_i2c_read.ino
// Datum: 15.09.22/TB
//
// Arduino Library
// https://github.com/uChip/MCP342X
#include <Wire.h>
#include <MCP342X.h>
MCP342X myADC;
void setup()
{
Wire.begin();
TWBR = 12; // 400 kHz (maximum)
Serial.begin(9600);
while (!Serial) {} // wait for Serial comms to become ready
Serial.println("Grove Photo Resistor..");
Serial.println("Testing device connection...");
Serial.println(myADC.testConnection() ? "MCP342X connection successful" : "MCP342X connection failed");
myADC.configure( MCP342X_MODE_CONTINUOUS |
MCP342X_CHANNEL_1 |
MCP342X_SIZE_16BIT |
MCP342X_GAIN_1X
);
Serial.println(myADC.getConfigRegShdw(), HEX);
Serial.println("Environment Light:");
Serial.println("-----------------------");
delay(1000);
}
void loop()
{
static int16_t result;
myADC.startConversion();
myADC.getResult(&result);
// Serial Output
Serial.println(result, DEC);
// warten
delay(1000);
}
Other languagesIf you prefer a Raspberry Pi, Raspberry Pi Pico or other RP2040-based board take a look a this Micropython library.
https://github.com/jajberni/MCP342x_LoPy
TestingAfter upload the code into the Arduino IDE you can open the serial monitor.
The serial output displays the setup information and after the live environmental values (Values between 0 and 32676).
Move you hand on the LDR sensor and you will see the change of the numbers.
Use cases
The Grove Photo Sensor is a perfect light sensor for
- Smarthome applications
- Detection of dark/bright, Light on/off
- Robot applications
Comments
Please log in or sign up to comment.