Reading Light Intensity with a Photoresistor and Arduino Uno

Reading Light Intensity with a Photoresistor and Arduino Uno

Welcome back to Maker Tech Lab! In this tutorial, we will show you how to measure light intensity using a photoresistor (light-dependent resistor) and an Arduino Uno. You will learn how to read analog values and display them on the Serial Monitor.

Materials Needed

  • Arduino Uno
  • Photoresistor (LDR)
  • 10k ohm resistor
  • Breadboard
  • Jumper wires

Circuit Diagram

Let’s set up the circuit. Follow the diagram below:

  1. Connect the Photoresistor: Place the photoresistor on the breadboard. Connect one end to the 5V pin on the Arduino and the other end to an analog pin (e.g., A0).
  2. Add the Resistor: Connect a 10k ohm resistor between the analog pin (A0) and ground (GND).

The Code

Let’s move on to the code. We’ll use the Arduino IDE to write a program that reads the light intensity and displays it on the Serial Monitor.

// Pin where the photoresistor is connected
const int sensorPin = A0;
// Variable to store the sensor value
int sensorValue = 0;
// Setup function runs once when you press reset or power the board
void setup() {
// Initialize the serial communication
Serial.begin(9600);
}
// Loop function runs over and over again forever
void loop() {
// Read the analog value from the sensor
sensorValue = analogRead(sensorPin);
// Print the sensor value to the Serial Monitor
Serial.print(“Light Intensity: “);
Serial.println(sensorValue);
// Wait for a second before taking another reading
delay(1000);
}

Explanation

  • Pin Setup: We define the pin where the photoresistor is connected.
  • Setup Function: We initialize the serial communication at 9600 baud rate.
  • Loop Function: This function runs repeatedly. It reads the analog value from the photoresistor and prints the light intensity to the Serial Monitor every second.

Uploading the Code

  1. Open the Arduino IDE.
  2. Copy and paste the code into the IDE.
  3. Select the correct board and port from the Tools menu.
  4. Click the upload button.
  5. Open the Serial Monitor from the Tools menu to see the light intensity readings.

Conclusion

That’s it! You’ve successfully created a project that measures light intensity using a photoresistor and an Arduino Uno. This project introduces the concept of analog input and data reading, which are essential for working with sensors. Stay tuned for more tutorials and exciting projects at Maker Tech Lab!

Leave a Comment

The technical storage or access that is used exclusively for anonymous statistical purposes.