Twitching Servos and an Arduino Brain

As this project had a few parallel activities some parts could be attacked in the few hours available mid-week after work. The Luggage's brain was one such of these activities.

As mentioned before, I'd decided that The Luggage would be controlled by an Arduino microcontroller. The exact flavour that I picked up was the Arduino Micro. It's very compact and would support control of motors / servos through the analogue (PWM) outputs.

While buying the Arduino controller from the store, I noticed that they also had some continuous rotation servos available. Given that these are essentially programmable motors and being sold by the Arduino store I figured that they'd work nicely with the Arduino Micro.

Before I pushed the "buy" button, I did do a few quick back-of-the-envelope1 calculations to ensure the servos would have enough grunt to move The Luggage about. More about that next time though.

The logical design in The Luggage's brain wasn't difficult. Given that I only had time decided to simply make it move randomly, all I needed was a simple loop() that generated some random numbers then moved the servos accordingly. This didn't take too long to come up with, and had the advantage that if the final robot didn't have quite the right sort of behavior, changing it would be the case of poking a variable or two.

Of course, it's no good to just have the brain sending signals out to some control pins with nothing attached to actually do anything. So The Luggage had to be wired up.

Wiring diagram for The Luggage

Wiring diagram for The Luggage

There, doesn't that look simple? All that you need is to attach power through a switch to the Arduino and servos, attach the PWM outputs to the servos and gather the ground connections.

This is the unholy implementation of the above wiring diagram. I am not proud of this.

This is the unholy implementation of the above wiring diagram. I am not proud of this.

Whilst it killed me2 to generate a rats-nest of wires as shown, they did at least work, so the engineer in me let it go.

<aside>The double power connection came from some earlier work with Hexy that demonstrated that whilst you could run the servos and logic from the same 5V supply, you really shouldn't. High current spikes from the motor coils can cause momentary dips in voltage. Not a problem for the servos (which are current devices), but digital logic circuits will often reset (as they're based on voltage levels), or behave unexpectedly.

In the bad way.</aside>

So where does that all get us to? We have a brain, we can connect electricity to it, and we can connect servos to it. The Luggage lives!

Two servos being independently controlled in an early test sketch. Note that the reactive torque is enough to cause the second to jump about when abruptly reversing direction.

Two servos being independently controlled in an early test sketch. Note that the reactive torque is enough to cause the second to jump about when abruptly reversing direction.


1literally.

2figuratively.