# Controllig LED by Potentiometer

88

Previously, we have used Serial Monitor to send data to the control board, which may be enlightening to know a new software. In this lesson, let’s see how to change the luminance of an LED by a potentiometer, and receive the data of the potentiometer in Serial Monitor to see its value change.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 2: ​Principle

A linear potentiometer is an analog electronic component. So what’s the difference between an analog value and a digital one? Simply put, digital means on/off, high/low level with just two states, i.e. either 0 or 1. But the data state of analog signals is linear, for example, from 1 to 1000; the signal value changes over time instead of indicating an exact number. Analog signals include those of light intensity, humidity, temperature, and so on.

## Step 4: ​Procedures

In this experiment, the potentiometer is used as voltage divider, meaning connecting devices to all of its three pins. Connect the middle pin of the potentiometer to pin A0 and the other two pins to 5V and GND respectively. Therefore, the voltage of the potentiometer is 0-5V. Spin the knob of the potentiometer, and the voltage at pin A0 will change. Then convert that voltage into a digital value (0-1024) with the AD converter in the control board. Through programming, we can use the converted digital value to control the brightness of the LED on the control board.

Step 1:

Build the circuit.

Step 2:

Step 3:

Upload the sketch to the Arduino Uno board

Click the Upload icon to upload the code to the control board.

the bottom of the window, it means the sketch has been successfully uploaded.

Spin the shaft of the potentiometer and you should see the luminance of the LED change.

If you want to check the corresponding value changes, open the Serial Monitor and the data in the window will change with your spinning of the potentiometer knob. This experiment can also be changed to others as you like. For example, use the potentiometer to control the time interval for the LED blinking.

## Step 5: Code

```//Controllingled by potentiometer//Rotate
the shaft of the potentiometer and you should see the luminance of the LED
change.//Email:info@primerobotics.in//Website:www.primerobotics.in/******************************************/const
int ledPin = 9;//the led attach toint
inputValue = 0;//variable to store the value coming from sensorint
outputValue = 0;//variable to store the output value/******************************************/void
setup(){  Serial.begin(9600);//set the serial
communication baudrate as 9600}/******************************************/void
value from the potentiometer  Serial.print("Input: "); //print
"Input"  Serial.println(inputValue); //print
inputValue  outputValue = map(inputValue, 0, 1023, 0,
255); //Convert from 0-1023 proportional to the number of a number of from 0 to
255  Serial.print("Output: "); //print
"Output"  Serial.println(outputValue); //print
outputValue  analogWrite(ledPin, outputValue); //turn the
LED on depending on the output value  delay(1000);}/*******************************************/```

## Recommendations

• ### Internet of Things Class

22,770 Enrolled