Potentiometer - AnalogRead


I want to put out some values on the Serial Monitor as I turn the potentiometer around.

But when i do not turn it around, he should not print anything.

I tried it like this:

#define POT A0
#define LED 10
int AnalogerWert;
int DigitalerWert;
float DutyCycle;
int voltage;

void setup()

void loop()
  AnalogerWert = analogRead(POT);
  DigitalerWert = AnalogerWert/4;
  DutyCycle = (((float)DigitalerWert*100.0)/255.0);
  voltage = AnalogerWert * ((float)(5000.0 / 1023.0));
  if (AnalogerWert > 0)
  Serial.println("Analog: " + (String)AnalogerWert + " - Digital: " + DigitalerWert + " - Duty Cycle: " +    DutyCycle + "%" + " - Voltage: " + voltage + "mV");
  analogWrite(LED, DigitalerWert);
  //now i need something, that will break the print and do nothing until the point of turning around the potentiometer.
    delay(?); //well he should delay till I do something. he should give me no results back. but how? 

Do some of you know how to solve my problem?
Is there like a time checking function. Like wait 5ms and check if somethings changed and then print all out, if not then check again and so on...?

Save the previous value. If the new value is the same as the previous value don't print anything.

It may be wise to allow a little slack so that a tiny bit of jitter is not treated as a new value - perhaps the value has to change by +/- 5 to be considered a new value.


Why are all those variables that are used only in loop() global? It is a good idea to keep the scope of variables as small as possible.

Some servo/pot test code you can use to see the output on the serial monitor. You don’t need a servo to just see the output on the serial monitor.

//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor

#include <Servo.h> 
Servo myservoS1;
Servo myservoS2;

int potpinS1 = 0;  //analog input pin A0
int potpinS2 = 1;

int newvalS1, oldvalS1;
int newvalS2, oldvalS2;

void setup() 
  Serial.println("testing dual pot servo");  

void loop() 
  newvalS1 = analogRead(potpinS1);           
  newvalS1 = map(newvalS1, 0, 1023, 0, 179); 
  if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){  
    Serial.print("1- ");

  newvalS2 = analogRead(potpinS2);
  newvalS2 = map(newvalS2, 0, 1023, 0, 179);
  if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){  
    Serial.print("2- ");    
  delay(50); //slow down looping to better read serial monitor 

I tried it like that, and my Potentiometer began to smoke! Haha


Time to get more.