Photoresistor and Led Experiment with Arduino – Tutorial #11

In this experiment we are going to use a element called photoresistor. This sensor allows us to interact with the external environment, through intensity of light. The photoresistor is based on light resistance, it will sense the light and will allow the microcontroller in this case Arduino to react and change the intensity of Led Diode.

The photoresistor creates a different resistance based on the intensity or the light. Changing the resistance through intensity changes the voltage too. The microntroller reads different values and will light up the Led with more or less intensity. A low resistance value will occur when the sensor is well lighted and a high resistance value will occur when it is in darkness.

Circuits are designed on Fritzing software which is open source and you can design perfectly the Arduino experiments and export the circuits in formats like PCB layout, Fritzing format etc.

Arduino Sketch Code

// source:
int readPinAnalog = 0;
int writePinPwm = 11;
void setup()
   pinMode(readPinAnalog, INPUT);
   pinMode(writePinPwm, OUTPUT)
void loop()
{ // cycle functions below
   int readAnalogValue = analogRead(readPinAnalog);
   int tmp = readAnalogValue / 4; 
} // end of cycle functions

Code Explanation:

We declare the pins the we are going to use for the photoresistor and led diode in lines 1 and 2. At line 3, 4, 5, 6 we need to declare the function of the components that we have connected if is an input or an output . Line 8 is the starting of the cycle that is going to perform while Arduino is powered on. Line 10 is used for reading analog values from photoresistor and storing the values to a variable called “int readAnalogValue”.

Line 11 is a function that stores the value analog read divided by 4 to a new variable called “int tmp”. Line 13 is the function that makes the Led lighting to change and line 14 is the delay that Arduino performs between different values.

No Comments

Join the conversation!

Error! Please fill all fields.