how to control DC motor go forward, reverse and stop with IR sensor?
hello
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
--- CONDITIONS ---
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
Comments
4 years ago
https://www.instructables.com/id/Starting-programmi...
Draw a flow chart then turn each box into the relevant code.
If you don't know the commands you need to look them up or search for examples.
I have issues with using library routines because I don't think they teach people how to program.
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.