Home | IoT - Connected Objects | Blynk | Blynk + ESP8266: drive a Pan-Tilt PTZ SG90 in WiFi with a smartphone or tablet

Blynk + ESP8266: drive a Pan-Tilt PTZ SG90 in WiFi with a smartphone or tablet

In this tutorial we will learn how to assemble a PTZ mini-kit (Pan-Tilt) based on SG90 servo motor. We will use Blynk to drive the PTZ turret in WiFi. If you have a Blynk account you can go directly to the assembly step. For best performance, it is advisable to install a local Blynk server. Indeed, even if the transfer is very fast, the orders will pass through the servers of blynk.cc. By installing a local server, you will eliminate latency. In addition to better performance, you will no longer be limited in energy.

Prepare a local Blynk server

For this project, you can use your official Blynk account (and use some energy) or install a local Blynk server and enjoy unlimited energy and reduce latencies. Depending on your environment, follow the corresponding tutorial to install and configure your local private server

Assembly of the PTZ SG90 mini kit

PTZ kits are available from €4 in china. If you already have 2 SG90 servos, you can buy only the bare kit for less than 1€ (provided you are patient for the delivery time)! The kit consists of 6 molded plastic parts as well as the necessary screws. Since there is no documentation, I had to do some research on the internet. To avoid this, here is how to assemble the kit step by step.

mini ptz pan tilt kit sg90 parts

Base Assembly (PAN)

We will start by assembling the base. Here are the necessary parts.

mini ptz kit pan tilt sg90 base assembly

Follow the steps below to assemble the base

mini ptz kit pan tilt sg90 Insert the servo motor into the housing

Make sure the servo shaft is on the opposite side to the pivot point of the tilt bracket

mini ptz kit pan tilt sg90 Assemble the second side of the pan support to enclose the servo
mini ptz kit pan tilt sg90 Complete the assembly by screwing the 2 sides together with 2 short screws
mini ptz kit pan tilt sg90 Screw the four-pointed cross with a short screw
Use a short enough screw to fix the base to the servo shaft. An overly long mounting screw can damage the servo and is screwed too far.
mini ptz kit pan tilt sg90 base assembled Finally finish by fixing the base to the cross with four branches by means of 4 mini screws

Tilt Mount Assembly

For the tilt bracket, you will need the following parts. You can replace the 2 short screws with the 2 long screws with spacer and nut. It is stronger, especially when assembling the tilt support on the base (Pan).

mini ptz kit pan tilt sg90 top

Follow the steps below to assemble the tilt bracket

mini ptz kit pan tilt sg90 top Screw the servo to the base. The servo shaft must be opposite the pivot hole
mini ptz kit pan tilt sg90 arbre lateral Insert the servo shaft into a branch in its housing
mini ptz kit pan tilt sg90 fixation arbre lateral Secure with 2 mini screws from the inside

Final assembly

Now you just have to assemble the support of inclination on the base

mini ptz kit pan tilt sg90 montage dessus Insert the servo shaft into the servo shaft housing
mini ptz kit pan tilt sg90 clips axe Insert the bracket onto the pivot

Do not tighten the drive shaft of the tilt bracket yet.

Circuit and code

Before completing the assembly, we will realize the wiring and uploaded the program into the ESP8266. This will allow us to position each servo motor to its original position. Then we can fix them definitively

Equipment used

I suggest you here to pilot the Pan / Tilt mini kit in WiFi. You can use any ESP8266.

esp8266 Wemos D1 mini Wemos D1 Mini
mini kit fpv pan tilt sg90 Mini Kit FPV Pan Tilt with 2 SG90 servo
jumper dupont Jumper Dupont
breadboard Breadboard

Circuit

mini kit pan tilt servo wemos d1 mini wifi blynk

Project Blynk

Start Blynk. If you have a local server, connect to it.

blynk create account local server

Create a new project. Add a slider for the PAN and assign it the virtual pin V0. Change the upper limit to 180 (degrees). Check Send Value on Release Only.

 blynk virtual pin Pan servo

Then a second slider for the Tilt (V1). Change the upper limit to 180 (degrees). Check Send Value on Release Only.

blynk virtual pin tilt servo

Blynk is ready. Activate the project by pressing the arrow in the upper right corner of the screen.

blynk virtual pin tilt servo

Arduino Code

In the previous tutorial we saw how to use a servo motor with an Arduino and control it with a potentiometer. Here, the program is not that different. The position of each servo motor is retrieved on the Blynk server on two virtual pins.

Start the Arduino IDE and create a new sketch, paste the code below, and change the following parameters:

  • SSID of your Wi-Fi network
  • Wi-Fi Network Password
  • The Tokly of the Blynk project received by email
  • Choose the connection mode to the Blynk server among these three possibilities:
    • Sign in to an official account: Blynk.begin (auth, ssid, pass)
    • Login to an account by specifying the server: Blynk.begin (auth, ssid, pass, “blynk-cloud.com”, 8442)
    • Connection to a local Blynk server: Blynk.begin (auth, ssid, pass, IPAddress (xxx, xxx, xxx, xxx), 8442)
  • Check the pin on which each servo is attached. Here Pan is on D5, Tilt is on D6
  • The Pan servo will be driven by the virtual pin V0. The Tilt servo will be driven by the virtual spindle V1

Upload the program

Adjusting the origins

Return to the Blynk application and advance the Tilt slider to 90 (degrees). Make sure the tilt bracket is in the correct position. Complete the assembly is screwing the servo shaft onto the servo shaft.

servo tilt 90 degrees

Check that the base is correctly fixed by positioning it at 0° then 180°

pan servo 180 degree

Piloting the Pan / Tilt Kit with a Joystick from Blynk

Blynk offers a joystick. It’s less precise than the slider, but it’s more fun to use. Pass the project into editing (square in the upper bar) and delete both sliders. Slide the sliders to the top of the screen. You can also go to in the widget page. You will find a Delete button at the bottom of the page.

Add a Joystick. Select V0 and V1 for both pins. Change the maximum values to 180 (degrees). Set the Auto Return option to OFF if you do not want the servos to return to the original position.

pan tilt blynk joystick configuration pan tilt blynk joystick servo sg90

Start the project and have fun! In the next tutorial we will add a camera to the montage. A short video to sum up all that.