# Potentiometer Values Shown by LED's

2,594

4

2

I'm a beginner with the Arduino and have started to make leaps and bounds with my projects. This is a segment of another project in which I am using a potentiometer to control fixed pwm signals for a large electric solenoid which operates a hydrolic wheel. When I completed this project I realized that I would like to see a simple display of the values based on the position of the pot to gauge the rotation of this wheel. I decided that the easiest way to do this was with a set of LED's. I plan to eventually post the completed project in the future, but for now here is the pot with LED's. This project will outline the components, schematic, and code for the Arduino.

### 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 1: Components

To replicate this project you will need:

1. Arduino board
2. (3) 330 Ohm resistors
3. (3) LED's; preferably different colors so you can tell the difference between values
5. Potentiometer (through hole leads is easier, but I soldered wires onto mine)

First, you will need to wire the project based on this schematic. The wiper lead on the pot goes to analog 2 on the Arduino, red led to Digital 13, yellow led to digital 8, and green led to digital 12. The led's ground leads should go through the 330 ohm resistors to ground. I like to pull 5v and ground to my bread-board also to make the wiring easier. I also put the pot positive, ground and wiper lead on the bread-board and jumpered the wiper lead over to the Arduino.

## Step 2: Arduino Code

Next, copy and paste this code into your Arduino IDE window and upload it to the board. After uploading, you should be able to rotate the pot and the different pot value ranges specified in the code will turn on the 3 different LED's. I basically set ranges for high medium and low. If you want to change the ranges feel free. You could even set more ranges with more LED's if you wanted to. The video I have is awful, so maybe you can make do with 3 pictures and your own setup when you have it completed.

I hope you enjoyed this instructable. It is a very easy project and was great for a beginner like myself to design my own code for a specific purpose.

//Potentiometer_Values_Code

const int ledgreen         = 12;    // DIGITAL PIN GREEN LED CONNECTED TO
const int ledyellow        = 8;     // DIGITAL PIN YELLOW LED CONNECTED TO
const int ledred           = 13;    // DIGITAL PIN RED LED CONNECTED TO
const int potpin           = A2;     // DIGITAL PIN POTPIN CONNECTED TO

int sensorValue = 0;

void setup() {
Serial.begin (9600);
pinMode (ledgreen, OUTPUT);   // DECLARE GREEN LED, (PIN 12) AS OUTPUT
pinMode (ledyellow, OUTPUT);  // DECLARE YELLOW LED (PIN 8) AS OUTPUT
pinMode (ledred, OUTPUT);     // DECLARE RED LED (PIN13) AS OUTPUT
pinMode (potpin, INPUT);      // DECLARE THE POTPIN (ANALOG 2)AS INPUT
}

void loop() {
if ((sensorValue >= 0) && (sensorValue <= 300))
{
digitalWrite (ledgreen, HIGH);
digitalWrite (ledyellow, LOW);
digitalWrite (ledred, LOW);
}

else
{
digitalWrite (ledgreen, LOW);
}
if ((sensorValue > 300) && (sensorValue < 900))
{
digitalWrite (ledyellow, HIGH);
digitalWrite (ledgreen, LOW);
digitalWrite (ledred, LOW);
}
else
digitalWrite (ledyellow, LOW);

if (sensorValue >= 900)
{
digitalWrite (ledred, HIGH);
digitalWrite (ledyellow, LOW);
digitalWrite (ledgreen, LOW);
}
else
digitalWrite (ledred, LOW);
Serial.print("sensor = ");
Serial.print(sensorValue);

}

Participated in the
Arduino Challenge

## Recommendations

• ### Internet of Things Class

22,853 Enrolled

## 2 Discussions

Your right, alone, this is over-complicated. I produced some code with the arduino to sporadically turn these wheels called comber wheels which contain tines for combing out grape vines. The arduino translates PWM into hydrolic signals (through a hydraulic solenoid) which controls the sporadic nature of these wheels. I designed the code to alter the frequency of the sporadic turning of these wheels. I needed a way to easily tell at what level the pot was at so I added this small section of code which lights up the led's (the project you have commented on).

I see what you mean though. Without explaining the full nature of the project it appears to be a useless stop light controlled by a pot. I have not posted the original instructable because i don't think it is probable that anyone would want to translate pwm signals through hydraulics, nor should they put that strain on the hydraulic solenoids by doing this. The individual who requested this was using a foot pedal to do this same thing and would damage the solenoids eventually anyway, so at least this process is automated.

Why do you need an Arduino for this? This seems overly complicated.