Integrating IR sensor and Motors

Hello guys, I’ve just jumped into the Arduino bandwagon recently . Glad to see much helpful threads around :wink: :wink:

Okay, so I have this project where I would need to integrate TCRT5000 (its an IR sensor) with 2 motors where when the IRs detect a black line/tape . The motor would stop and reverse back to another direction .
In short, the project is a robot which motor’s would turn away from the black tape detected via the TCRT5000 IR sensor and just move around the place which has no black tape.

I already have a partial code (for the motor and the sensor), I did not integrate everything yet . Is there any tips here on how should I integrate the IR sensor and the motor’s codes together ?
I know the if loop could be used, but I can’t think of a way to implement it, would be helpful if someone here gives me some examples on how to perform the coding .

Thanks alot guys ! :smiley: :smiley:

2motor run.txt (1.5 KB)

newIR.txt (910 Bytes)

I know the if loop could be used

The if STATEMENT does not loop.

Hi PaulS, thanks for the heads up, appreciate it =)

If I'm not mistaken, the if statement has the condition if it satisfies the condition then it would run, else it would initiate other instructions instead . Pardon for my rusty C programming language, I'm still a new in this :-\