Table of Contents

Understanding Potentiometers and How to Use Them with Arduino

Example Description
Learn about potentiometers, their working principle, and applications as variable resistors or voltage dividers.

Potentiometer and It’s working

A potentiometer is a versatile three-terminal resistor that forms an adjustable voltage divider or variable resistor (rheostat). It consists of two terminals connected to a resistive element and a third terminal connected to an adjustable wiper. The potentiometer can vary the amount of resistance in the circuit based on the wiper’s position.

Circuit Diagram

Code

  1. Create a variable called “brightness” and set it to 0.
  2. Add the “forever” block from the control palette.
  3. Use the “map” block from the Arduino palette to convert the range of values (0-1023) to the desired range (0-255) for brightness control. Read the values from Arduino pin A0 and place them in the first space of the map function.
  4. Set the brightness variable to the mapped value using the “set brightness to” block.
  5. Use any PWM pin of the Arduino to connect an LED.
  6. Set the PWM value to the brightness variable.
  7. Add these two blocks inside the forever block.
  8. Finally, add when flag clicked event to complete the script.

Script

Output