I connected a potmeter to my arduino like in this tutorial. https://www.arduino.cc/en/tutorial/potentiometer
But when printing the output to the monitor i get values of 0,1, 2 & 3 instead of a value between 0 and 1023.
Anybody got an idea why?
I connected a potmeter to my arduino like in this tutorial. https://www.arduino.cc/en/tutorial/potentiometer
But when printing the output to the monitor i get values of 0,1, 2 & 3 instead of a value between 0 and 1023.
Anybody got an idea why?
Post your code and circuit here
Circuit is like here https://www.arduino.cc/en/tutorial/potentiometer
#include <Wire.h>
int status_module = 0;
#define potmeter A3
void setup() {
Serial.begin(9600);
Wire.begin(1);
Wire.onRequest(requestEvent);
}
void loop() {
int pot_waarde = analogRead(potmeter);
Serial.println (pot_waarde);
}
//SUB-ROUTINES
void requestEvent() {
Wire.write(status_module);
}
Let’s see your actual wiring.
.
Hi,
If you have the center terminal of the pot connected to A2.
Then
#define potmeter A3
should be.
#define potmeter A2
Tom...
I found the problem. I had the potmeter hooked on the 5v and GND of another arduino (the master) and to pin A3 of the slave, where the sketch is running. I didn't think that would matter, but does... Anybody able to explain why?
Have you got the grounds of the two Arduinos connected together?
If not you won't get a proper reading.
You need to connect the two grounds together so that the second arduino has a zero volt reference to measure from.
If you were trying to measure the voltage with a multimeter, you wouldn't expect to get a correct reading with only the red probe connected, would you? That is in effect what you were trying to do.
If you would have replied to this "Let's see your actual wiring" as requested, we could have seen the problem.
justvervaart:
I found the problem. I had the potmeter hooked on the 5v and GND of another arduino (the master) and to pin A3 of the slave, where the sketch is running. I didn't think that would matter, but does... Anybody able to explain why?
WHAT OTHER ARDUINO? ? ? ?
There is only ONE Arduino in the link and diagram you referred too, saying;
[u]**I connected a potmeter to my arduino like in this tutorial. https://www.arduino.cc/en/tutorial/potentiometer**[/u]
No you didn't!
Why connect to another Arduino when the tutorial shows you don't?
Tom... :o