Introduction: Remote Control Mini-VideoTelescope With Pan/Tilt/Zoom

About: My name is Kevin Palivec. I'm a network engineer who lives in Texas. I love building useful stuff from scavenged parts.

Sitting out at night looking through a telescope is relaxing and fun! But sometimes you just want to stay inside where it's cool or warm and where there's not so many bugs biting you.

Here's a project that will let you sit at your computer and watch the skies from the comfort of your easy chair!

We're going to build a remote controllable sky-camera. with a zoom lens you'll be able to watch the skies 24/7! This camera will have the ability to be panned and tilted, zoomed and focused and have it's extremely low light settings all be controlled via a browser.

And best of all! All the parts were pretty cheap!

This is really going to be several Instructables rolled into one! I'm breaking it up into "Parts" any single part could be used in several ways not limited to just a sky camera. There's a lot to digest and read and many parts to this build but It's my hope that the systems and ideas presented in this project will be useful to readers in many different ways!

In Step one you'll learn how to Use an H-bridge and an Arduino to control DC motors. Useful not only for thllZoom Lens but also useful for robots, cars, winches.... you'll also learn how to control arduino pins with a web interface.

In Step Two you'll see how to use relays and an Arduino to turn a manual antenna rotor into an automated rotor.

In Step three you'll learn how to use transistors to turn manual press buttons into automated and web controlled press buttons and how to use a transistor as a switch.

So lets get at it!!


Part 1 (The basic skycam) will be the Web based Zoom Lens Control.

This is to allow the motorized zoom lens functions to be controlled remotely via web page . (This is probably the part that is the most fundamental to the project.)


Part 2 will be the Web Browser based Pan and Tilt control of a cheap antenna rotor and a stepper motor.

This is to allow the camera to be moved and pointed via Web Browser based remote control


Part 3 will be the Camera OSD (On Screen Display) Menu Web Browser Control.

This is to allow the camera to be put in a permanent outdoor housing and still allow the user to control the onscreen camera settings via a web page remotely. (This part isn't as important if you're planning on "NOT" having the camera outside on a permanent basis or if the camera is going to be within easy reach. ((Mine's up at the top of a 30 foot pole))

So lets gets started........

Step 1: First We Need to Get Our Parts.

For this project we're going to need the following parts....

For all Part 1 of this Project you'll need.....

____________Camera, Zoom Control and Power________________

1. A low light camera. About $60. this is the one I'm using.

0.0001LUX 1200TVLines 1/2 MCCD Prime 300w Camera BNC AV Night Vision Monitor Riflescope 1/2 F1.2 16mm 25mm Lens DIY Infrared. you can order one here....
(LINK)

(This camera has good color low light sensitivity and also the ability to go into a black and white only mode.

It has a movable IR-Cut filter.(this helps with filtering out Infra red from the color video. Infra red in color gives everything a pinkish tint and makes plants look white. almost all color video cameras use an infrared cutting filter.)

2. Well need a motorized zoom lens. This is a bit trickier to get. We'll have to search Ebay for a Motorized zoom lens C-mount or CS-mount. (the C mount is a threaded screw-in type lens used on most CCTV or Closed Circuit TV cameras. "That's what we ordered" The prices for these will be all over the place. Look for a cheap used one. All we care about is that it's motorized. Also look at the zoom factor! It'll be listed like this...." 18-108mm f/1.8 C-Mount motorized Zoom Lens" The smaller number is the "wide angle view(zoomed out) and Most Importantly, The larger number is the Close up view (Zoomed in). the larger this higher number, The more magnification you get on the zoomed in view"

the basic rule is... Get as much zoom as you can for the least about of money!

I found one for $25! using a "Make offer"

3. A Weatherproof housing to mount the camera and it's control circuitry and micro controller in.

(LINK- Weatherproof Camera Housing)

Again ebay is a good source for one of these. Get one that is at least 11" long. they'll cost around $25 unless you can find one locally used for free. Scavenging free parts is always best!! .

4. An Arduino Mega. This will be the Brains that will control everything we shove into our camera housing, We use a mega because it's got enough I/O pins to do everything we need and they're pretty sturdy in variable temps. (it's going to be outside in the camera housing and will be subjected to hot and cold temps.) I have one that's been living out in a camera I build 3 years ago and it's still chugging along happily!

(LINK - Arduino mega)

5. An Ethernet shield.

(LINK - Ethernet shield)

6.2 H-Bridge modules. (ebay again) These will control the motors on our zoom lens' Zoom, Focus and Iris.

What's an H-bridge? I hear you ask? Well... An H-bridge is a series of transistors arranged in a way that with 2 inputs (one High and one Low.. High = Voltage and Low = no Voltage) you can run a DC motor ether forward or backwards. These Modules usually can control 2 separate motors so we need 2 for our 3 motors. Zoom, Iris and Focus. Commonly referred to on motorized lenses as "FIZ"

(LINK - 2 H-Bridge Modules)

7. A 12 V 1A DC power supply

___________________________________

For Part 2 of this project you'll need....

_____________Pan and Tilt Control_________________

8. An antenna rotor. You might find one cheap on ebay or at a garage sale. New they go from $50-$120 or so. Used they could be cheap to free! Here are some links..

http://www.ebay.com/itm/Channel-Master-9521A-9521-Antenna-Rotor-Rotator-Motor-Only-for-TV-Ham-CB-WIFI-/381623814490?hash=item58da8d495a:g:788AAOSwKfVXK15N

https://www.google.com/?gws_rd=ssl#q=antenna+rotator&tbm=shop

9. A relay shield with 4 5V relays. Make sure it uses 5V controlled relays. The Arduino puts out 5V on it's pins. This will control our Tilt angle.

(LINK 5v relay shield

10. 1 stepper motor and a control shield.

LINK - Coupler

13. 1 200mm threaded rod and nut.

(LINK-threaded rod and nut)

_____________________________________

For Part 3 Of this project you'll need....

_______Camera On Screen Menu Control_________

14. 5 2n2222 Transistors

(LINK - 2n2222 NPN Transistors

And some soldering skills plus some Nerve to open up the camera and do some surgery on it!

Step 2: Part 1. the Camera and Lens.

For this part of our build we're mostly going to "Focus" on the Lens.

We'll need to open the lens and get at the motors that control the Zoom, Iris and Focus. Each is driven with a small 12V dc motor and gears to rotate. Most lenses just have a simple plug or wires coming from them to allow DC voltage to drive the motors. These will come in one of two flavors.... Common Ground or separate grounds.

In a Common Ground setupall the (-) negative sides of the motors are connected together and only the (+) positive sides are separate. (SEE The Diagram Marked "NO" above.) We don't want that! We want all the motor power lines to come out to our H-Bridge modules because we need to be able to reverse the polarity on each motor independently in order to run them forwards or backwards.(See the Diagram marked YES!)

Open up your lens and look for the motors.....

Step 3: Find the Motors and Their Power Leads.

Inside the lens you'll find at least 3 motors. One for Zoom, iris and Focus.

the Focus motor will probably be easiest to see. if you rotate the lens at the front you'll see which motor gear moves. Note and label the two power leads coming from that motor.

The iris and zoom motors will be a little trickier. I've added a video to show you what you're looking for and how to locate each motor.

After we identify each motor and it's power leads we'll want to unhook them from any internal control boards and also separate the (-) wires if they're run to a common ground as mentioned before.

We need to run them out to our h-bridge modules so we can control them directly.

Step 4: Connect Lens Motors to H-Bridges and Arduino Mega

What the heck is an H-Bridge?!

Ok.. first a description.

An H-Bridge, So named because it's diagram looks kind of like an "H". Is a circuit that by opening or closing 2 of 4 switches will allow you to run a dc motor forwards or backwards. In fact with 4 switches, relays or transistors you could build one yourself. (I've drawn some diagrams showing the current flow and how it causes the motor to run) However, it's so much easier to just get a cheap one already made off ebay. See the images above for a simple h-bridge diagram. We next want to connect the Positive and Negative wires from each motor to an H-bridge output so we can control our motors from the Arduino. Each module can control 2 separate motors so we need 2 H-bridge modules for our 3 motors. See my handy dandy awfully drawn diagram for where to hookup the motors!

See the photo of all parts connected to the lens.

Next we'll install the Ethernet card and install the code into the arduino.

Step 5: Installing the Ethernet Adapter for Web Access.

This part is relatively simple. We're just going to line up the pins on the Ethernet card and press it onto the Arduino mega board so we'll have network connectivity to the camera, lens and pant/tilt system as we add them.

If you look at the attached photos in order you'll get a good view of how to install the Ethernet card. It's pretty straight forward and if you're building this project you probably have a good idea how the card attaches to the arduino. It's THAT easy!! =)

Step 6: Installing the Arduino Code for the Lens.

At this step we'll install our code for the Arduino Lens control.

This will allow us to remotely change the zoom, iris and focus via a web browser.

The code works by initializing the Ethernet card and setting its ip address on the network and defining what pins will control which motors on the lens.

It then builds a simple web button page with Pre-set motor on and off duration for forward and backwards motion on each of the lens' drive motors..

You'll find the code for this part of the project below.

I've commented it so you'll be able to see what each part of the software does. Feel Free to modify it to suite your needs! the HTML page it builds is simple by design to save memory in the arduino.

Code:

/*---H-bridge Pin assignments for this code.....

First H-Bridge ----- Arduino 
____________
Iris (+) IN1     ---- 22 
Iris (-) 1N2     ---- 23
Zoom (+) IN3     ---- 24
Zoom (-) IN4     ---- 25

Second H-Bridge ---- Arduino
____________
Focus (+) IN3    ---- 26
Focus (-) IN4    ---- 27

--*/

#include <SPI.h> //install libraries for the ethernet 
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>


byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD3, 0x7B}; // <-Set your ethernet card's MAC address. this should be ok.
byte ip[] = { 10,16,176,223 };                      //<--Replace with your ip address
EthernetServer server(80);                          //<--Create a Web Server. WWW runs on port 80 by default.  

String camString;             //Create a string to use for buttons
String message = "";          //same here

// Setup for tilt stepper motor.....
//declare variables for the motor pins
 int motorPin1 = 30;    
 int motorPin2 = 31;      
 int motorPin3 = 32;    
 int motorPin4 = 33;   
                        
 int motorSpeed = 1000;  //variable to set stepper speed
 int count = 0;          // count of steps made
 int countsperrev = 512/2; // number of steps per full revolution
 int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
 






void setup(){

  Serial.begin(9600);
  
   for (int i=2; i<53; i++){  //quickly make all pins outputs
  pinMode(i, OUTPUT);
  digitalWrite (i,LOW);       // and set them low
  }
    Ethernet.begin( mac,ip); //<-- start the ethernet card
  server.begin();            //<-- start the web server

//declare the tilt stepper motor pins as outputs
   pinMode(motorPin1, OUTPUT);
   pinMode(motorPin2, OUTPUT);
   pinMode(motorPin3, OUTPUT);
   pinMode(motorPin4, OUTPUT);

 }

void loop(){

  EthernetClient client = server.available();    //<-- start listening for someone to talk to us
  if (client) {
Serial.println("connection");
    while (client.connected()) {
      
      if (client.available()) {
        char c = client.read();

 
        if (camString.length() < 100) {


          camString += c; 
        } 
        if (c == '\n') {                              // <-someone knocked. lets show them a webpage full of buttons!
          client.println("HTTP/1.1 200 OK"); 
          client.println("Content-Type: text/html");
          //client.printlnln();
          client.println(F("<HTML>"));
          client.println(F("<HEAD>"));
          client.println(F("<TITLE>Arduino CamControl</TITLE>"));
          client.println(F("</HEAD>"));
          client.println(F("<BODY><html>"));
          client.println(F("Lens Control<br><table>"));
          client.println(F("<tr><td><input type=button value=zoomin onmousedown=location.href='/?zoomin;'></td>"));
          client.println(F("<td><input type=button value=zoominall onmousedown=location.href='/?zoominall;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=irisclose onmousedown=location.href='/?irisclose;'></td><td><input type=button value=irisopen onmousedown=location.href='/?irisopen;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=zoomout onmousedown=location.href='/?zoomout;'></td>"));
          client.println(F("<td><input type=button value=zoomoutall onmousedown=location.href='/?zoomoutall;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=focusin onmousedown=location.href='/?focusin;'></td><td><input type=button value=focusout onmousedown=location.href='/?focusout;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=focusin20 onmousedown=location.href='/?focusin20;'></td><td><input type=button value=focusout20 onmousedown=location.href='/?focusout20;'></td></tr>"));
          client.println(F("</table>Pan/Tilt control<br>"));
          client.println(F("<table><tr><td><input type=button value=TiltUp onmousedown=location.href='/?tiltup;'></td>"));
          client.println(F("<td><input type=button value=TiltDown onmousedown=location.href='/?tiltdown;'></td></tr></table>"));
          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);     
          client.stop();
          
          // The block below watches for button presses and applies the correct actions.......
          if(camString.substring(6,12) == "zoomin")  //<-- Zoom in button pressed. 
          {
                          zoomin();                   //<-- jump to routine that sends appropriate commands to motors
          }
           if(camString.substring(6,13) == "zoomout") //<-- Same as above but for Zoom Out
          {
                          zoomout();
          }
               
               if(camString.substring(6,15) == "zoominall") //<--zooms in all the way
          {
                          zoominall();
          }
           if(camString.substring(6,16) == "zoomoutall")   //<--zooms out all the way
          {
                          zoomoutall();
          }
                             
           if(camString.substring(6,14) == "irisopen")
          {
                          irisopen();
          }
           if(camString.substring(6,15) == "irisclose") 
          {
                          irisclose();
          }
          if(camString.substring(6,13) == "focusin") 
          {
                          focusin();
          }
           if(camString.substring(6,14) == "focusout")
          {
                          focusout();
          }
          if(camString.substring(6,15) == "focusin20")
          {
                          focusin20();
          }
           if(camString.substring(6,16) == "focusout20") 
          {
                          focusout20();
          }

          if(camString.substring(6,12) == "tiltup") 
          {
                          tiltup();
          }

            if(camString.substring(6,14) == "tiltdown") 
          {
      
                          tiltdown();
          }
          camString="";  //<-- this clears the command string so it doesnt keep doing the same command over and over!

        }
      }
    }
  }
} 
// This block holds all the routines that control what the pins do when buttons are pressed.
 
void zoomin()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(100);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomoutall()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(3000);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}


void zoominall()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(3000);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomout()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(100);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}



  void irisopen()
{
  digitalWrite(22, HIGH);
  digitalWrite(23, LOW);
 

  delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}

void irisclose()
{
 digitalWrite(22, LOW);
  digitalWrite(23, HIGH);  
 
 delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}
   void focusin()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusin20()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}
void focusout()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusout20()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

 void tiltup()
 {
  for(int w=1;w<countsperrev;w++){
   for(int i = 0; i < 8; i++)
   {
     setOutput(i);
     delayMicroseconds(motorSpeed);
   }
  }
  for (int i=2; i<53; i++){  //quickly make all pins outputs
  pinMode(i, OUTPUT);
  digitalWrite (i,LOW);       // and set them low
  }
  }

 void tiltdown()
 {
  for(int w=1;w<countsperrev;w++){
   for(int i = 7; i >= 0; i--)
   {
     setOutput(i);
     delayMicroseconds(motorSpeed);
   }
 }
 for (int i=2; i<53; i++){  //quickly make all pins outputs
  pinMode(i, OUTPUT);
  digitalWrite (i,LOW);       // and set them low
  }
 }
 
void setOutput(int out)
 {
   digitalWrite(motorPin1, bitRead(lookup[out], 0));
   digitalWrite(motorPin2, bitRead(lookup[out], 1));
   digitalWrite(motorPin3, bitRead(lookup[out], 2));
   digitalWrite(motorPin4, bitRead(lookup[out], 3));
 }

Step 7: Place It All in Your Weatherproof Camera Housing or Just Stick It on a Tripod.

With this step there are many options. The arduino and circuitry are small enough to fit inside a CCTV weatherproof camera housing or could just be mounted on a tripod. I have mine in a housing and out on a 30' pole

If you opt to place it on a tripod for "session" viewing. Remember to bring it in when you're finished!!

Step 8: Sit Back and Watch the Camera Output.

There are many ways to view the output from your camera and lens.

1. plain old video monitor. just wire the camera up to a video monitor and watch it live. You could hook it to a DVD recorder or an old VCR

2. A video grabber on your PC. This is what I do. You can save it to disk.

Here's a video of it in action. It's a daytime video but it can be used at night and zoomed in enough (depending on your zoom lens factor.) to see craters on the moon or Jupiter and it's moons!

Just a note: The timestamp running on the bottom of the video is a separate box I added to the video going into my PC. The Camera Itself doesn't produce it.

I'm also adding some images and videos of things you might capture with your cameraLike Red Sprites and Meteors!.

Soon to be added is a pan/tilt control. We'll be adding the hardware to a weatherproof camera housing and adding the ability to control it from our web page.

Watch for it to be added to this instructable!

If you like this instructable and find it useful, show your love and hit the VOTE button up top! =)

Step 9: Part 2. Remote Control Pan and Tilt of a Simple Antenna Rotor

In this Section we're going to hack a simple antenna rotor and Camera housing to allow us to Remotly pan and tilt

them from our web browser page.

for this we'll need an old (or new) Antenna rotor, a 5v relay shield, a threaded rod and nut, a coupler and a stepper motor and driver.

A word of CAUTION: This part of the project involves the Rotor control box using 120V AC so we need to make sure nothing is connected to power.

that being said. Lets proceed!

Step 10: Here's What We'll Be Doing.

Here's how this will work.

We're going to be taking control away from the dial controller inside the rotor control box and using our relays to do the work that the switches inside the box did. (Time for another diagram- See above!)

The Rotor works by first transforming 120V AC down to 24V AC. The 24V AC is run to a switch with 3 poles..

One line of the AC runs to the middle of the switch and the other side is split to either side of the middle pole.

This side of the switch puts power on either the Clockwise or anticlockwise side of the AC motor.

There are actually 2 motors in this system. One that moves the motor outside on the antenna and another that moves in unison inside the control housing to turn the dial at the same rate as the motor outside. This is to indicate where approximately the outside motor is turning to and to move the 3 pole switch to the position of the dial which has a plastic finger on it that disconnects the switch when it's reached. Thus stopping the motor rotation at the point selected.

Since we're going take over the role of the dial and switches with our Arduino and Relays. All we really want is the 24V Transformer's 24V output. Above there's a quick little badly drawn diagram video to show what's going on.

Step 11: Getting at the Antenna Rotors "transformer"

((((((((( REMINDER!!! CAUTION!! )))))))))

((((((((( DO this section at your own RISK!!!))))))))

(((((( 120V monsters can lurk inside))))))))

(((((( they bite if you're not CAREFUL!)))))))))

This part gets Kind of complex. Not to bad but more involved than I could put on one step and have it still be meaningful and easy to follow. So I'm going to break it down....... way on down!

First we need to make sure the rotor controller is unplugged from the wall and motor! <---IMPORTANT read it again!!

Now we'll turn the control box over and remove the screw in the middle. The rest of the case is held on with clips along the edge. They can be unlatched with a flat head screwdriver in the provided slots along the edge. Free each clip and lift the top half away from the bottom. Everything inside is secured to the bottom half of the case.

Step 12: Locate the Rotation Switches and Transformer.

Now that we've opened up the control housing and have a good view of the workings. Lets take a moment to identify the parts.

The first thing you'll notice is the dial that cuases the motor to turn. Next to that is a motor inside the control box. this motors turns at the same rate as the motor out at the outside rotor and gives an indication of where the rotor is pointing. it also moves a ring with a knob on it that presses against some metal fingers under it to stop the rotation when the desired location is reached. There is also a second switch that is pressed together that closes the Mains AC power from the wall to the transformer. This keeps the transformer from always being "ON" when you're not moving the rotor. When the dial is turned the rocker on the edge of the switch ring is pressed over and closes the main power switch and also rocks over and presses the switch which engages the appropriate direction switch and sends 24V out to the rotor motor causing it to spin in the desired direction. As the wheel turns under the dial it slides along until hit hits a notch in the outer "direction ring". when this notch lines up with the rocker, the springy metel of the switches cause it to pop back into the middle and this open the switches back up. shutting off power to the transformer and motors. We're going to disable this mechanical system and automate it with our Relay Shield.

Step 13: Taking Control of the Switches

In this tutorial we're going to preserve the Control box so if needed we can return it to normal functioning easily.

You could just pull the transformer and chuck the rest if you never plan to use the rest again. Or you could add some "cut over" switches and make it into a Dual function control but for out purposes we're just going to disable the spring switches and tap into the power leads and redirect them to our relays.

Take a look at the Switches. I'm sure you know what they are but just in case. they're the brass lengths of metal.

There are two.

The one with only 2 brass fingers is the 120V Transformer mains power and the one with 3 fingers is the direction control switch.

The first thing we need to do is lift out the little clear plastic rocker. This will disable the internal spring switches.

This has a side effect. It allows the mains power spring to touch one of the motor control springs. That would be bad! That'd feed 120V right to the motor so we have to keep that from happening. therefor we need to isolate those two springs somehow. I used a length of plastic tubing. See photo

Next we need to isolate the middle finger of the 3 spring switch and one side of the 2 spring switch.

I tried several ways of isolating the contacts until I settled on a length of Cat5 Ethernet cable outside insulation cut to the length of the spring. (see image 4)

Step 14: Tapping the Switches and Feeding Wires Out of the Control Box

Having located and disabled the internal switches in the rotor control box, We now need to "tap" into those lines so we can feed them out to our arduino controlled relays.

Basicly what we're doing is connecting to those switches in "parallel" in other words we're adding a switch so that if either switch is closed the circuit will function. Thus maintaining the ability to return the control box to it's original function if needed.

First we need to solder a 2 foot length of 2 conductor wire to the two spring mains switch on the rotor cam.(see first photo) I used wire cut from an old low amperage extension cord. We're not pulling a lot of amps so a thinner and more flexible cord is preferable.

And the same with a 3 conductor wire to the rotor control switch. (see second photo) for this I used a length of Networking Cable. Cat 5. we're only dealing with 24V on this one.

We're going to run the wires down through the middle of the cam so they can rotate with it. Again to maintain functionality.

These wires will be run down and out of the control box through one of the clip holes in the bottom of the box.

Step 15: Connecting It All to the Relays.

Once we have the wires fed outside of the control box. We need to connect them to the relay shield so we can switch them on and off remotely.

The mains (transformer power) switch is easy. It's a single relay connected to the middle relay connector and to the "normally open" connector.

Next..

The direction control wires (3 conductor wire) connects to (2) relays. One for Clockwise and one for Counter Clockwise rotation.

The wire that connects to the middle of the 3 spring switch will connect to both relay's center connector.

The remaining 2 wires will each connect to the "normally open" side of each relay. one to one relay and one to the other. See the diagram provided.

The control cable that feeds from the control box to the rotor remains the same as originally installed.

When the web page rotation button is pressed. The arduino will close this relay about 100milliseconds before the direction control relay. This "turns on" the power to the transformer. Then the chosen direction relay closes and the rotor turns in the desired direction.

CAUTION: The relay shield needs to be put into some kind of box or container to protect the user. Remember we have 120V AC going to it! Make sure to KEEP IT AWAY FROM ACCIDENTAL CONTACT!!

Step 16: Adding the Code to Our Arduino.

Now that we have our hardware built we need to add our software to control it.

Here We've added some code to the previous program to allow controlling the pins to the relay shield.

It adds 2 additional buttons (right) and (left). when pressed the arduino makes the transformer power relay close

100 milliseconds before it closes the directional relay for whichever button was pressed. it then holds those relays closed for 1 second or (1000 milliseconds). It then opens the relays in the same order thus stopping the rotation.

I've kept the code simple for this instructable. You could easily add more buttons with longer time durations. Pressing (left, left, left, left.....) to move the rotor in 1 second increments will get old after a while!

The code is commented so I'm not going to paste it into this text.

I've added a short video of it in action. Please excuse the way it's formatted. It's small on a sea of black but you can see it well enough to get the idea of what to expect! =)

Full Code with Pan control added:

/*---H-bridge Pin assignments for this code.....

First H-Bridge ----- Arduino 
____________
Iris (+) IN1     ---- 22 
Iris (-) 1N2     ---- 23
Zoom (+) IN3     ---- 24
Zoom (-) IN4     ---- 25

Second H-Bridge ---- Arduino
____________
Focus (+) IN3    ---- 26
Focus (-) IN4    ---- 27

--*/

#include  //install libraries for the ethernet 
#include 
#include 
#include 
#include 
#include 
#include 


byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD3, 0x7B}; // <-Set your ethernet card's MAC address. this should be ok.
byte ip[] = { 10,16,176,223 };                      //<--Replace with your ip address
EthernetServer server(80);                          //<--Create a Web Server. WWW runs on port 80 by default.  

String camString;             //Create a string to use for buttons
String message = "";          //same here

// Setup for tilt stepper motor.....
//declare variables for the motor pins
 int motorPin1 = 30;    
 int motorPin2 = 31;      
 int motorPin3 = 32;    
 int motorPin4 = 33;   
                        
 int motorSpeed = 1000;  //variable to set stepper speed
 int count = 0;          // count of steps made
 int countsperrev = 512/2; // number of steps per full revolution
 int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
 
// define antenna rotor control pins 
#define power 34
#define CW 35
#define CCW 36 

void setup(){

  Serial.begin(9600);
  
   for (int i=2; i<53; i++){  //quickly make all pins outputs
  pinMode(i, OUTPUT);
  digitalWrite (i,LOW);       // and set them low
  }
    Ethernet.begin( mac,ip); //<-- start the ethernet card
  server.begin();            //<-- start the web server

//declare the tilt stepper motor pins as outputs
   pinMode(motorPin1, OUTPUT);
   pinMode(motorPin2, OUTPUT);
   pinMode(motorPin3, OUTPUT);
   pinMode(motorPin4, OUTPUT);

// Set up rotor control pins
pinMode(CW,OUTPUT);
pinMode(CCW,OUTPUT);
pinMode(power,OUTPUT);
digitalWrite(CW,HIGH);
digitalWrite(CCW,HIGH);
digitalWrite(power,HIGH);

 }

void loop(){

  EthernetClient client = server.available();    //<-- start listening for someone to talk to us
  if (client) {
Serial.println("connection");
    while (client.connected()) {
      
      if (client.available()) {
        char c = client.read();

 
        if (camString.length() < 100) {


          camString += c; 
        } 
        if (c == '\n') {                              // <-someone knocked. lets show them a webpage full of buttons!
          client.println("HTTP/1.1 200 OK"); 
          client.println("Content-Type: text/html");
          //client.printlnln();
          client.println(F(""));
          client.println(F(""));
          client.println(F("Arduino CamControl"));
          client.println(F(""));
          client.println(F(""));
          client.println(F("Lens Control<br><table>"));
          client.println(F("<tr>"));
          client.println(F("</tr>"));
          client.println(F(""));
          client.println(F("<tr>"));
          client.println(F("</tr>"));
          client.println(F(""));
          client.println(F(""));
          client.println(F("</table>"));
          //Build rotor control buttons
          client.println("<table>");
          client.println(F("<tr>"));
          client.println(F("</tr>"));
          client.println(F("</table><br>"));
          client.println("");
          client.println("");
 
          delay(1);     
          client.stop();
          
          // The block below watches for button presses and applies the correct actions.......
          if(camString.substring(6,12) == "zoomin")  //<-- Zoom in button pressed. 
          {
                          zoomin();                   //<-- jump to routine that sends appropriate commands to motors
          }
           if(camString.substring(6,13) == "zoomout") //<-- Same as above but for Zoom Out
          {
                          zoomout();
          }
               
               if(camString.substring(6,15) == "zoominall") //<--zooms in all the way
          {
                          zoominall();
          }
           if(camString.substring(6,16) == "zoomoutall")   //<--zooms out all the way
          {
                          zoomoutall();
          }
                             
           if(camString.substring(6,14) == "irisopen")
          {
                          irisopen();
          }
           if(camString.substring(6,15) == "irisclose") 
          {
                          irisclose();
          }
          if(camString.substring(6,13) == "focusin") 
          {
                          focusin();
          }
           if(camString.substring(6,14) == "focusout")
          {
                          focusout();
          }
          if(camString.substring(6,15) == "focusin20")
          {
                          focusin20();
          }
           if(camString.substring(6,16) == "focusout20") 
          {
                          focusout20();
          }

          if(camString.substring(6,11) == "right") 
          {
                          righ();
          }

            if(camString.substring(6,10) == "left") 
          {
      
                          left();
          }
          camString="";  //<-- this clears the command string so it doesnt keep doing the same command over and over!

        }
      }
    }
  }
} 
// This block holds all the routines that control what the pins do when buttons are pressed.
 
void zoomin()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(100);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomoutall()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(3000);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}


void zoominall()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(3000);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomout()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(100);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}



  void irisopen()
{
  digitalWrite(22, HIGH);
  digitalWrite(23, LOW);
 

  delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}

void irisclose()
{
 digitalWrite(22, LOW);
  digitalWrite(23, HIGH);  
 
 delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}
   void focusin()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusin20()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}
void focusout()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusout20()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void right()
{
 digitalWrite(CW,LOW);
 delay(50);
 digitalWrite(power,LOW);
 delay (1000);
 digitalWrite(CW,HIGH);
 delay(50);
 digitalWrite(power,HIGH);
           }

void left()
{
  digitalWrite(CCW,LOW);
 delay(50);
 digitalWrite(power,LOW);
 delay (1000);

  digitalWrite(CCW,HIGH);
 delay(50);
 digitalWrite(power,HIGH);
                }

Next up..... Adding tilt to the system!

Step 17: Adding a Way to Tilt the Whole Thing!

Ok now that we have our camera, web browser zoom,iris,focus and pan controls. We need to add a way to tilt the camera up and down.

Since the camera housing sits on a kind of rocker that you lock down with screws. We can leave them loose. and by means of a rotating threaded rod or bolt we can fix a nut to a small beam connected to the back of the housing and when we rotate the threaded rod. the nut will travel up and down and tilt the housing.

Now we need a way to rotate and control the rotation of the threaded rod. At first I thought of a simple DC motor and our left over h-bridge. This will work but we wouldn't have very good speed control of the motor. We might have a hard time getting the tilt accurately and a small dc motor might not have enough torque to drive the threaded rod with the weight of the camera against it.

I decided on a geared stepper motor and control module. they're super cheap and have a lot of strength. They also have the advantage of being accurately moved in steps rather simply.

The other thing we have to take into account is that. As the camera tilts, the threaded rod will need to be able to lean back and forth as the angle changes. I'm going to use a small universal joint connector to connect the rod to the stepper motor. a small piece of flexible rubber hose would probably work just as well.

Step 18: Installing the "tilt" Mechanism and Hooking It Up

In order to Tilt the housing we need to mount the stepper motor inside with the camera. the universal joint coupler and the threaded rod will protrude out of the housing through the hole provided for the incoming wires. There's enough room that the turning shaft wont interfere with the wires.

We need the threaded rod to be able to lean as the housing tilts because the angle will change as the whole housing tilts up and down past horizontal. you can use a small bit of rubber tubing to accomplish this or a u-joined coupler. The Stepper motor shaft is 5mm and the threaded rod I used is 8mm. you'll need to measure your motor shaft and threaded rod and make sure to get the appropriate coupler.

The nut the threaded rod will run along needs to be affixed the the camera housing's support. I used epoxy to "glue" the bolt in place. It's not a permanent solution but it'll work until I weld it!

Once the motor is secured into the housing. We need to connect the Driver circuitry to the arduino mega.

The board will run off the 5V provided by the 5V pin. so connect the 5V input from the shield to the 5V out on the arduino.

The pins that drive the motor shield are labeled IN1 IN2 IN3 IN4. These pins are connected to the arduino mega pins 37, 38, 39 and 40 in that order. (See Img 6)

Step 19: Adding Our "tilt" Code to the Arduino

Now we add the filt functionality to our arduino code.

First we build 2 more buttons, "Up" and Down" and add them to our rotor control html table.

Next we add the code to the already built arduino code. When Up or down are pressed they send control to a routine that rotates the stepper motor Counter clockwise for "up" (this actually causes the nut on the threaded rod to move downward but we want the front of the housing to move up so we much drag the back end down.

and the opposite is true for "down".

Full code with Tilt added:

/*---H-bridge Pin assignments for this code.....

First H-Bridge ----- Arduino 
____________
Iris (+) IN1     ---- 22 
Iris (-) 1N2     ---- 23
Zoom (+) IN3     ---- 24
Zoom (-) IN4     ---- 25

Second H-Bridge ---- Arduino
____________
Focus (+) IN3    ---- 26
Focus (-) IN4    ---- 27

--*/

#include  //install libraries for the ethernet 
#include 
#include 
#include 
#include 
#include 
#include 


byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD3, 0x7B}; // <-Set your ethernet card's MAC address. this should be ok.
byte ip[] = { 10,16,176,223 };                      //<--Replace with your ip address
EthernetServer server(80);                          //<--Create a Web Server. WWW runs on port 80 by default.  

String camString;             //Create a string to use for buttons
String message = "";          //same here

// Setup for tilt stepper motor.....
//declare variables for the motor pins
 int motorPin1 = 30;    
 int motorPin2 = 31;      
 int motorPin3 = 32;    
 int motorPin4 = 33;   
                        
 int motorSpeed = 1000;  //variable to set stepper speed
 int count = 0;          // count of steps made
 int countsperrev = 512/2; // number of steps per full revolution
 int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
 
// define antenna rotor control pins 
#define power 34
#define CW 35
#define CCW 36 

void setup(){

  Serial.begin(9600);
  
   for (int i=2; i<53; i++){  //quickly make all pins outputs
  pinMode(i, OUTPUT);
  digitalWrite (i,LOW);       // and set them low
  }
    Ethernet.begin( mac,ip); //<-- start the ethernet card
  server.begin();            //<-- start the web server

//declare the tilt stepper motor pins as outputs
   pinMode(motorPin1, OUTPUT);
   pinMode(motorPin2, OUTPUT);
   pinMode(motorPin3, OUTPUT);
   pinMode(motorPin4, OUTPUT);

// Set up rotor control pins
pinMode(CW,OUTPUT);
pinMode(CCW,OUTPUT);
pinMode(power,OUTPUT);
digitalWrite(CW,HIGH);
digitalWrite(CCW,HIGH);
digitalWrite(power,HIGH);

 }

void loop(){

  EthernetClient client = server.available();    //<-- start listening for someone to talk to us
  if (client) {
Serial.println("connection");
    while (client.connected()) {
      
      if (client.available()) {
        char c = client.read();

 
        if (camString.length() < 100) {


          camString += c; 
        } 
        if (c == '\n') {                              // <-someone knocked. lets show them a webpage full of buttons!
          client.println("HTTP/1.1 200 OK"); 
          client.println("Content-Type: text/html");
          //client.printlnln();
          client.println(F(""));
          client.println(F(""));
          client.println(F("Arduino CamControl"));
          client.println(F(""));
          client.println(F(""));
          client.println(F("Lens Control<br><table>"));
          client.println(F("<tr>"));
          client.println(F("</tr>"));
          client.println(F(""));
          client.println(F("<tr>"));
          client.println(F("</tr>"));
          client.println(F(""));
          client.println(F(""));
          client.println(F("</table>"));
          //Build rotor control buttons & tilt control buttons.
          client.println("<table>");
          client.println(F(""));
          client.println(F("<tr>"));
          client.println(F("</tr>"));
          client.println(F(""));
          client.println(F("</table><br>"));
          client.println("");
          client.println("");
 
          delay(1);     
          client.stop();
          
          // The block below watches for button presses and applies the correct actions.......
          if(camString.substring(6,12) == "zoomin")  //<-- Zoom in button pressed. 
          {
                          zoomin();                   //<-- jump to routine that sends appropriate commands to motors
          }
           if(camString.substring(6,13) == "zoomout") //<-- Same as above but for Zoom Out
          {
                          zoomout();
          }
               
               if(camString.substring(6,15) == "zoominall") //<--zooms in all the way
          {
                          zoominall();
          }
           if(camString.substring(6,16) == "zoomoutall")   //<--zooms out all the way
          {
                          zoomoutall();
          }
                             
           if(camString.substring(6,14) == "irisopen")
          {
                          irisopen();
          }
           if(camString.substring(6,15) == "irisclose") 
          {
                          irisclose();
          }
          if(camString.substring(6,13) == "focusin") 
          {
                          focusin();
          }
           if(camString.substring(6,14) == "focusout")
          {
                          focusout();
          }
          if(camString.substring(6,15) == "focusin20")
          {
                          focusin20();
          }
           if(camString.substring(6,16) == "focusout20") 
          {
                          focusout20();
          }

          if(camString.substring(6,11) == "right") 
          {
                          righ();
          }

            if(camString.substring(6,10) == "left") 
          {
      
                          left();
          }
          if(camString.substring(6,8) == "up") 
          {
      
                          ccw();
          }
          if(camString.substring(6,10) == "down") 
          {
      
                          cw();
          }
          camString="";  //<-- this clears the command string so it doesnt keep doing the same command over and over!

        }
      }
    }
  }
} 
// This block holds all the routines that control what the pins do when buttons are pressed.
 
void zoomin()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(100);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomoutall()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(3000);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}


void zoominall()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(3000);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomout()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(100);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}



  void irisopen()
{
  digitalWrite(22, HIGH);
  digitalWrite(23, LOW);
 

  delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}

void irisclose()
{
 digitalWrite(22, LOW);
  digitalWrite(23, HIGH);  
 
 delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}
   void focusin()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusin20()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}
void focusout()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusout20()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void right()
{
 digitalWrite(CW,LOW);
 delay(50);
 digitalWrite(power,LOW);
 delay (1000);
 digitalWrite(CW,HIGH);
 delay(50);
 digitalWrite(power,HIGH);
           }

void left()
{
  digitalWrite(CCW,LOW);
 delay(50);
 digitalWrite(power,LOW);
 delay (1000);

  digitalWrite(CCW,HIGH);
 delay(50);
 digitalWrite(power,HIGH);
                }

void cw(){
  for (int T=1;T<512;T++){
  digitalWrite(37,HIGH);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,HIGH);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,HIGH);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,HIGH);
  delay(4);
  }
}

  void ccw(){
    for (int T=1;T<512;T++){
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,HIGH);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,HIGH);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,HIGH);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,HIGH);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  }
}

Step 20: Part 3 Adding Remote Web Control to the Camera's on Screen Display Menu.

The camera I'm I used in this project has some buttons to allow access to the On Screen Display or OSD menu system. Through the menu buttons you can set the mode of the camera (Color or Black and White). Set the shutter speed and amount of light amplification. Set Dead pixel elimination and ect.

If you're setting the camera in a tripod and sitting it out temporarily the button based menu us fine. However if you're placing the camera in a weatherproof housing out on a pole or tower. the buttons are going to be pretty hard to get at!

Fortunately the buttons on the camera are simple momentary on buttons that only pull a signal LOW to bring up the menu and settings. It's a simple task to simulate the button presses with an arduino and some transistors.

Step 21: Getting at the Buttons!

The first thing we'll need to do is open up the camera and get at the button board. Internally the camera consists of a sesnor board, a button board and a processor board. All are plugged in to each other with one way plugs so it's almost impossible to put it back together wrong! HOWEVER, as an aid I suggest you photograph the camera as you take it apart. that way you have a nice per-disasemblly reference to go back to if you cant figure something out!

Looking at image 2 you'll see our plan. The buttons on the board all use a common-ground. (remember those?) this time it's a good thing! that means all the buttons use one ground and we only have to worry about the signal side of them for our little transistor switches. the way it works is. We're wiring up our own electronic switch in "parallel" so what if either the physical button or our "electronic" button are pressed. the button's signal is sent. See image 4.

We're going to solder a ground wire to the ground side of the first switch. the rest of the switched only need one wire going to them. Once you have your wires soldered and cut to a length you like. We can move onto the next step.

Hooking them to the "switching" transistors.

Step 22: How the Transistors Work As Switches.

A transistor is the mainstay of most electronics! Put simply they do 2 things. Switch something on or off or amplify a signal. We're going to use them to switch something on or off!

Looking at the First image you can see that when a current is not going to the "base" of the transistor it's as if there's no connection between the collector and the emitter. The collector and the emitter are the poles of our switch. when we apply a small current to the "base" it "presses" the button more accurately. Allows the current to flow through it. When the current flows. The camera sees it as a button press.

to accomplish this we need to solder all the emitters from the transistors. One for the Enter, Up, Down, Left and Right buttons to the ground line. We have 2 things connected to this ground line. The Arduino ground and the camera ground.

Next each of the signal sides of each button needs to go to it's own transistor. Enter, Up, Down...

Next we connect the base of each button to the arduino.

Enter to pin 41.

Up to 42.

Down to 43.

Right to 44.

Left to 45

And lastly we need to add the code to our Arduino sketch!

Full code with OnScreen control added:

/*---H-bridge Pin assignments for this code.....

First H-Bridge ----- Arduino 
____________
Iris (+) IN1     ---- 22 
Iris (-) 1N2     ---- 23
Zoom (+) IN3     ---- 24
Zoom (-) IN4     ---- 25

Second H-Bridge ---- Arduino
____________
Focus (+) IN3    ---- 26
Focus (-) IN4    ---- 27

--*/

#include <SPI.h> //install libraries for the ethernet 
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>


byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD3, 0x7B}; // <-Set your ethernet card's MAC address. this should be ok.
byte ip[] = { 10,16,176,223 };                      //<--Replace with your ip address
EthernetServer server(80);                          //<--Create a Web Server. WWW runs on port 80 by default.  

String camString;             //Create a string to use for buttons
String message = "";          //same here

// Setup for tilt stepper motor.....
//declare variables for the motor pins
 int motorPin1 = 30;    
 int motorPin2 = 31;      
 int motorPin3 = 32;    
 int motorPin4 = 33;   
                        
 int motorSpeed = 1000;  //variable to set stepper speed
 int count = 0;          // count of steps made
 int countsperrev = 512/2; // number of steps per full revolution
 int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
 
// define antenna rotor control pins 
#define power 34
#define CW 35
#define CCW 36 

void setup(){

  Serial.begin(9600);
  
   for (int i=2; i<53; i++){  //quickly make all pins outputs
  pinMode(i, OUTPUT);
  digitalWrite (i,LOW);       // and set them low
  }
    Ethernet.begin( mac,ip); //<-- start the ethernet card
  server.begin();            //<-- start the web server

//declare the tilt stepper motor pins as outputs
   pinMode(motorPin1, OUTPUT);
   pinMode(motorPin2, OUTPUT);
   pinMode(motorPin3, OUTPUT);
   pinMode(motorPin4, OUTPUT);

// Set up rotor control pins
pinMode(CW,OUTPUT);
pinMode(CCW,OUTPUT);
pinMode(power,OUTPUT);
digitalWrite(CW,HIGH);
digitalWrite(CCW,HIGH);
digitalWrite(power,HIGH);

 }

void loop(){

  EthernetClient client = server.available();    //<-- start listening for someone to talk to us
  if (client) {
Serial.println("connection");
    while (client.connected()) {
      
      if (client.available()) {
        char c = client.read();

 
        if (camString.length() < 100) {


          camString += c; 
        } 
        if (c == '\n') {                              // <-someone knocked. lets show them a webpage full of buttons!
          client.println("HTTP/1.1 200 OK"); 
          client.println("Content-Type: text/html");
          //client.printlnln();
          client.println(F("<HTML>"));
          client.println(F("<HEAD>"));
          client.println(F("<TITLE>Arduino CamControl</TITLE>"));
          client.println(F("</HEAD>"));
          client.println(F("<BODY><html>"));
          client.println(F("Lens Control<br><table>"));
          client.println(F("<tr><td><input type=button value=zoomin onmousedown=location.href='/?zoomin;'></td>"));
          client.println(F("<td><input type=button value=zoominall onmousedown=location.href='/?zoominall;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=irisclose onmousedown=location.href='/?irisclose;'></td><td><input type=button value=irisopen onmousedown=location.href='/?irisopen;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=zoomout onmousedown=location.href='/?zoomout;'></td>"));
          client.println(F("<td><input type=button value=zoomoutall onmousedown=location.href='/?zoomoutall;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=focusin onmousedown=location.href='/?focusin;'></td><td><input type=button value=focusout onmousedown=location.href='/?focusout;'></td></tr>"));
          client.println(F("<tr><td><input type=button value=focusin20 onmousedown=location.href='/?focusin20;'></td><td><input type=button value=focusout20 onmousedown=location.href='/?focusout20;'></td></tr>"));
          client.println(F("</table>"));
          //Build rotor control buttons & tilt control buttons.
          client.println("<table>");
          client.println(F("<tr><td></tr><td>Pan/Tilt Menu</td><td></tr>"));
          client.println(F("<tr><td></tr><td><input type=button value=Up onmousedown=location.href='/?up'></td><td></tr>"));
          client.println(F("<tr><td><input type=button value=Right onmousedown=location.href='/?right'></td>"));
          client.println(F("<td><input type=button value=Left onmousedown=location.href='/?left'></td><td></td></tr>"));
          client.println(F("<tr><td></tr><td><input type=button value=Down onmousedown=location.href='/?down'></td><td></tr>"));
          client.println(F("</table><br>"));
          //Build OSD Buttons
          client.println("<table>");
          client.println(F("<tr><td></tr><td>OSD Menu</td><td></tr>"));
          client.println(F("<tr><td></tr><td><input type=button value=Up onmousedown=location.href='/?btnup'></td><td></tr>"));
          client.println(F("<tr><td><input type=button value=Right onmousedown=location.href='/?btnright'></td>"));
          client.println(F("<td><input type=button value=Left onmousedown=location.href='/?btnleft'></td><td></td></tr>"));
          client.println(F("<tr><td></tr><td><input type=button value=Down onmousedown=location.href='/?btndown'></td><td></tr>"));
          client.println(F("</table><br>"));
          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);     
          client.stop();
          
          // The block below watches for button presses and applies the correct actions.......
          if(camString.substring(6,12) == "zoomin")  //<-- Zoom in button pressed. 
          {
                          zoomin();                   //<-- jump to routine that sends appropriate commands to motors
          }
           if(camString.substring(6,13) == "zoomout") //<-- Same as above but for Zoom Out
          {
                          zoomout();
          }
               
               if(camString.substring(6,15) == "zoominall") //<--zooms in all the way
          {
                          zoominall();
          }
           if(camString.substring(6,16) == "zoomoutall")   //<--zooms out all the way
          {
                          zoomoutall();
          }
                             
           if(camString.substring(6,14) == "irisopen")
          {
                          irisopen();
          }
           if(camString.substring(6,15) == "irisclose") 
          {
                          irisclose();
          }
          if(camString.substring(6,13) == "focusin") 
          {
                          focusin();
          }
           if(camString.substring(6,14) == "focusout")
          {
                          focusout();
          }
          if(camString.substring(6,15) == "focusin20")
          {
                          focusin20();
          }
           if(camString.substring(6,16) == "focusout20") 
          {
                          focusout20();
          }

          if(camString.substring(6,11) == "right") 
          {
                          righ();
          }

            if(camString.substring(6,10) == "left") 
          {
      
                          left();
          }
          if(camString.substring(6,8) == "up") 
          {
      
                          ccw();
          }
          if(camString.substring(6,10) == "down") 
          {
      
                          cw();
          }
          if(camString.substring(6,11) == "btnent") 
          {
                          BTNent();
          }

            if(camString.substring(6,10) == "btnup") 
          {
      
                          BTNup();
          }
          if(camString.substring(6,8) == "btndown") 
          {
      
                          BTNdown();
          }
          if(camString.substring(6,10) == "btnleft") 
          {
      
                          BTNleft();
          }
          if(camString.substring(6,10) == "btnright") 
          {
      
                          BTNright();
          }
          camString="";  //<-- this clears the command string so it doesnt keep doing the same command over and over!

        }
      }
    }
  }
} 
// This block holds all the routines that control what the pins do when buttons are pressed.
 
void zoomin()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(100);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomoutall()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(3000);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}


void zoominall()
{
  digitalWrite(24, HIGH); 
  digitalWrite(25, LOW);  
  delay(3000);
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);  
 
}
  
  void zoomout()
{
digitalWrite(24, LOW); 
   digitalWrite(25, HIGH); 
    delay(100);
  
   digitalWrite(24, LOW); 
   digitalWrite(25, LOW);   
}



  void irisopen()
{
  digitalWrite(22, HIGH);
  digitalWrite(23, LOW);
 

  delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}

void irisclose()
{
 digitalWrite(22, LOW);
  digitalWrite(23, HIGH);  
 
 delay(30);

  digitalWrite(22, LOW);
  digitalWrite(23, LOW);
}
   void focusin()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusin20()
{
 
  digitalWrite(26, HIGH); 
  digitalWrite(27, LOW);
 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}
void focusout()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(30);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void focusout20()
{
 digitalWrite(26, LOW); 
  digitalWrite(27, HIGH); 

 delay(700);

  digitalWrite(26, LOW);
  digitalWrite(27, LOW);
}

void right()
{
 digitalWrite(CW,LOW);
 delay(50);
 digitalWrite(power,LOW);
 delay (1000);
 digitalWrite(CW,HIGH);
 delay(50);
 digitalWrite(power,HIGH);
           }

void left()
{
  digitalWrite(CCW,LOW);
 delay(50);
 digitalWrite(power,LOW);
 delay (1000);

  digitalWrite(CCW,HIGH);
 delay(50);
 digitalWrite(power,HIGH);
                }

void cw(){
  for (int T=1;T<512;T++){
  digitalWrite(37,HIGH);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,HIGH);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,HIGH);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,HIGH);
  delay(4);
  }
}

  void ccw(){
    for (int T=1;T<512;T++){
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,HIGH);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,LOW);
  digitalWrite(39,HIGH);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,LOW);
  digitalWrite(38,HIGH);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  digitalWrite(37,HIGH);
  digitalWrite(38,LOW);
  digitalWrite(39,LOW);
  digitalWrite(40,LOW);
  delay(4);
  }
}
void BTNent()
{
  digitalWrite(41, HIGH); 
  delay(30);
  digitalWrite(41, LOW);   
}
void BTNup()
{
  digitalWrite(42, HIGH); 
  delay(30);
  digitalWrite(42, LOW);   
}
void BTNdown()
{
  digitalWrite(43, HIGH); 
  delay(30);
  digitalWrite(43, LOW);   
}
void BTNleft()
{
  digitalWrite(44, HIGH); 
  delay(30);
  digitalWrite(44, LOW);   
}
void BTNright()
{
  digitalWrite(45, HIGH); 
  delay(30);
  digitalWrite(45, LOW);   
}

Step 23: Watch the Skies!

Now that we have all the parts in place it's time to sit back and watch the skies!

If you find this Instructable informative or helpful. I'd appreciate your vote in the Space contest!

Having your own Remote control Mini-Telescope/Video camera is great fun!

Space Contest 2016

Second Prize in the
Space Contest 2016