Wall's Corners Wall's Corners Author
Title: Calibrate a Sensor Automatically (Calibration)
Author: Wall's Corners
Rating 5 of 5 Des:
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 connecte...

During the first 5 seconds that the 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 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.

arts Needed

  • 1 × LDR (Light Dependent Resistor)
  • 1 × LED
  • 1 × 10k resistor
  • 1 × 220 ohm resistor
 Arduino Website Page

Calibration

In the Arduino IDE

File → Examples → 3.Analog → Calibration

Building the Circuit

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.

Programming and Operating the Circuit

In the Arduino IDE, open and upload the Calibration sketch (File → Examples → 3.Analog → Calibration).

Press the Arduino reset button and then move your above the LDR so that a minimum value is sampled and saved. Move your away from the LDR so that it receives more 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.

Share This:

View more at: http://bit.ly/1XReQFr

About Author

Advertisement

Post a Comment

 
Top