56Views3Replies

Author Options:

how to control a dc motor by taking the user input? Answered

I am trying to write a code to control a DC motor with the user input. The motor needs to stop after N iterations where N is given by the user. Each iteration doesn't have a specific time hence I used an IR sensor. The motor must rotate until the IR value is high and in N iterations the IR value becomes N times low. I hope you understand my question. Please help me with the code.

Discussions

0
iceng
iceng

4 years ago

Set up a counter that adds each IR iteration Using the interrupt structure ma work better then polling the sensor.

Then keep comparing the stored N value to the counter and branch when equal.

0
VinodhT
VinodhT

Answer 4 years ago

thank you for your suggestion but I have already tried that using for loop and while loop, the motor stops only after certain time rather than after N iterations. Can you please suggest with the code.

0
steveastrouk
steveastrouk

Answer 4 years ago

Then you need to improve your code. Show us what you have tried.