Following on from Part 1, we’ve done our design and now it’s to put our prototype to the test, this will post won’t be as long as the design because all we need to do is test.
This is how our circuit looks to power 1 motor in 1 direction only.
Compare this to the design we showed in Part 1 and it looks the same.
And so we multiply this circuit by 4, now here’s what the 2 motors in both directions look like, quite a lot of components to it!
The only thing you do in your Arduino is execute this simple code for each direction of each motor:
const int motor1Forward = 2; void setup() { // Initialize the digital pins as an output pinMode(motor1Forward, OUTPUT); } void loop() { digitalWrite(motor1Forward, HIGH); }
What I didn’t mention in the design is, what happens if our motor voltage drop below 6 volts, say to 5 volts? Well what will happen is the PNP transistor will reduce it to 4.3V as usual but then it connects to the NPN next to the PNP right and the voltage from the Arduino gets reduced to 4.3v there too. So we have two sources of 4.3V and what can happen is instead of the current being draw from the motor’s power supply it’s actually taken from our Arduino which will firstly make the motor spin slower and may cause damage to the Arduino and/or transistors.
The way which we can prevent damage to our circuit is quite simple, we add a resistor say 10K, connect this from the PNP’s base to the Arduino’s Analog input and and now we are able to read the voltage up to 5 volts. Now all we need to do is look out for a voltage of 4.3 – 4.5 volts (to be safe) as we explained above and then disable the output pin on the Arduino if this voltage is detected. The only problem with our method is that we’ll need to enable the output for a few milliseconds and that’s when we are able detect the voltage.
Another thing to note is that the Arduino only doesn’t output exactly 5V, it’s more like 4.8V. So 4.8V – 0.7V = 4.1V, so then 4.1 – 4.2 voltages is the minimum voltage that we need to look out for.
The only problem is that we would need to put in 1 main resistor and then 1 diode for each direction of each motor, so for us it’s not really worth it but something for you to keep in mind when implementing motor controllers to your projects. An easy way around this would to put the 10K resistor connected to a diode (to simulate 0.7V drop) and then connect it directly to the battery. (I haven’t included this damage prevention in my final circuit but though I’d point this out.)
I’ve tested the motor controller circuit and it all works great, so our implementation was successful. Part 3 will be converting our prototype to a PCB.