AdSense

Friday, July 14, 2017

10 - Arduino: sensing light with a Photoresistor


ARDUINO: SENSING LIGHT WITH A PHOTORESISTOR

- Layout for this exercise:





1 - Introduction


The purpose of this exercise is to demonstrate how an Arduino board can be used to implement a safety measure consisting of establishing a line between a source of light (LASER or flashlight) and a photoresistor, so that when the light line breaks the alarms are triggered:

https://www.youtube.com/watch?v=mr834Cs9ncs

https://www.youtube.com/watch?v=KX2_LCUkhDs


photoresistor is a light controlled variable resistor, occurring that the resistance decreases with increasing incident light intensity, exhibiting photoconductivity.

- A photoresistor can be applied in light sensitive detector circuits, and light and dark activated switching circuits.

https://en.wikipedia.org/wiki/Photoresistor


- The schematics for this exercise is pretty simple, the only remarkable issue is to connect one of the legs of the photoresistor to the analog pin A0, where the light level readings are received.



2 - Code

- Code for this exercise:









- Let's analyze the code.

- First of all, the pins for the photoresistor (A0), buzzer (11) and RGB LED (3,5,6) are set:




- The photoresistorPin is directly connected to the analog A0, so the input reading measures the light received from the enviroment:

 


- If the reading is below the threshold 500 nothing happens, for instance when a LASER  or a great source of light is pointing to the photoresistor.

- However, if the reading goes above the threshold 500, for instance when the light line of sight is broken between the source of light and the photo cell, both the buzzer alarm and the Colors() function are triggered, and also an ALARM message is printed at the serial monitor:



- Finally, the functions Colors() and noColors() determine the combination of the RGB LED lights when the alarm is triggered and when the system runs normally.


3 - Running the program

- The serial monitor displays readings from the analog pin A0, showing an ALARM message only when the reading goes above the threshold 500:




- Testing the circuit, in this video it can be checked how the system is quiet when a flashlight points to the photoresistor. However, as expected all the alarms go off when the flashlight is retired: