close
KnowledgeBase

Arduino Starter’s Guide (7/7): Potentiometer and LED

IMG_4892

A potentiometer takes an input voltage and outputs a variable amount of it to a circuit, which is determined by the position of a slider on a resistive element. The potentiometer can be used as a voltage regulator, as described above, a means of introducing a variable amount of resistance into a circuit or as a means of adjusting the power in a circuit. The last case, it is filling the role of a rheostat. These inputs take a voltage (from 0 to 5 volts) and convert it to a digital number between 0 (0 volts) and 1023 (5 volts) (10 bits of resolution).

Hardware Used:

  • 1 – LED
  • 1 – Arduino UNO
  • 1 – 10k potentiometer
  • 1 – 100 ohms Resistor

You can buy all this Hardware at Createlabz.

Software Used:

Arduino IDE

Set up the Hardware:

 

 

Code:

Code Breakdown:

Pins for the Potentiometer and LED.

declares the ledPin as an OUTPUT

it will map input voltages between 0 and 5 volts into integer values between 0 and 1023.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.

Try MORE!!!!

Threshold Switching:

If you want to switch an output when value exceeds certain threshold. Change the loop code to.

Fading:

To control the brightness of a LED directly from the potentiometer. To do this we need to first change the pin LED from pin 13 to pin 9.

and change the loop code to.

then upload the code and watch as the led fades in relation to your potentiometer twisting.

 

Tags : arduinoArduino KitLedpotentiometerStarter Kit

Leave a Response