6 - Connecting the motor

 

Now that we have the LEDs flashing correctly we can connect the motor instead.

 

For each coil of the motor the centre tap is unused (as we are simulating a bipolar motor) and the ‘a’ and ‘b’ terminals are connected to the outputs of the L293D driver (instead of the LEDs).

We can now change our program so that instead of waiting 1 second between pulses we can send faster pulses. My motor has a frequency of 300Hz – so one pulse every 3.3ms. However: my timer only lets me wait for a given number of milliseconds so I shall round that up to waiting for 4ms.

Now turn on – and your motor should rotate. If it doesn’t then maybe you’ve got the frequency wrong. For example: if I try to ‘over-clock’ my motor by changing my delays to 3ms then it just hums and doesn’t rotate.

Increasing your delay time will obviously make your motor turn slower.

 

 

But what about reverse? Well if you’ve followed my wiring convention then you can rotate one of the motor connectors through 180 degrees to swap the a and b connections. That should work. Interestingly: I started by swapping the leads round for both coils – and it made no difference – so only reverse one of them. You could, of course, add additional circuitry to do this for you, but this would need an additional controller pin to select forward or reverse and, in my view, this is better done in software:-

Set your pins as outputs

While(1){

Pin1a = low, Pin1b = high, Pin2a = low, Pin2b=low

Wait 1 second

Pin1a = low, Pin1b = low, Pin2a = high, Pin2b=low

Wait 1 second

Pin1a = high, Pin1b = low, Pin2a = low, Pin2b=low

Wait 1 second

Pin1a = low, Pin1b = low, Pin2a = low, Pin2b=high

Wait 1 second

}