Pan and Tilt webcam mount – Arduino powered


A long time ago I built a little pan and tilt mount from some scavenged electronics (a stepper motor from a printer and a worm drive from a cd player) I connected it via a parallel port and used darlington arrays and direct pin out of the parallel port to control the whole thing from some script language, I forget which. It was a little unreliable and fairly cumbersome but it got the job done. I used it to watch what my cats were up to whilst I was out at work. At some point I got tired of the very bulky and rubbish looking thing sat in the living room and it got decommissioned.

Spin on a few years and I have a few arduino’s laying around, and a higher budget to buy parts. So I decided to revive the pan and tilt camera mount using servos and an arduino to control things. I’m still going to need a pc application to talk to the arduino, but it handles the servo logic and the PWM stuff.

When I looked on line a lot of what shows up is very basic servos stuck to each other and a webcam stuck on the end. This works but looks a little rough and possibly not that robust. So I decided to go with something a little more ‘constructed’. It is probably overkill for just a camera but it could potentially serve for other purposes in the future.

wp-1399203733823

Mechanical:

The design of the pan is around the use of a lazy susan bearing, this is where all the weight is supported, so in theory I could have quite a heavy load on top and the servo just needs to overcome rotational friction, it doesn’t also need to support the weight.  To make this work, I have a base board that attaches to the bottom of the lazy susan bearing, and centred within that I screwed one of the standard servo attachments, then just dropped the servo onto it. This then let me figure out the location to cut a hole to fit the servo body into for the board connected to the top of the bearing.
After a certain amount of drilling and chiselling I cut out a recess that snugly fit around the servo body, so that there is no weight pressing down on the servo, but in order for it to twist, it is twisting the whole top board.

wp-1399203750009

With that base in place I could mount whatever I like on top, in this case I wanted a tilt mechanism. The basic idea is that you have a platform that can tilt back and forth, onto which I could mount a camera (or whatever else I wanted). The platform has a centre of axis around which it is going to rotate, on one side there will be the servo, on the other a free spinning axel of some kind to just support the weight. I used a bearing mounted into the side of the platform, and a wooden peg that fit on the inside of the bearing which was just stuck into a support strut. This allowed the platform to spin on the bearing supported by the peg. On the other side then I just needed a block to mount the servo into which brought its centre in line with my desired centre of rotation.

wp-1399203759886

And that’s about it from a mechanical perspective. It is quite chunky by comparison to an off the shelf pan/tilt camera. I’m not sure what future purposes I might come up with, but it should be able to take a considerable amount of weight and still be able to pan at least.

Electronics:

As I mentioned the electronics comes in the form of an arduino. In theory this is very simple, but I had a couple of false starts. The important thing to realise is that whilst you can very easily get the initial sense of success by just wiring up the servo to the arduino for power and signals, this WILL NOT WORK. I know, you’ve done it, and it seems like it is working, but this is an illusion. It is unreliable to the point of being worthless. Servos draw a lot of power, I’ve seen indication that they can draw up to 1A each. depending on what they’re doing. The arduino is not able to provide that kind of power. The path I went down I wired everything up away from the mechanical setup, and everything worked! because the servos had absolutely no LOAD to move. so they drew relatively little power. I was also driving them only one at a time. But the second I had things inside the mechanical build, you’d get one movement, and the arduino would crash. If you were lucky on a small movement, maybe it wouldn’t, but basically everytime you try to do anything it crashes. So what is required is an external power supply to provide the power needed.

wp-1399203774500

wp-1399203781681

My second false start was in assuming I could plug that power supply into the arduino board via that convenient plug socket designed for the purpose. I bought myself a 9V 2.2A supplied and plugged it in. But this yielded the same crashing results. It turns out that the arduino power regulator simply isn’t rated to allow that much power draw through it even if the supply can provide it. So I needed to wire the power supply independently straight to the servos. And just bridge the GND line into the arduino. That bit is important as without the same reference ground level the servos won’t recognise the PWM signals coming from the arduino.

Once I had done this though, I was in business. I made myself a nice little ‘breakout’ board that just plugs down into the arduino to grab the signal pins I was using and the ground line, with some extra pins just to make the board somewhat stable when connected. This let me run the servo lines fairly neatly, and screw the whole assembly to the back of the platform. Whilst this is arguably still very scrappy compared to a commercial unit, it is leaps and bounds more slick than my previous attempt.

Control

Right now, control is via the arduino software serial console, where I sent it a pair of numbers to represent the position for the servos. The program running on the arduino scales whatever I give it to sit inside the range of valid movements for the servo. And actually in the tilt case it is more restrictive as mechanically it would crash into things if it moved the full range the servo is capable of.

I do want to play with making some kind of web interface to it that will both show the video feed from the webcam, but also provide controls to pan/tilt.
Not sure exactly how I’ll approach that yet, maybe see if there is some off-the-shelf software option that I can hook up. I seem to recall using something on linux when I made my first attempt. But I might use it as an opportunity to learn something new, maybe play with some ruby? I could just make a desktop app, but I think it will be more useful as a webapp.

, ,