Light Detection
Control LED brightness depending on the amount of light
In this program we will learn two different concepts.
Control brightness of LED depending on the amount of light that falls on one of the Light Detecting Resistor (LDR)
Display the analog value read by the two LDR's on a serial monitor.
To begin with, upload the program below and monitor the LED. Move the hand closer to dim the LED. Flash a light on the LDR and the LED turns brighter. The inverse effect (LED brightens with lesser light) is also possible by changing the threshold_val
and modifying the if
condition.
Serial Monitor is an essential tool when creating projects with Arduino. It can be used as a debugging tool, testing out concepts or to communicate directly with the Arduino board. Its job is to allow you to send messages from your computer to an Arduino board (over USB) and also to receive messages from the Arduino board.
Arduino IDE has Serial Monitor tool integrated with the editor, which means that no external software is required.The command 'Serial.begin(9600)' starts serial communication, so that Arduino can send out commands through the USB connection. The value 9600 is called the 'baud rate' of the connection. This is how fast the data is to be sent. You can change this to a higher value, but you will also have to change the Arduino Serial monitor to the same value.
Once the code is uploaded, Tools -> Serial Monitor opens a new window where all the messages are displayed. You should be able to see LDR values printed on the monitor. For Arduino versions > 2.0, Serial monitor is built into the IDE and does not open a new window.
Last updated