Go Down

Topic: IF statement to be used inside FOR loop with sensor input (Read 18342 times) previous topic - next topic

mrameshwaram

hello,
I am new to Arduino,

I want to do the following stuff in Arduino:

1. Read the signal from sensor and will store it as x. for example x=6.

2. if x=6, "I want to run two motors one after another after getting a signal from IR sensor and stop". This process  should run for X=6 times after each signal input from IR sensor.
I tried this so many times with IF statement inside FOR loop but failed.

3.The loop should end and wait for next X value. It may be 6 or 12 or any thing.

your help will be appreciated.

TheMemberFormerlyKnownAsAWOL

#1
May 27, 2020, 06:30 pm Last Edit: May 27, 2020, 06:31 pm by TheMemberFormerlyKnownAsAWOL
Post what you already tried.

Tell is why it fell short of your expectations.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

TheUNOGuy

You can use a while loop to wait for the input:
Code: [Select]

while ( !irrecv.decode(&results) );
x = results.value;

if ( x == 6 ) {
   // Run the motors
}

It's better if you check the internet  ( your friend ) before posting..! :D
#Learn how to use the FORUM - https://forum.arduino.cc/index.php?topic=148850.0

Go Up