Monday, September 4, 2017

Tutorial: Building Your First Drone

Developing Your First Robot


Develop a remote-controlled Drone with a camera feed. Requirement sparks from the need to investigate in small tight places. This is to help inspect specific environments that might prove difficult to reach without causing break and tear. Control is meant to be conducted through a laptop, mobile or tablet.



  • Small flathead screwdriver (small electric testing screw driver will do the trick)
  • Glue Gun


  • Raspberry PI running the Raspbian OS (Follow NOOBs tutorial for setup [1])
  • Mobile Battery Pack
  • 2-Wheel chassis (will be used for prototype purpose but can be switched based on application)
  • L298N board (for a 2 DC motor chassis, might be required to swap out if chassis is changed)
  • USB WiFi adapter
  • Raspberry PI camera (using 5MP standard camera, can be changed in the event of application change)
  • LED (using a 3 color LED)
  • 9v Battery (connector might be useful but unnecessary)
  • Relevant jumper cables to connect it all together
  • 5V Battery Pack (To power the Raspberry PI, if Possible identify one with a 2mA current as it will affect the performance of the PI)


Assembel It

  1. Connect the camera to its designated location on the raspberry pi
  2. LED has 4 connectors, Left to Right:
    1. Red
    2. Green
    3. Blue
    4. Ground
    using 4 female-to-female jumper cable, connect the 4 pins of the LED to the following pins in the same order as above, 3, 5, 7, 9 (where 9 is for ground)
  3. Connect the L298N board: the L298N board is split into 4 sections:
  4. Section on the left to control the left wheel, using 2 male-to-male jumper cable, connect the top slot on the L298N to the positive slot of the left DC wheel (on the chassis) and the bottom slot to the negative slot of the left DC wheel.
  5. Section on the right to control the right wheel, using 2 male-to-male jumper cable, connect the top slot on the L298N to the positive slot of the right DC wheel (on the chassis) and the bottom slot to the negative slot of the right DC wheel.
  6. On the top left slot, there are 4 pins that should be connected to the raspberry pi. The two on the left will control the left wheel, and the 2 on the right will control the right wheel. From Left to Right, connect the Pins in the following order 35, 37, 36, 38.
  7. On the top right side of the L298N board, there are three slot:
    1. using a male-to-male jumper cable, connect the right slot to the positive side of the 9V battery
    2. Using to jumper cables, connect the middle slot to the negative side of the 9V battery using a male-to-male jumper cable and to pin 39 using a male-to-female jumper cable
    3. leave the right left slot empty (you can potentially connect it to Pin 2 of the Raspberry PI but concern is that it will not be capable of providing the PI with a steady current which in turn will impact the stability of the PI.
  8. Connect the USB WiFi adapter to one of the USB slots on the raspberry PI
  9. Using a glue gun, fix everything in place to ensure it stays in place. ensure to fix the camera and the LED in place.

Configuring the Raspberry PI

  1. Run 'sudo apt-get update' and once completes, 'sudo apt-get upgrade' to ensure all dependencies have been applied
  2. using 'sudo apt-get install xxx' to install the following components where 'xxx' will be replaced by the component name:
    • 'hostapd' to enable the raspberry pi to act like a WiFi hotspot
    • 'dhcpd' to allow the pi to issue IP addresses for connectivity
    • 'oracle-java8-jdk' to get the latest Java Development Kit (can be replaced with ‘java’ in case of applying the solution)
    • 'vncserver' to enable remote desktop to Raspberry PI (Useful to run NetBeans, if using command line compiling, unneccesary)
  3. Install RPI Webcam (based on reference3)
  4. setup 'hostapd' and 'dhcpd' based on reference 2
  5. Download the latest "Netbeans" from 'http://' and extract it. it might be useful to create a shortcut on the desktop.



  1. Install Visual Studio. Ensure to select Windows Desktop, .NET Framework 4.5 (or the latest) and Web components
  2. Connect to the Raspberry PI WiFi network you setup, I am using the SID "Drone"
  3. using putty, connect to the raspberry PI and ensure connectivity (I am using IP '')
  4. Run 'vncserver :1' to enable X-Terminal
  5. using VNC client, connect to the PIs X Terminal using ''
  6. Now you can directly configure the PI through the GUI interface or the Command Prompt as required.


Connection to the Drone will be connected through WiFi as it:
  • Helps with the distance that can be covered in contrast to bluetooth and infrared,
  • In addition, with WiFi, we can configure a Wireless LAN that is hosted from the PI which would simplify the development of a TCP/IP application,
  • Tutorials are readily available
  • Both Java and .NET cover it as part of their standard Framework.
  • Messages can be passed between client and server in ASCII format


Writing the Raspberry PI code (Server)


Setup TCP Listener
 Listen: Establish Connection
 Case to received command
  Light: Toggle Light 'On' or 'Off'
  Forward: Move Forward by setting pins 35 and 36 to true for 0.5 Secs
  Backward: Move Backward by Setting pins 37 and 38 to true for 0.25 Secs
  Left: In-Spot turn Left by switching pins 35 and 38 to true for 0.10 secs
  Right: In-Spot turn Right by switching pins 36 and 37 to true for 0.10 secs
  Default: Do nothing
 Terminate Connection
 Goto Listen


Writing the Client Code


MainFrame: Execute Command
 Connect to Server on Listening Port
 Case to selected command
  Light: Send Light Command to Server
  Forward: Send Move Forward to Server
  Backward: Send Move Backward to Server
  Left: Send Turn Left to Server
  Right: Send Turn Right to Server
  Default: Do nothing
 Terminate Connection
 Goto MainFrame


Camera Feed

On Server: Modify main page of web page on PI to only display the webcam picture (continuously refreshed picture). This can be identified by going through the PHP page as downloaded by the RPI webcam solution and clearing everything that is not related to the <div> for the camera shot. Your new PHP file should be reduced to fit in a page or slightly over.
On Client: Using a web control, point the URI to the webcam page on the PI (can test URI using any browser)


After Closure, what was developed was a base product of a remote controlled drone with a camera feed. The idea is to be able to investigate locations that are difficult to reach. Based on the applications (highlighted below), the drone can be customized further to be built for a specific need. The above details the implementation which covers details of the development of the base product. A good step forward might be to try to deploy it as a live solution and omitting out all development steps.


  1. Installing Raspbian with NOOBS (19-Dec-2016)
  2. Setting Up a Raspberry Pi as a WiFi Access Point (19-Dec-2016)
  3. RPI-Webcam-Interface (24-Nov-2016)

No comments:

Post a Comment