Introduction: Reginald: a UDP Surveillance Bot; Control Via the Internet

About: My name is Nick, I work at Continental and just recently got my BSEE. I love working with projects on lower levels to design them from the ground up. Working in the lower levels also gives me a greater underst…
Reginald started from the simple, yet bold idea to control a bot from anywhere in the world with a live video feed. What I wasn't expecting was for Reginald to develop into an involved, feature rich project. With my work and money, I was able to complete a project exactly to my satisfaction and more. This tutorial chronicles the entire project: from top to bottom.

Before I started my project, I had several goals that I wanted to see in Reginald:
  • Have one battery power absolutely everything (redundant technologies cause complications)
  • Implement a method where the video feed and the controls work through the same technology. This simplifies Reginald for the end user. The user will only need to connect to Reginald in one way and not two separate ways which is what I often see in most projects that implement video feeds (Again, redundant complications; saturate two separate links to one).
  • For the user to be able to interact with Reginald in real time.
  • Encrypt Reginald so no one can just simply type in the IP Address and access him
  • Have one single input/output board to saturate all the circuitry. This way: Reginald is much cleaner in appearance, and will create a sturdy electric foundation to connect my peripherals to.
  • Have a live console bringing information to the user.
  • Code a GUI that looks good, can be controlled via key commands and is feature rich.    
  • Simplicity in end user experience; so any layman could operate.
  • Most importantly: set up the network connection to allow access from anywhere
What's the point of this?

Reginald is a very useful project for the end user. If a user is interested in checking on his or her house from school or work, that person would be able to do so from an infinite amount of angles. The user can move around the house wirelessly and greet others. If you have children you can let them know you always have your eye on them!

More importantly, the biggest use featured in this Instructable is the implementation of the UDP technology. If someone can interface any physical and/or electrical object to an Arduino, that person could be able to control this object wirelessly in real time from anywhere. This is very useful. Reginald is an example application for UDP, a highly under utilized technology among projects.

What will this Instructable provide?

This Instructable will introduce Reginald as a whole and then go into a breakdown of every component in detail.

Performing all the necessary networking to accomplish this can be very complex and involved, however this method of communication is clarified and explored through this Instructable. I saturated approximately a solid month of research and troubleshooting into a simple guide; I provide troubleshooting guidance and example tests along the way.

Step 1: Introduction/Prerequisites

This is a large project; so I believe it will provide the best clarity to break down this guide first with a large perspective and afterwards exploring each individual component of the project separately.

Instructable Breakdown:
  • First, I will discuss the prerequisite knowledge that you should have to first attempt to tackle this project. A beginner will likely have trouble following the guide.
  • Secondly, I will show a "macro" view of the project and discuss it generically so the reader understands my approach to accomplish Reginald. If the reader understands my process, it'll be easier for the reader to pick and choose components from my process that he/she desires in his/her own project. I don't assume that everyone would want to clone their own Reginald; but to customize the project with their own wants.
  • Thirdly, I will give the parts list divided among the different components of the project.
  • It is at this point that I will go into detail of each part of Reginald.
Prerequisite Knowledge that I will assume you already know:

This will save time of myself and others who are already very familiar with these topics. If I was to cater to the absolute beginner here, this Instructable would be easily, magnitudes larger. Someone who already understands the topics would have difficulty following the guide due to the size of it.

However, an absolute beginner can familiarize oneself with the given topics to research before attempting Reginald. If an individual understands these topics, that person will be able to understand the project.

Therefore, this Instructable caters to all. Given one is willing to learn.

The topics are:
Helpful Notes:

In this tutorial, I will be showing schematics and diagrams of the custom PCB I built to saturate all the circuits; but showing how to build the board step by step would be a fairly large instructable in itself. If you understand the above, you won't have a problem following the information that I provide.

The networking section is by far the most important, especially if you're interested in communicating with your project via the Internet; and even more so if you happen to have AT&T as your ISP. You'll see later. 


Step 2: Macro View of the Project

Here I will discuss the overall project so the reader understands my intentions in the design. As mentioned earlier: if the reader understands my intentions, then it will be a trivial task for the reader to choose the parts of my design he/she wishes for his/her own project.

The Macro View of Reginald

The main picture is from a large point of view of how Reginald works. 

The grey box in the bottom left corner is the physical robot, located at home. 
The grey box in the bottom right corner is the client program. It is a GUI that receives commands from the user and transmits the commands to Reginald. The GUI is run on a computer.

The Networking

Notice that there are two separate ways to connect to Reginald. This is because it is useful to have two different ways to make the connection dependent on the circumstances.
  • There is a direct connection from the GUI (Client) to Reginald (Server). This is under the circumstance that Reginald is very close to the User. If the User is using the GUI (Client) on a laptop, then Reginald can create its own wireless "hotspot" if you will (however it's not an actual hotspot because the user cannot connect to the internet). The user at this point can connect directly to Reginald and control him. 
  • The other method of connection is much more complex, and where the knowledge of Networking is critical. For simplicity, lets assume the user is on a computer at school while Reginald is at home. Reginald at this point is utilizing the Wireless Bridge shown and is connected as a wireless device on the home network. Reginald has a specific IP address and Port within the network. The Primary Home Router is configured with a Port Forward exception that a UDP request on the corresponding Port of Reginald goes to said Reginald. The user could run the GUI (Client) program on the computer at school. At this point, the user types in the external IP address of the Primary Home Router and the Port Reginald is located into the program. The user then sends a command by interacting with the interface. The command gets sent through the internet and to the Primary Home Router. The Primary Home Router sees the specified Port and, being configured properly, sends the command wireless to the Wireless Bridge on Reginald. The Wireless Bridge hands the command to the Arduino and Reginald responds appropriately.
It's worth mentioning that the latter connection method is optional. The reader may decide to go with a simpler approach and only use the direct connection. The obvious downside to this is that the user will not be able to control Reginald from anywhere, only when Reginald's hotspot is within range of the user will the user be able to control Reginald.

Don't the Routers complicate the project and make it bulky?

I realize that using the routers on Reginald is a bulky at best; as an alternative, I could have used a wireless surveillance camera connected directly to the Primary Home Router and used a wifi sheild for the Arduino to also connect to the Primary Home Router. This would have cut out the "middle man" (Routers) of the project out and I could have made Reginald significantly smaller; in addition to this, utilizing the routers in my design is harder to implement.

Why did I use Routers?

The reason behind the routers is that one of my goals is simplicity in user experience. If the user wants to control Reginald, at home, from school, and decides to take Reginald to his/her friends house to show off: the user simply unplugs the camera, power and Arduino from the Wireless Bridge and plugs it into the Netgear Router. The user connects to the Netgear router and that's it! If I were to implement a wireless network camera and wifi shield in my design, the user would perform the following to accomplish the same scenario:  bring Reginald to friend's house; get all the networking information of the home network from friend; configure the camera to the network; access Reginald's code; change web configuration and upload new sketch to board; then connect.

Be mindful when I refer to the Routers:

This project actually uses three Routers. The first one I will refer to as the "Netgear" router located on Reginald. I won't talk about this very much, it's only used for the direct connection to Reginald if you brought him outside the home network. A simple setup.

The second and third routers talk to each other. They are what set up the communication to anywhere. I'll refer to one Router as a "Wireless Bridge" which is located on Reginald. I call it a Wireless Bridge because it is a client to the third Router: the "Primary Home Router", I may also call the third Router an "Access Point" (AP). The Primary Home Router is the Router connected to your modem at home which brings a wifi internet connection to your home. The Wireless Bridge is a client that serves the internet from the Primary Home Router to devices connect to itself (in this case: Reginald).

Later I'll be talking about how the Wireless Bridge works.

Interesting Notes:

Also notice that the camera does not interact with the Arduino at all. The camera is powered with the PCB board and connected to the Wireless Bridge or Netgear Router. The user can access the camera from anywhere at that point.

It is also important to recognize that the only thing the Battery is connected to is the PCB board. This is because the PCB distributes the power to everything else. Not all of the components require equal amounts of power. The Routers both require 12 volts; the Arduino and Peripherals all require 7 volts; and the Camera requires 5 volts. The PCB board needs to accommodate all these parts.  

Step 3: List of Parts

My project proved to be much more expensive than I anticipated. However, this is mostly from buying nice parts for Reginald so my project would appear as impressive as the networking technology behind it.

Additional Note: If you were looking just to extract the internet controlling paradigm I provide, it will be much cheaper. You only need a Router you probably have laying around and an Arduino and Ethernet Shield. 

Quantities are placed in parenthesis.

The Reginald parts list, divided by component:

Chassis and misc. mechanics:
Drivetrain:
Flashlight:
  • (1) Luxeon Rebel Triple-LED Narrow Lens $5.95 each https://www.sparkfun.com/products/9733?
  • (3) LEDs - Infared 950nm $0.95 each https://www.sparkfun.com/products/9349
  • ABS sheet (included with the "Chassis and misc. mechanics" category)
  • Generic single thread speaker wire (included with the "Electronics" category)
  • (1) B.E.C. or Molex connector (included with the "Electronics" category)
  • (1) Black Poster Board $1.95 each (Walmart)

Electronics (Arduino and Custom PCB):
Surveillance Cameras:
Ballistics:Network:
  • (2) Routers $??.??
This list doesn't include obvious items; these include but are not limited to: Heat Shrink Wrap, Ethernet Cables, Bolts and Nuts etc.

Tools:

None of the tools used in this project are specialized. You will need your basic tools: a soldering iron, multimeter, tools to cut the chassis pieces out, a drill, a hammer etc. 

About the Routers:

The Routers I left in question for price since the price on this varies so heavily. Personally, my Netgear Router was one that was just laying around doing nothing and the Linksys WRT54G V8 Router I bought for $3 on Amazon! Don't jump ahead on both the Routers though. One is left with the original firmware and the other will be flashed with the DD-WRT firmware. More on this later.


Step 4: Overview of the Individual Components

Now I'll start introducing the individual components of Reginald in detail. The first ones to be introduced will be the most fundamental and slowly I'll move onto the more involved pieces. I'll save the Internet communication for last.

Table of Contents:

Bare Minimum:
  • Setting up the Basic Wifi connection - Step 5
  • Reginald's Code - Step 6
  • Let's test the system so far - Step 7
The Electrical Side:
  • Setting up the Surveillance Camera - Step 8
  • The Custom PCB - Step 9
    • Building the Power Distribution Component - Step 10
    • Adding the Servo Pins - Step 11
    • Building the Flashlight circuit - Step 12
    • Interfacing the Dream Cheeky Turrets - Step 13
Building the Peripherals:
  • Modifying the USB Turrets for the Arduino - Step 14
  • Building the Flashlight - Step 15
​Constructing Reginald and Mounting the Peripherals:
  • Building Reginald's Chassis - Step 16
  • Painting Reginald - Step 17
  • Carefully Mounting the Mechanics - Step 18
  • Mounting the Flashlight and the Camera -Step 19
  • Mounting the Turrets onto the Tilt Bracket - Step 20
  • Creating a Battery Housing - Step 21
Control over the Internet:
  • Using DD-WRT to create a Wireless Bridge - Step 22
  • Configuring a Wireless Bridge with DD-WRT when you have AT&T - Step 23
  • Port Forward your Home AP to allow UDP and TCP exceptions - Step 24
  • Testing the Communication over the Internet - Step 25
Closing Notes:
  • Conclusions and Future Plans - Step 26

Step 5: Setting Up the Basic Wifi Connection

This step will be one of the easiest. For this, you should have:
  • Arduino (of your choice, UNO R3 is used here)
  • Arduino Ethernet shield
  • A stock wireless Router ("Netgear" Router)
  • A Ethernet Cable
  • (Optional) 5V wall wart with 2.1mm barrel jack to plug into your Arduino, make sure the wall wart is center positive or you'll blow the board
Combine the Ethernet shield and the Arduino, and power the board with the wall wart (The wall wart is temporary, I want us to first have the basic technology down on Reginald before moving onto the more specific components. After the custom PCB is built, you will be able to power the Arduino through a battery).

Connect the shield to the "Netgear" Router with the Ethernet cable, power the Router. I hesitate to mention to make sure not to plug the Ethernet cable into the WAN port on the Router. 

That will be it, the hardware is put together. Connect to the Router wirelessly with your computer. Check the configuration settings of the Router through your favorite browser (Chrome for me) and make your own changes, so long it doesn't affect the Arduino or the ability for you to connect to it.

Step 6: Reginald's Code

There are two separate programs to this project. The Arduino (Server) side and the GUI (Client) side.

In summary; to successfully run the code for Reginald, you will need to accomplish the following:
  • Download everything required. (Arduino and Processing IDE, the .zip file on this Instructable page and the libraries)
  • Configure Processing by placing the libraries in the correct directory in the Processing program folder
  • Configure the sketch for the GUI
  • Be able to upload code to the Arduino
For the GUI, you will require the Processing IDE (it will look familiar, the Arduino IDE is based on the Processing IDE), the ControlP5 library and the Hypermedia library.

I assume you already have the Arduino IDE, download the .zip on this instructable page and the follow the links to download the appropriate SW:

Processing IDE:
http://processing.org/download/

ControlP5 Library:
http://www.sojamo.de/libraries/controlP5/

Hypermedia Library (Click on "Processing library"):
http://ubaa.net/shared/processing/udp/

About Processing and the Libraries:

Processing is a great way to easily create programs that open independent windows to capture user events. After a program is finished, it's a trivial matter to export the program into an executable. There are many ways to capture user interaction.

The ControlP5 library helps create the various buttons and widgets used in the GUI I made. ControlP5 is a superior library for GUI creation. It's easy to use, very sharp and comprehensive. With Processing and ControlP5, one can easily create a powerful and feature rich user interface.

The Hypermedia Library handles all of the UDP communications.

What do I do with the Libraries?

After you have downloaded everything, be sure to place the two libraries in the correct location so Processing can find them. Unzip the libraries (Hypermedia will download as a "udp.zip" file) and follow the path: 
processing-X.X.X\modes\java\libraries
within the processing program folder in your downloads. The 'X's represent the version number of Processing you have downloaded. Place the folders for the libraries here.

Now to configure the sketch for the GUI:

To configure the sketch for the GUI, all one needs to do is to grab the folder: "GUIClient" from the .zip file and put that somewhere on his or her computer.
Within the Processing IDE, choose to open a sketch and browse to the "GUIClient" folder. Enter the folder and select the sketch inside. A new window of Processing should load up with code. Run the program.
After choosing "Run", an error may appear within the Processing console regarding the program being unable to open the socket correctly. This can be expected; since the proper IP address and port likely hasn't been entered yet.

Encrypting Reginald:

Reginald doesn't want to be controlled by just anyone, so he's encrypted with his own password. See pictures 4 and 5 to see a demonstration of this.

When you send the command "wake", Reginald sees this as a request for access. At that point, he finds your IP address and Port number from which you have sent and sends a greeting back to you. At this point, he will request a password for access. Enter in the correct password and you may have control. You will be denied however if the password is incorrect.

If you are trying to control Reginald from a remote location, keep in mind you may not receive Reginald's greeting and confirmation of access. This is because if you are connected to the wifi of a school or business, the firewall of that wifi may block the messages Reginald is attempting to send you. However this won't affect functionality. If you simply enter in "wake" followed by your password, you will gain access within 15 seconds. Reginald will simply assume you did receive the packets. This is one of the drawbacks to UDP as opposed to TCP. TCP makes sure that the packet is received whereas UDP simply sends the packet and doesn't worry about. However this lack of verification makes UDP much quicker and lightweight, which I like.

Times like these are where the "Locking Switch" is handy. If I were to send "wake" with the "Locking Switch" disabled, then pressing the keys 'w' and 'a' would send commands. This could confuse Reginald, and you would be denied trying to enter your password.

**** EDIT March 6th, 2013 ****

Processing has since updated their SW from 1.5.1 to the Beta 2.0. If your version is 2.0 or above, use the GUIClient2.0 within the .zip file. The only difference is the key capturing method, you can read about it here:
http://processing.org/reference/key.html

Step 7: Let's Test the System So Far

At this point, the network has been put together and the software and code has been configured and prepared. To test what has been done so far, we will wirelessly turn an LED on and off with your computer over a wifi connection.

TEST THE SETUP

Follow these steps:
  1. Have your Simple Network set up as discussed earlier (Arduino plugged into Router and powered, etc.)
  2. Use a bread board to connect a LED and resistor in series. Connect the LED to pin A5 and the resistor to GND.
  3. Connect the USB cable from your Arduino to your computer. Upload the Arduino sketch to the board.
  4. Note that the IP Address used within the sketch is 192.168.1.177 and the Port is 8888
  5. Connect wireless to the Router with your computer
  6. Run the GUI
  7. Verify that in settings, the IP Address and the Port match the Arduino's settings
  8. Enter the word "wake" in the text field and hit "Send"
  9. After Reginald greets you, enter the password: "password"
  10. Reginald will verify you, then allow you access
  11. Toggle the Light Switch on the Main Page of the GUI
  12. The LED should light on and off; the console reads that the Light is being activated and deactivated
If you got the LED to light up then congrats! The basic connection to the Arduino has been made and now you are able to wirelessly control the LED.

If you want to disable the password and salutations features from Reginald; go into the Arduino code and comment out the "Salutations()" function within, under "void setup()".

Step 8: Setting Up the Surveillance Camera

This is an easy step of the project.

What type of Camera will you want?

When choosing the Surveillance Camera, it will need to have network capabilities. In my opinion, it's best to have a camera with an Ethernet port. That way you would trivially connect an Ethernet camera from the camera to the Router. You could get one that is solely wireless, and have it configured to wirelessly connect to the Router on Reginald. I recommend Amazon for purchasing these Cameras.

Why did I implement this for video feed?

This is a fairly trivial method of implementing a video feed, and not at all challenging; but I felt as though it was by far the most practical. If you were to use the Arduino to interface with a camera and to process the video feed, the FPS would be dismal at best. The Arduino is not powerful enough to process even small images. Then the equally difficult task would be to create a sort of interface on the computer end to accept the video feed and display it. 

Setting up the Camera:

First, connect the surveillance camera to the Router you are using for Reginald via Ethernet cable. Install the SW and drivers for the camera from your computer. You should be connected to Reginald's network so the SW can detect the camera. The SW should set the camera up with a default IP Address.

Access the camera through your favorite browser and set it to a static IP address. Specify a Port number for the camera (81 is a good choice). 

That's it! However you can only access this camera while you are connected to Reginald's network. Later when I discuss Port Forwarding, it will be understood how to configure the camera so you can view it from anywhere.

Power Cable for the Board

This specific camera requires 5 volts, and we will make sure that we supply that voltage when we construct the custom PCB. For now we will will create a cable to plug into the future PCB. 

In the 3rd picture, there is the power inlet on the back of the camera. This camera is center positive, meaning that the center pin in this inlet needs to have the 5 volts. 

Look at the 4th picture, this shows a barrel jack I purchased from Radioshack. Since the camera is center positive, the metal inside the jack needs to be 5 volts, and the outer barrel needs to be ground. There are 2 pins at the bottom of this barrel jack for each of these. Use a multimeter to test the continuity between the pins and the outer and inside. Solder a wire to each pin and interface the other end of the wires with a BEC or Molex connector so it can be plugged right into the PCB.


Step 9: The Custom PCB

Why build the board?

As mentioned before, my PCB for this project was meant to saturate all necessary circuits into a single board. That way, I can connect all peripherals to one source, instead of having wires all over the place. Also previously mentioned: the PCB distributes the power to the components. Everything on Reginald connects to this board for power.

So, how does this interact with the Arduino? 

On the copper side of the PCB, you'll see I have long header pins extending from the board. These plug into the Arduino Ethernet Shield, this is how the circuits on this board will interface with the Arduino pins. Solder the circuits to these pins. To solder the pins in place, I removed the plastic jacket, inserted each pin individually and soldered them in. The pins I used are seen in the last picture. They have an eyelet on one side which is very convenient because one can easily insert them into a PCB hole and they'll stay in place. These pins are from Sparkfun, I provided the link on the List of Parts step.

Don't be intimidated by the looks of it:

If you were to look at my board, I would imagine it would be very difficult to follow what I did to build it. Wires and pins on the board are absolutely everywhere. So don't worry about trying to understand my board, because the board that you require for your build may need to be different from mine to compensate for the different voltages and your needs. 

Basically, this board is many, very simple circuits. One of its purposes is to be a power distributor, dividing the power appropriately to the various components. If you look at the flip side of the board, there are very long power and ground buses that run through it. The power also changes on the way.

Follow the next couple steps, and I'll give the schematics and  descriptions of each part of this board individually. If you heeded the prerequisites at the beginning of the tutorial, the hardest task for you is to decide where you will place the circuits on the board.

Step 10: Building the Power Distribution Component

The circuit that distributes the power is probably the most important of the other circuits. This circuit takes in the 12 volts from the battery and hands off 12 volts to the router. You will need header pins in the PCB for the Battery and the Router to plug into. Place a Molex or BEC connector on a Router cable and the Battery to plug into the header pins. The camera also needs 5 volts; 7 volts may have worked, but I didn't want to risk a hundred dollar camera to spare $2 in electrical components. So I have another voltage regulator and an additional decoupling capacitor. Picture 4 shows my setup.

12 volts to 7 volts

The 12 volts continues into the regulator input pin, a decoupling capacitor crosses the power and ground on the input and output sides of the regulator to account for voltage discrepancies. 

I wanted 7 volts to power most parts of the circuit (Arduino, servos, DC motors, flashlight), but I couldn't find a regulator that outputs 7 volts, so I settled with a 7805 regulator (outputs 5 volts), and used resistors to adjust the voltage that the regulator outputs. See the schematic to see where the resistors need to be placed. Resistor R2 needs to go between the Ground pin on the regulator and Ground. The resistor R1 needs to go between the middle Ground pin on the regulator and the output power. 

The values of the resistors depends on what value your regulator outputs. Use the following calculator to determine what resistors you'll need:

http://www.daycounter.com/Calculators/Voltage-Regulator-Resistor-Divider-Calculator.phtml

The reference voltage is what your regulator outputs, the output voltage is the voltage you want outputted. Be sure to troubleshoot this for your application with a multimeter.
Keep in mind that it is the RATIO between the two resistors that determines the output voltage.

If everything I mentioned seems like gibberish, you will need a good read on how a power supply circuit works. Here's a wonderful one, it will explain the basics and assumes you know virtually nothing:

http://www.sparkfun.com/tutorials/57

12 volts to 5 volts

Here is the other voltage regulator to drop the volts down to 5 just for the surveillance camera.

Test the circuits so far by inputting 12 volts to the pins on the battery. Is the output from the first voltage regulator 7 volts? Is the output from the second voltage regulator 5 volts?

Important Note: Lots of voltage regulators can only handle an amp of current at max. If you surpass this limit you'll get power failures. With Reginald, I was able to barely make the amp limit. Amazing considering how many peripherals I am running but Reginald does well so far. Keep this in mind: it is probably safe to think about using switching regulators for the power supply circuit.

Step 11: Adding the Servo Pins

There needs to be a way to interface the servos to the Arduino via the PCB board. Use header pins to create a 5 x 3 set of pins, soldered to the PCB. I'm not sure about other brands of servos, but Hitec servo pins are arranged with the Ground wire on one side, the middle pin is power, and the other side is the signal wire. 

About the diagram shown:

In the 1st picture, you can see I plan for "Left Wheel", "Right Wheel", "Pan" and "Tilt" servos. The right and left wheel servos obviously power the wheels for Reginald. The panning and tilting servos are for panning and tilting the Camera and the Turrets on Reginald. There are two independent servos for tilting and one servo to pan both the Camera and the Turrets.

The signal wires of the Tilt brackets are tied together so they are in sync with one another. My goal was to have the Camera and the Turrets to move together. This way, where ever the Camera is pointed, the Turrets will fire.

Testing:

When everything is wired and connected, test by plugging it into the Ethernet Shield on the Arduino. If you kept the same pins as I have, you can simply load the code onto the board. Set yourself up as you did when you toggled the LED. Use the GUI to try to control some of the servos. When you press up, do the wheel servos move?


Step 12: Building the Flashlight Circuit

The Flashlight circuit is trivial. Consider it a warm up for the Turret circuit that comes next.

The Flashlight will interface with the custom PCB with header pins and a BEC or Molex connector (as with everything in this project). I choose the A0 pin on the Arduino to output HIGH or LOW to turn the Flashlight on or off.

About the NPN Transistor:

When you read about Transistors through your favorite search engine within the Prerequisite topics I offered: you discovered that Transistors act as little electrical switches. The amazing thing about Transistors is that you can control a large amount of current with a small amount of current. This is ideal opposed to having the Arduino drive or power the LED Flashlight, which isn't very practical. It's better to have the Arduino signal when current can pass through or not. The Arduino doesn't actually power the Flashlight on and off, it simply allows the battery to power the Flashlight at specified moments.

When the "Base" pin on the NPN Transistor goes HIGH, current flows from the "Collector" to the "Emitter", connecting the negative pin of the Flashlight to ground and thus completing the circuit.

Now that you understand my design, build it!

Testing your own circuit:

Test this by plugging the PCB into the Ethernet and Arduino setup as before. Get your connection up and running and toggle the "Light Switch" since you haven't constructed the Flashlight yet, is there a voltage difference between the Flashlight pins when the switch is on?

Step 13: Interfacing the Dream Cheeky Turrets

The electrical circuit for the turrets are two separate transistor circuits. The circuits for the turrets are just like the Flashlight circuit except slightly more complicated.

How do these turrets function exactly? 

Within each turret is a switch and a small DC motor. These are all you need to fire the turret. The DC motor cranks a plunger to the back of the turret, and at a certain point, the mechanics within the turret release the plunger. This is spring loaded so the plunger then launches forward, firing a missile. At this point, the plunger trips a switch. The DC motor continues to pull the plunger back again. The mechanics within the turret automatically rotate the barrel; prepping the next missile as the switch releases. The process starts all over again.

The design in this product is fairly impressive. The mechanics within the turret take care of so much for you. The only things you have to control to fire the turret correctly are the switch and the DC motor.

How to build the circuit for the Turrets:

In the old microcontroller that we cut out from the turret: it used the switch to detect when the turret fired exactly. It then sets a timer to run the DC motor just a little bit longer to pull the plunger back a bit. In the original design, when you fire the turret, it runs the DC motor for a good second before it actually fired. This was not satisfactory to me, I wanted the turret to fire the moment I pressed my space bar on the keyboard. 

Later, we will modify the turrets to interface with our board, but for now, we are only building the board.

This is how the transistor circuit works:

The positive wires of the DC motors in the turret are connected directly to 7 volts, the negative wires are connected to the transistor "Collector" pin. The "Emitter" on the transistor goes to ground. When the "Base" of the transistor is LOW, no current flows through the "Collector" to the "Emitter". When I want to fire a missile, I set the "Base" HIGH with the Arduino. Current then starts flowing, and turns the DC motor on. While the "Base" is set to HIGH, the Arduino is constantly checking its input pin (the input pin is the one connected to the switch) with a "While" loop. Since the DC motor is running, the turret will eventually fire. It is at that point the switch inside the turret will close, and send the input pin to the Arduino HIGH. The Arduino sees this and counts for a certain period of time before setting the "Base" pin LOW, and stopping the current to the DC motor. In this period of time, the switch is released and goes back to LOW.

The amount of time the Arduino counts for before setting "Base" LOW again is the amount of time it takes for the DC motor to pull the plunger back just before the moment of firing. It is through this method that the turret will fire the moment I press the space bar.

Important Note about the input pin to the Arduino:

It is important to keep in mind, that it is a good idea to have a resistor in between the input pin on the Arduino and the switch, so that way the input pin doesn't receive a powerful 7 volts. I don't show this resistor in the first two diagrams, but in the 4th picture of my board, these resistors are highlighted.

Step 14: Modifying the USB Turrets for the Arduino

I purchased two USB turrets from Thinkgeek that I used to mount onto Reginald. Much of the turret was scrapped to leave only the necessary cannon component for the project.

Essentially the procedure is composed of separating the cannon from the base, removing the old wires from the DC motor and switch component from the cannon and soldering in new wires.

Follow the pictures and the comments to get a thorough explanation.

After finishing, put everything back together and connect a 9V battery to the DC motor. If it doesn't fire and only makes this clicking sound, you have the polarity backwards. The DC motor only needs to run in one direction. All the turning and firing is automatically taken care of in the mechanics when you are running the DC motor.

Step 15: Building the Flashlight

For Reginald, I built my own flashlight. I wanted one that was small, light and had a plug that would go into the custom PCB. Describing how to build the flashlight in words would be difficult. Instead, pictures of the process will be much more effective. Just click on the first one, and use the images and comments as your guide.


Step 16: Building Reginald's Chassis

Reginald's chassis is very simple as I was planning. I didn't require anything elaborate since my overall goals for Reginald was to have him be feature rich and sturdy. I cut two 7.5" by 15" pieces of ABS for the top and bottom and drilled three 0.875" holes on top for the ball bearings. The side plates are 4" x 6" each.

My recommendation with this is to cut very slow. Too high of speeds will heat up and melt the plastic: a mistake I made on the rear hole on the top platform. See the 3rd picture for this.  

Step 17: Painting Reginald

After constructing the chassis, I had some days to wait until my next parts package arrived: I took that time to amuse myself painting.

To paint the sophisticated man, I printed him out and cut around the contour. I simply drew him on and filled in the rest. 

The "Reginald" lettering was painstaking to be modest. First I taped the side panel with painter's tape and printed off "Reginald" in fancy lettering. I cut the word out and taped that on top of the tape of the side panel. At that point I took an razor and slowly cut around the letters, and peeling the tape off underneath. It took me about 3 hours to do this! Then I painted it blue and peeled the tape for the letters off, leaving the white text.

The pure white camera was a bit boring, so I taped it off and painted part of it blue. 

Step 18: Carefully Mounting the Mechanics

Once I got my package from Servocity, I started constructing the Mechanics.

About the Tilt Brackets:

Servocity has this great tilt bracket kit; I'm using these to mount the turrets and the camera onto. The panning motion is achieved with a single servo. The panning servo mounts to the bottom panel and uses a shaft adapter to hold the 3/8" diameter shaft. I mounted 2 48 tooth sprockets to the shaft. The end of the shaft interfaces with the ball bearing on the top panel. Two small 1" copper tubes also run through the side bearings where I mounted a 20 tooth sprocket on each. The tilt brackets interface with a 3/8" copper tubing via a hub that clamps onto the tilt bracket.

I choose the copper tubing so that way I can pass wires through it to reach the Arduino underneath. This neatens Reginald.

Other hardware to mount:

A chain then wraps around the middle to the side post, where the servo can effortlessly pan the brackets around. 

After this, I mounted the Arduino and all onto the bottom panel with Nylon spacers and bolts.

I picked up some nice caster wheels from Tractor Supply Company (13th picture). These sit at the end of Reginald. Mounting these was a trivial task.

Step 19: Mounting the Flashlight and the Camera

Now that the Tilt Brackets have been installed, it's time to mount the Camera and Flashlight.

There are convenient holes located in the Tilt Brackets. I took a hose clamp and tightened it around the Flashlight with a zip tie looped through it. The zip tie then passed through the holes in the bracket. 

The Camera only needed to be bolted onto the bracket. 

In the last step, I mentioned that I was utilizing copper tubes for the Tilt Brackets to grasp onto so that way the wiring could pass through. In the second picture, you can see that I am running the wires (Ethernet cable, power to Camera, Servo wires and Flashlight wires) through to the underneath. Why have I done this? It cleans Reginald up quite a bit by tucking the wires in, and it doesn't allow the wires to interfere with the mechanical operation as easily.

I had to splice the Ethernet Cable and the Servo wire so i could fit it through the copper tube because the connectors wouldn't fit. After I cut the wire, the wire itself could fit through and I would solder them back together.

Step 20: Mounting the Turrets Onto the Tilt Bracket

I wanted a nice way to interface the turret to the Tilt Bracket on Reginald. Shown is a fairly good way to accomplish this. 

Mount the Turrets:

Start by unscrewing the halves of the body that holds the firing mechanism. The two halves are not equal.  The right side contains all the guts of the firing mechanism and the left is an empty shell. 

We will mount the Turrets onto the Tilt Bracket by drilling holes in the turret and leaving well placed nuts. Drilling through the tilt platform, we will insert to bolts to interface with the nuts. I drilled the holes on one of the halves, I had to do this because there isn't enough room on the platform to fit both turrets drilled in the center.

Basically, to mount a Turret on the left side of the Tilt Bracket, you will need to drill holes in the right half of the turret (the one with all the guts); for the right side of the Tilt Bracket, drill holes in the left half. If this doesn't make sense, see the 1st picture for a graphical representation.

View the pictures of the process of how I interfaced the turrets to the tilt bracket plate.

Helpful Notes:

Keep in mind that these bolts are epoxied in, so resist the temptation to tighten the bolts! Only finger tight on the screwdriver is adequate. Remember that these Turrets won't be undergoing a tremendous amount of stress, so tight bolts are unnecessary and you'll be putting yourself at risk of breaking the nut loose from the turret. This actually wouldn't be the worst thing to happen since the turret will still be mounted tight, but you'll likely never be able to remove the Turret if you wanted to (at least not easily).

Step 21: Creating a Battery Housing

To house the battery, I was looking for a simple method. Using 10 bolts, 27 nuts and two metal plates with holes in them, I was able to create a cage to enclose the battery.

The dimensions of the battery are 134mm x 41mm x 31mm. Using these dimensions, I drilled appropriately placed holes to run the bolts through that will hold the metal plates.

One of the bolts only has a wing nut attached for easy removal of the bolt to insert and remove the battery. 

Step 22: Using DD-WRT to Create a Wireless Bridge

This was, by far, the most challenging portion of the project; yet it is what makes Reginald so unique.

What is a Wireless Bridge?

A Wireless Bridge is a device used to extend a Home Network, and provides an internet connection to devices connected to it. If you have an old computer that needs a wired connection, yet is too far away from the Modem/Access Point (AP), a Wireless Bridge can be configured for the old computer to plug directly into. The Wireless Bridge then serves the computer an internet connection from the AP. There is another device that is close to the Wireless Bridge, which is called a Repeater. Both of these are wireless from the Modem/AP in a home; but there are a couple key differences. A Repeater acts as an AP to other devices. A device can wirelessly connect to a Repeater. However, devices on a Repeater have a different subnet than other devices. This essentially means that a device connected to the repeater cannot come into contact with any other devices connected to the Primary AP. Devices connected to a Wireless Bridge will however, be on the same subnet as all the other devices in the home, but the connection needs to be wired.

With Reginald, a Wireless Bridge is used. You can buy a Wireless Bridge and make it easy on yourself; but if you'd like a little more of a challenge and have an old router lying around, give the free firmware: DD-WRT a try.

What is DD-WRT?

DD-WRT is a Linux based firmware that can be flashed to routers. It's an incredibly powerful OS that is also highly configurable. If you have a router lying around, check to see if it can be supported with this firmware here:

http://www.dd-wrt.com/site/support/router-database

Assuming that your Router is supported: congratulations! You now have much reading to do! I wish I was joking: but much research is required before flashing the DD-WRT firmware to your router. Little or no research will put you at great risk of bricking your router and rendering it useless.

Be SURE to read the Peacock Thread:

http://www.dd-wrt.com/phpBB2/viewtopic.php?t=51486

Some Notes on Flashing DD-WRT to your Router:

After finding your Router in the database (be mindful of version numbers), find the wiki associated with that model (when you find the Router within the Router Database, there will very likely be a link for a wiki unique to that Router). Usually every Router has its own set of unique instructions. Therefore, I can't give a tutorial on flashing DD-WRT, I can only provide links for your research. Don't worry though, if you read the wiki and the Peacock thread, you will be instructed exactly what to do.

When the Router has been flashed with DD-WRT, leave the router powered and connect to the Router from your computer. Use your favorite browser and type in 192.168.1.1 to access the Router's configuration page.

When you are able to connect, you will do some configuration to setup the router as a Wireless Bridge.

Perform the Following:
  1. Log into the router, DD-WRT defaults to "root" as the username and "admin" for the password".
  2. Choose "Wireless" and "Basic Settings".
  3. For "Wireless Mode" choose "Client Bridge".
  4. Apply.
  5. Choose the Network Mode of the AP of the home, which usually can be found on your Primary Home Router's webpage.
  6. Enter the SSID, this is the name of your network.
  7. Apply the settings.
  8. Choose "Wireless Security".
  9. Conform these settings to match those of your Primary Home Router.
  10. Go to the "Network Setup" by choosing "Setup" and "Basic Setup".
  11. Make the "Local IP Address" the IP Address of the Wireless Bridge. For example, if your Home AP's internal IP Address is 192.168.1.1, choose an IP Address for your Wireless Bridge that's the same except for the last number. e.g.: 192.168.1.2
  12. "Subnet Mask" is 255.255.255.0
  13. "Gateway" and "Local DNS" are the IP Addresses of the Home AP.
  14. Choose "Status" and "Wireless".
  15. Click on "Site Survey".
  16. Find the Home Network on the list and select to Join that network.
  17. Apply your settings.
Connect your computer to the Wireless Bridge via Ethernet Cable if it's not already (It should be seeing how you configured all those settings). You should have an internet connection now. You may have to power cycle the router first. 

If you have AT&T as an ISP, you may not be successful. Read the next step for AT&T users.

Step 23: Configuring a Wireless Bridge With DD-WRT When You Have AT&T

(Only applies if you have AT&T as a ISP; OR if your Home Router only allows devices on the LAN that use a DHCP handshake)

Why am I making a separate step just for AT&T?

The reason why I'm picking on AT&T is that the 2WIRE Modem/AP that I currently use will only allow devices to connect to it if the device offers a DHCP handshake. I should mention, that my personal Modem/AP is outdated, I encourage anyone who has a recent Modem/AP from AT&T to leave a comment for theirs. As in, provide whether or not the Modem/AP requires devices to have DHCP to connect to it. 

I believe most other ISPs will allow for you to use a 3rd party router to connect to the Modem.

AT&T is a great service for those who don't know how to network because it's easy to setup when the Router, Modem and the ISP are from the same company. From a technical standpoint, it can be more of a challenge to perform advanced tasks, such as setting up a Wireless Bridge. The reason why a Wireless Bridge will not be able to receive internet even when you configured it correctly is because the Wireless Bridge is attempting to connect with a Static IP Address.

How to configure your Wireless Bridge if your Primary Router is from AT&T:

To get the Wireless Bridge with DD-WRT to connect to your AT&T Modem/AP, you will need to follow the default steps on the previous page, and then enable a DHCP handshake on the Wireless Bridge so the Modem/AP will allow it to connect. However there is no way to accomplish this through the GUI, you will need to create a custom startup script for the Wireless Bridge.

Within the DD-WRT interface, choose "Administration" and then "Commands". In the command text box, copy and paste the following:

udhcpc -i br0 -p /var/run/udhcpc.pid -s /tmp/udhcpc -H test-wrt-wireless
hostname `nslookup \`ifconfig br0 | grep 'inet addr' |cut -f 2 -d ':'\` | grep 'Name:' | awk '{print $2;}' | cut -f 1 -d '.'`
if test `hostname` != `nvram get wan_hostname`; then
     nvram set wan_hostname=`hostname`;
     nvram set router_name=`hostname`;
     nvram commit;
fi

Select to "Save Startup". Give the Wireless Bridge a moment or two to save everything. 

Disconnect the Wireless Bridge from power, wait for a few seconds and power it back on. The Wireless Bridge should utilize the Startup script you wrote to it to acquire an IP Address on the Home Network via DHCP. 

This should be what it takes to connect your Wireless Bridge with DD-WRT onto the home network.

Configuring the Arduino to the AT&T Home Network:

The Wireless Bridge isn't the only device that needs to be configured with DHCP to run on the LAN. The Arduino and Camera will need to be adjusted as well.

The code used for the Arduino uses a Static IP Address, so the LAN probably won't accept your Arduino if you use AT&T. To get communication open to the Arduino over the internet, you will need to initialize it with DHCP. 

Grab the code from this page: http://arduino.cc/en/Tutorial/DhcpAddressPrinter

And upload it to your board. Connect it via Ethernet directly to the Home Router and power the Arduino. The AT&T Modem/AP should recognize the Arduino and create an instance of it within the LAN. From there, you should be able to load the original Reginald code back to the board.

Check the configuration page of your Home Router through your favorite browser. You'll probably see a new device on the network. If you loaded the Reginald code back on the board, it may or may not show it is connected. The name of the device won't be "Arduino", but the name will probably have some variation of "wiznet". 

Configuring the Camera:

For the Camera, you may or may not have to do the same thing as the Arduino. First check your configuration page of the Home Router to see if your Camera is discovered if you plug it directly into the Home Router. If not, you will have to set it to use DHCP for the Home Router to initialize it into the LAN, then you could probably switch it back to a Static IP at that point. Regardless, it should have its own port.

Setting everything up:

Connect the Camera and Arduino to the Wireless Bridge. Port Forwarding is next, if everything was configured correctly, you should be close to done.

Step 24: Port Forward Your Home AP to Allow UDP and TCP Exceptions

To allow communication to Reginald from anywhere in the world, you will need a method to pass through the Firewall of your home to reach Reginald. The Firewall by default won't allow your packets to reach the Arduino, and it won't allow the Camera to serve its interface to you.To reach the Camera and the Arduino on Reginald, you will need to create a small hole in your Firewall with Port Forwarding.

To accomplish Port Forwarding, you will need to acquire the following information:
  • The external IP address of the Primary Home Router (if you just Google: "What's my IP?", Google will tell you).
  • The Port Numbers on the Camera and on the Arduino
    • If you didn't change the code given to you by me, the Port Number on the Arduino will be 8888
    • The Port Number for the Camera should be somewhere in the Camera's interface; if this is 80, then it will probably be a good idea to change it.
  • The IP Addresses of the Camera and the Arduino
  • The internal IP address of the Primary Home Router (you entered it in when configuring the Client Bridge)
How to Port Forward your Primary Router:

Now, open your favorite browser (Chrome for me), and enter the internal IP address of your Primary Home Router. 

Here's a bit of a tricky part, since there's hundreds of different Routers in the world, there isn't a "one size fits all" tutorial for this. You could visit http://portforward.com/ which is incredibly comprehensive. If you choose your Router on this site, it will eventually ask you for which game would you like to Port Forward for. Just pick one of them since they are all the same for the most part. The important thing is to know the path within the Home Router's interface to follow to reach the Port Forwarding options.

I will try to speak generically here: when you have reached the page where you are provided with Port Forwarding options, you will probably need to "Add" an exception, or service or case etc. When you do this, the common options for adding a Port Forwarding feature are: the name, the protocol type, the starting and ending port, and the IP Address of what is serving the exception. If there are more options, they will probably be left at default or blank.

You will need to create two exceptions, one for the Camera, and one for the Arduino.

For the Camera:
  • Enter a name for the exception
  • Choose "Both" or "TCP" for the protocol type
  • The starting and ending port will both be the Port Number of the Camera
  • The IP Address is the IP Address of the Camera
For the Arduino:
  • Enter a name for the exception
  • Choose "Both" or "UDP" for the protocol type
  • The starting and ending port will both be the Port Number of the Arduino
  • The IP Address is the IP Address of the Arduino
At risk of confusing you: you can have a specific EXTERNAL IP Address for the Arduino and Camera if you like. I don't believe this adds a real advantage, you would still have to perform the Port Forward exceptions. This is what I have done, but it's not necessary.

Plug the Arduino and the Camera into the Wireless Bridge. Power everything. Time to test!

Step 25: Testing the Communication Over the Internet

It's not enough to enter the IP Address of the Primary Home Router and the Port of the Arduino into the GUI Program for Reginald to test. That's because it won't test the firewall, assuming that you are connected to the LAN. It will simply act within the LAN. 

Different ways to set yourself up to test:

If you are able to perform a data tether with your cell phone, this is a good way to test. Turn off the wireless abilities on your computer and setup to data tether. 

Also, if you have friends, you could get one of them to volunteer by handing them the GUI. Try being nice to that friend and export the Processing sketch to an .exe application so all the friend has to do is double click it to run. 

If you don't have friends, you can test it simply from outside the house (at least Reginald will be your friend).

Set up the Hardware:

Have your Arduino and Camera plugged into the Wireless Bridge with everything powered, plug the LED Flashlight into the flashlight pins on the Custom PCB.

Assuming that the DD-WRT empowered Wireless Bridge connects to the WLAN, and that the Port Forwarding exceptions are all set; perform the following to test:
  • While NOT on the LAN of Reginald, using one of the above methods, open up the GUI Client.
  • Enter in the External IP Address of the Home Router into the "Settings" tab. 
  • Enter the correct Port Number of the Arduino.
  • Enter the credentials to Reginald and gain access.
  • Toggle the "Light Switch" on the main page of the GUI
The LED should light. Having a friend perform this or you with a data tether on your phone is ideal because you can troubleshoot the board if it doesn't work. Whereas being outside your own home to test can be rather inconvenient.

If the LED doesn't light, here's some troubleshooting tips:
  • Try plugging the Arduino into the computer with the USB cable, modify the Arduino sketch to add some "Serial.println()" statements to help debug. Use the Serial Monitor through the Arduino IDE to see if the Arduino is receiving the UDP packet. If it is, then something is wrong with your LED circuit.
  • With the Arduino and Camera plugged into the Wireless Bridge, connect your computer to the LAN. Try toggling the "Light Switch" again. You can leave the External IP Address and Port alone. If it does light, then something is wrong with your Port Forwarding exception. If you can get the LED to toggle in this setup, the Home Router can connect just fine to the Wireless Bridge and to the Arduino. From the outside of the LAN however, your Home Router isn't allowing the UDP packet into the LAN. Therefore, your Port Forward exception is the problem.
  • Can you connect to the Camera from outside the LAN? If you can access the Camera but the Arduino won't turn the LED on and off, then the problem is likely the Home Router. When the Home Router receives the UDP packet directed at a port, it probably doesn't know where to send it. Is the Port Forward Exception made for the same port as the Arduino? Maybe, worst case: the Arduino has died.
Assuming you have the right IP Addresses and Ports entered in and everything is powered; if, after troubleshooting:
  • The Arduino does not print any Serial Commands
  • You can't connect to the Camera
  • You can't turn the LED on or off within the LAN
Then the issue is probably the Wireless Bridge. Connect your computer to it via Ethernet cable and make sure the wireless capabilities are off. You probably will not be able to access the Internet. Review the steps regarding the Wireless Bridge, verify your settings. Does your Home Router recognize the Arduino and Camera when plugged into the Wireless Bridge?

Step 26: Conclusions and Future Plans

After completing the Reginald Project, I was very pleased that I completed all my goals that I initially proposed for the project and more. 

I mention in the beginning but it's worth repeating: Reginald the Bot is only an example application for a topic much greater: the ability to control virtually anything, wirelessly from anywhere in the world. A very useful, and powerful method indeed. The UDP is a very under-utilized technology in everyday projects. With the ideas in my project; hopefully it will act as a precursor to many more. In the tutorial: I provide a practical, yet difficult to implement, solution that has now been explored and clarified. 

Of course I am already considering future plans:
  • Upgrade the Uno to a Mega to accommodate plans 
  • Remotely turn Reginald on and off
  • Implement an LED screen to communicate with those at home. The mic in the camera allows me to hear others
  • Upgrade the drivetrain to DC motors
  • Reconstruct the PCB with a more permanent etched PCB 
  • Implement proximity sensors for safety when Reginald is in "Velocity Control"
  • Implement a battery level to report to the user when the battery is low

Thank you for your time in reading my compendium of the Reginald Project. I hope that my ideas may have inspired someone.
Hurricane Lasers Contest

Runner Up in the
Hurricane Lasers Contest