I am currently working on a project that involves steering wheels, and I would like a way for Arduino to wait for a change in value. A potentiometer is used and I would like a program to run (say, like lights blinking ) until there is a change in value of the potentiometer ( like an increase in 300).

Thanks in advance.

EDIT I realized that I did not give enough information about what I want, so here is the actual task I am trying to achieve :

The lights goes on when :

Button is pressed

The lights goes off when :

The button is pressed again


Another button is pressed


Potentiometer increases or (only one of it) decreases by 300

Plus I didn't mention that the value of the potentiometer will be constantly changing so the old value for the potentiometer should be the one right after the button press.

Soooo sorry for the inconvenience caused. ( I am really bad at programming)

int oldValue;
void setup()
    oldValue = analogRead(A1);

void loop()
    int value = analogRead(A1);
    while( abs(value-oldValue)<300 )
    oldValue = value;

    // start blinking lights here, as the value has changed by at least 300

  • Gerben thank you but I would like to wait for a change in value, and from my understanding analogRead just reads the value of the pin. Very sorry I didn't mentioned earlier that the analog value must not be zero at the start. – See Jian Shin Jul 23 '16 at 14:49
  • See my edit. It will trigger when the value is increased or decreased by at least 300. – Gerben Jul 23 '16 at 15:05
  • Soo sorry but I updated the question – See Jian Shin Jul 23 '16 at 15:59
  • That's not really how this works (-: First give it a try yourself (more than 30 minutes). If you can't figure it out, come back, and we'll gladly help. – Gerben Jul 23 '16 at 16:04

A change in value is nothing more than that. A change between a value then and the value now.

All you need to do is remember what the value used to be, and compare it with what the value is now. If the two have changed, and the change is big enough, then you do something.

And of course you have to remember that "now" will be "then" "next time".

  • 1
    Thank you Majenko !! ( Gerben basically put your words into c++) – See Jian Shin Jul 23 '16 at 15:32
  • 1
    No, Majenko put my code into words q-; (just check the timestamps) – Gerben Jul 23 '16 at 15:55
  • Soo sorry but I updated the question – See Jian Shin Jul 23 '16 at 15:59
  • @SeeJianShin You might find this useful for introducing you to the concepts you need: hackingmajenkoblog.wordpress.com/2016/02/01/… – Majenko Jul 23 '16 at 16:00

Figured it out in the end. Although my solution doesn't exactly fit what I wanted but it works in this case. I used the FMS Majenko mentioned like this : Wait for potentiometer value to go beyond a certain value, then wait for it to come back to the value. If that happens then the lights stop blinking. Thanks guys( this is quite different from what I initially wanted but it is enough for what it is meant to do)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.