Light-sensitive Array

This program converts the readings from a light-dependent resistor into a corresponding number of illuminated LED lights, creating a simple indicator of light brightness.

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

Elite Explorer Kit

300+

Elite Explorer Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

Arduino Uno R4 WiFi

-

Breadboard

BUY

Jumper Wires

BUY

Resistor

BUY

LED

BUY

Photoresistor

BUY

Wiring

../_images/04_light_sensitive_array_bb.png

Schematic

../_images/04_light_sensitive_array_schematic.png

Code

Note

  • You can open the file 04_light_sensitive_array.ino under the path of elite-explorer-kit-main\fun_project\04_light_sensitive_array directly.

  • Or copy this code into Arduino IDE.

How it works?

Here’s a step-by-step explanation of the code:

  1. Constant and Variable Definitions:

    NbrLEDs: Defines the presence of 8 LEDs. ledPins[]: LEDs are connected to Arduino pins 5 to 12. photocellPin: The photoresistor is connected to Arduino’s A0 pin. sensorValue: This variable stores the value read from the photoresistor. ledLevel: This variable stores the number of LEDs based on the sensorValue conversion.

  2. setup():

    Configures pins 5 to 12 as output to drive the LEDs.

  3. loop():

    Reads the analog value of the photoresistor from pin A0, typically ranging from 0 to 1023. Uses the map function to map the photoresistor’s value from the range 300-1023 to the range 0-8. This means that if the reading from the light-dependent resistor is 300, no LEDs will be lit; if the reading is 1023 or higher, all 8 LEDs will be lit.

    The subsequent for loop checks each LED. If its index is less than ledLevel, the LED will be turned on; otherwise, it will be turned off.