From the course: Learning Arduino: Pulse Width Modulation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Calibrating an analog input to fade an LED precisely

Calibrating an analog input to fade an LED precisely - Arduino Tutorial

From the course: Learning Arduino: Pulse Width Modulation

Start my 1-month free trial

Calibrating an analog input to fade an LED precisely

- Let's take a look at another great function in Arduino, constrain. In the Arduino IDE, I will select File, Examples, Analog, Calibration. For this sketch, I have a potentiometer attached to A0. I also have an LED with a resistor in series attached to pin 9. This sketch also calls for an LED on pin 13. My board has an onboard LED on pin 13, so I will not set up another LED on the breadboard. This program changes the brightness of an LED based on the value being red from analog 0. However, it begins by going through a calibration phase in the setup function. On start-up, the Arduino watches the analog input for five seconds. It captures the highest and lowest-values and assigns them to sensorMax and sensorMin. While it is doing this, the LED on pin 13 is turned on to signal that the program is in calibration mode. Calibration can be extremely helpful, depending on your project needs. Calibration can make your components more responsive by narrowing the range of map values. Imagine the…

Contents