Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

Lesson 11: Photoresistor Module

In this lesson, you will learn how to measure light intensity using a photoresistor sensor with an Arduino Uno. We’ll cover reading and displaying the analog values from the sensor, which reflect the amount of light it detects. This project is ideal for beginners as it provides hands-on experience in working with sensors and understanding analog input on the Arduino platform. You’ll also improve your proficiency in serial communication by outputting sensor readings to the serial monitor.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Universal Maker Sensor Kit

94

Universal Maker Sensor Kit

You can also buy them separately from the links below.

Component Introduction

Purchase Link

Arduino UNO R3 or R4

BUY

Photoresistor Module

BUY

Wiring

../_images/Lesson_11_photoresistor_module_uno_bb.png

Code

Code Analysis

  1. Setting Up the Sensor Pin and Serial Communication

    We start by defining the sensor pin and initializing serial communication in the setup function. The photoresistor is connected to the analog pin A0.

    const int sensorPin = A0;  // Pin connected to the photoresistor
    
    void setup() {
      Serial.begin(9600);  // Start serial communication at 9600 baud rate
    }
    
  2. Reading and Displaying Sensor Data

    In the loop function, we continuously read the analog value from the sensor and print it to the Serial Monitor. We also add a short delay to stabilize the readings.

    void loop() {
      Serial.println(analogRead(sensorPin));  // Read and print the analog value
      delay(50);                              // Short delay to stabilize readings
    }