why does my potentiometer give me random values to arduino nano?
Here's the code:
int pot = A2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int potval = analogRead(pot);
Serial.println(potval);
delay(100);
}
What value of pot are you using? 10K is usually recommended but 1K will also work and might give less random results. 100K will also work but might give more random results. 1M, 10M etc. too high and will give very random results.
Post a diagram of your circuit and check the actual circuit very carefully
Are you using a breadboard and if so is it the type that has breaks in its power rails ? If the latter then are you sure that the 5V and GND from the Arduino are actually connected to the pot ?
Assuming you are using the sketch in post #1:
disconnect any existing wire from A2 then connect pin A2 to the 5volt terminal.
Do you see a value of 1023 in the serial monitor ?
If you replace the sketch in post #1 with the following sketch, do you notice any difference ?
int pot = A2;
int led = 13 ;
bool flash = false ;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode( led, OUTPUT) ;
}
void loop() {
// put your main code here, to run repeatedly:
int potval = analogRead(pot);
Serial.println(potval);
delay(100);
digitalWrite( led, flash ) ;
flash = !flash ;
}