Author Options:

how to control DC motor go forward, reverse and stop with IR sensor? Answered


to use arduino, i am trying to control DC motor via IR sensor, but  i have no idea how to coding the source put in the conditions

the conditions are under

parts -

1. arduino Mega
2. IR sensor
3. DC motor
4. L298n(motor driver)

Current state  = DC motor STOP / IR sensor ON


1. IR sensor - no detected - DC motor Stop

2. IR sensor detected - DC motor go forward(set time) - STOP - IR sensor no detected during (set time)- DC motor reverse(set time) - STOP

3. IR sensor detected - DC motor go FW(set time) - STOP - secondly, IR sensor detected - DC motor reverse(set time)

4. During DC motor go forward, IR sensor detected sencondly - DC motor reverse(as time go forward as ) - STOP

another example

1. <STOP> - IR - detected - DC motor FW(4sec) - STOP - IR sensor no detected untill ( 25 sec) - DC motor RV(4sec) - STOP
2. IR  - detected - during DC motor forwarding ( 2.4 sec) - IR sensor detected - DC motor reversing (2.4 sec) - STOP
3. <STOP> - IR - detected - DC motor FW(4 sec) - STOP - (after 18 sec(less then 25sec)) IR sensor detected - DC motor reversing (4sec) - STOP


The forums are retiring in 2021 and are now closed for new topics and comments.

4 years ago

Start simple. Make the motor turn first.


Answer 4 years ago

After that ask your teacher for more reference link ;)
There are more than enough examples already included in the IDE, all you need to do is read them and combine the right two or three sketches.