Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation. Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)
Target Amount: $2000
Amount Raised: $1339
Top Donor: C.C. $100
Created on: 2 August 2012
During the first 5 seconds that the Arduino sketch for this project runs, it will read the value on analog pin A0 which has an LDR connected to it. The highest and lowest values read on A0 will be saved. After the 5 second period, the Arduino will expect to get values between the highest and lowest values that it saved. It has thus been "calibrated" to these values.
After calibration, the value on the A0 analog pin will be continually read. The value that is read will be converted to a value between 0 and 255. When the minimum saved (calibrated) value is read, it will be converted to 0. When the maximum saved (calibrated) value is read, it will be converted to 255. Any value between the maximum and minimum calibrated values will be converted to a value between 255 and 0.
The converted value is used to change the brightness of the LED connected to Arduino pin 9.
As an example: If the values read from A0 during calibration were between 20 and 100, then in the main program when values between 20 and 100 are received, values between 0 and 255 will be output to the LED.
Without calibration, the LED will never reach full dimness (0) when the lowest value (20) is read from A0. The LED would also never reach full brightness (255) when the highest value (100) is read from A0.
File → Examples → 3.Analog → Calibration
The circuit diagram and breadboard connections are shown on the Arduino website Calibration page. The LED is connected to pin 9 and the LDR to A0.
In the Arduino IDE, open and upload the Calibration sketch (File → Examples → 3.Analog → Calibration).
Press the Arduino reset button and then move your hand above the LDR so that a minimum value is sampled and saved. Move your hand away from the LDR so that it receives more light and a maximum value is sampled and saved. After calibration, the LED will switch on. You can now move your hand around the LDR and see the brightness of the LED change.
Can't see the video? View on YouTube →