Hello everyone,
I am working on a small project and facing some problems getting the Arduino do what I want !
It is basically controlling a DC motor through a motor drive and a current sensor.
I have it all wired up and running and giving me the inputs I want, but not the way I want it to do so.
My goal is to make the motor run at different speeds in different directions at different time intervals, while at the same time the current sensor reads the current and reacts accordingly ...
Example: (clockwise at full speed for 2 seconds, stop for 1 second, counterclockwise for 3 seconds at half speed, stops for 5 seconds, and so on....), the sensor reads the current and using the Interrupt function, if it goes above or below a threshold, it will stop the motor or make it do something else of my choice.
I have tried different codes with no success !
In a normal code with the "delay" function, the motor runs nicely and does what it is suppose to do, but the sensor has to wait for the full motor loop cycle to finish, then it sends the reading, but I want it to send the reading all the time while the motor does its thing !
In multitasking code with "mills" the sensor sends the reading continuously, but the motor is rotating continuously as well and not in the way I asked it to do !!
After reading, I understand the reason for that in both cases, and was wondering if there is a way to make the motor run as commanded and the sensor send a continuous readings and reacts as commanded !!
And if it is not possible to achieve this with one code in one Arduino, would it be possible to use the "master slave" as an alternative?! ... one controls the motor while the other one reads from the sensor and sends commands to the first one to react.