Hello! I don't know if it's a topic about this open already.
I was wondering how can i get rid of this variation of the analog input as you can see in the serial print bellow for this simple code for instance. Is it something physical (small variations of the V) or software, maybe something to do with the Voltage in my opinion..
Anyway what are your sugestions?
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
When averaging, you still have variations, only moved by a decimal place and/or slower.
What resolution do you need.
If you need less than 10-bit, you could add hysteresis.
Try this (untested) 8-bit output sketch.
Leo..
// converts the position of a 10k lin(B) pot to a byte (0-255)
// pot connected to A0, 5volt and ground
int rawValue; // raw reading
int oldValue; // for deadband
byte Byte; // final byte
byte oldByte; // for printing
void setup() {
Serial.begin(9600);
}
void loop() {
// rawValue = analogRead(A0); // dummy read, if needed
rawValue = analogRead(A0); // read pot
if (rawValue < (oldValue - 2) || rawValue > (oldValue + 2)) { // add some deadband
oldValue = rawValue; // update value
Byte = oldValue >> 2; // convert 10-bit to 8-bit
if (oldByte != Byte) { // only print if value changes
Serial.print("Byte is: ");
Serial.println(Byte);
oldByte = Byte; // update value
}
}
}
for 12-bit you need an external ADC as the Arduino's ADC offers only 10 bits resolution (the ATmega processor based ones, that is - some more exotic flavours of Arduino may offer 12-bit or higher resolution).
that code's indentation is such a mess I can't read it easily. Please fix that first, it's a simple button press (ctrl-T).
wvmarle:
I think two things after reading that message:
for 12-bit you need an external ADC as the Arduino's ADC offers only 10 bits resolution (the ATmega processor based ones, that is - some more exotic flavours of Arduino may offer 12-bit or higher resolution).
that code's indentation is such a mess I can't read it easily. Please fix that first, it's a simple button press (ctrl-T).
It's tennsy 3.2 so it has this resolution
now it's better?
Wawa:
4093 stable values from a common analogue pot?
Sounds like a challenge.
Leo..
it can be higher then this, you recommend even numbers, right?
it can be higher then this, you recommend even numbers, right?
We normally recommend powers of 2 as that's how computers work, so 4092.
But 4092 distinct values from a regular pot? Not much chance to get that perfectly stable. Vibrations from you touching the table may be enough to jump a few points up and down. The higher the resolution of your ADC, the more noise you will see.
That is just too weird a request so it must have popped right out of the realm of possibilities of "what an OP could actually want" making me completely miss the whole request.