Monday, April 3, 2017

Arduino Pan-Tilt controller

I'm working on a project to make an RC controller from Arduino parts and picked up a previously unfinished project where I was wanting to use servo's to control a Raspberry Pi camera with a pan-tilt mechanism hookup up to some micro-servos.

Parts :

  • Arduino Board - I used the UNO in this example.
  • Joystick or 2 potentiometers.
  • Pan-Tilt head
  • 2 Sub-micro servos.
  • Connecting wires


  1. Connect the center of each pot to the inputs (A0 and A1). 
  2. Connect the other sizes to of the pot to V+ and Gnd.
  3. Connect the orange signal wire of the servos to D9 and D10. 
  4. Connect the red servo wire to V+. It is best to connect to a separate power supply if you are using larger servos and/or expect a load on the servos. 
  5. Connect the brown servo wires to ground. These should be connected to the same ground as the Arduino controller.


Required Software Libraries:

  • Servo.h

Source Code:

  Pan-Tilt controller
  By Aaron Woehler 3 Apr 2017

  Transform 2 analog inputs into 2 pwm output to control pan-tilt servos.

D9 - Servo0
D10 - Servo1

A0 - Center pin of potentiometer 0
A1 - Center pin of potentiometer 0


int sensorPin0 = A0;    // select the input pin for the potentiometer
int sensorPin1 = A1;    // select the input pin for the potentiometer

int sensorValue = 0;  // variable to store the value coming from the sensor
Servo servo0;  // create servo object to control a servo
Servo servo1;  // create servo object to control a servo

int mapped;
void setup() {
  myservo0.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.attach(10);  // attaches the servo on pin 10 to the servo object

void loop() {
    // read the value from the sensor:
  sensorValue = analogRead(sensorPin0);
    //Adjust the read value which is in the range from 0 to 1024 to degrees 0 through 180.
  mapped = map( sensorValue, 0, 1024, 1, 180 );
    // tell servo to go to position in variable 'pos'

  sensorValue = analogRead(sensorPin1);
  mapped = map( sensorValue, 0, 1024, 1, 180 );
  //stop the program for 50 milliseconds:

Saturday, December 3, 2011

Preventing HTML5 autobuffer with Javascript

I was looking at creating an HTML5 video website the other day but was frustrated by the fact the browsers seem to automatically download the video when the page was opened. This seemed like a waste of bandwidth especially if you have to pay for it and your site goes viral. My solution so far was to created the following script to help prevent excess bandwidth charges.

Copy the code below into a script tag in the head of your HTML document and copy the second section into a script tag at the end of the BODY. Make sure to set the style width and height of your div tags with videobox class.

function setVideo() {
        obj = this.firstElementChild;
        //Remove the extension from the filename.
        vbase = obj.src.substr(0, obj.src.lastIndexOf('.') );
        var vbox=document.getElementById(;'visible';
        var vid = document.createElement("video");
        //Transfer the size information from the image to the video. =; =;

        //Remove the onlcick action and image.
        vbox.onclick = null;

        var vidsource;
        //Duplicate the following 4 lines for each available video source/format.
        vidsource = document.createElement("source");
        vidsource.type="video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"";

        vidsource = document.createElement("source");
        vidsource.type='video/ogg; codecs="theora, vorbis"';

        //Add the video to the document.
function html5Videos() {
        //Find all div tags with a class name of videobox.
        var x=document.getElementsByTagName("div");
        for( i=0; i < x.length; i++ ) {
                if( x[i].className == 'videobox' ) {
                        x[i].onclick = setVideo;


This is just a rough draft that I am sharing in hopes that others will find it useful and make improvements. I've tested in on the Android 2.3 browser, iPod Touch OS 4.3.3, Google Chrome 15.0.874.121 for Linux, Firefox 3.6.24.

Sunday, April 24, 2011

Mouse like Numberpad

The other day my number pad stopped working. Then I notice it was acting like a mouse and I remembered that I'd used this once before a long time ago. It can be handy if you are setting up a computer or trouble shooting things and don't have a mouse. Usually I prefer the number pad to act like a number pad and not a mouse. Here is how to toggle it back and forth press ctl-alt-numlock.

Monday, October 11, 2010

Link Shrink Adfly Service?

Has anyone else used the URL shrinking service before? Looks like an interesting service though it does cause you an extra click for users to get to you link. I found it as a referral in my Google Analytics data.

Thursday, October 7, 2010

Panoramic Eklutna Lake Mug

Just went on a bike ride along the Eklutna Lake near Chugiak and captured this wonderful panoramic view looking down the lake.