Warning: file_put_contents(/home/clients/81b51a55b78a35c5c4c50dd82cac1015/diyprojects/wp-content/uploads/wpo/images/wpo_logo_small.png.webp): failed to open stream: Disk quota exceeded in /home/clients/81b51a55b78a35c5c4c50dd82cac1015/diyprojects/wp-content/plugins/wp-optimize/vendor/rosell-dk/webp-convert/src/Convert/Converters/Gd.php on line 428
Blynk + ESP8266: drive a Pan-Tilt PTZ SG90 in WiFi with a smartphone or tablet • DIY Projects
DIY Projects

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

19 servo tilt 90 degrees

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.

Base Assembly (PAN)

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

Follow the steps below to assemble the base

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

Assemble the second side of the pan support to enclose the servo
Complete the assembly by screwing the 2 sides together with 2 short screws
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.
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).

Follow the steps below to assemble the tilt bracket

Screw the servo to the base. The servo shaft must be opposite the pivot hole
Insert the servo shaft into a branch in its housing
Secure with 2 mini screws from the inside

Final assembly

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

Insert the servo shaft into the servo shaft housing
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.

Wemos D1 Mini
Mini Kit FPV Pan Tilt with 2 SG90 servo
Jumper Dupont


Project Blynk

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

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.

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

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

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:

Upload the program

 * Mini Kit Pan/Tilt SG90 + Wemos + Blynk
 * - Use private or official Blynk server
 * - Use Blynk Joystik widget to drive Pan/Tilt kit 
 * - Use a WiFi connexion 
 * - Use 2 sliders or 1 joystick : Pan (V0: 0..180), Tilt (V1: 0...180)
 * How to 
 * - Install Private Blynk server on Raspbery PI
 * - Install private Blynk server on Orange Pi (Armbian) 
 * *******************
 * - Utilisez un serveur local pour une meilleure performance 
 * - Utiliser le widget joystick pour piloter le kit Pan/Tilt
 * - Utiliser la connexion WiFi 
 * - Utiliser 2 sliders ou un joystick : Pan (V0: 0..180), Tilt (V1: 0...180)
 * Tutoriels
 * - Comment installer un serveur Blynk local sur Raspberry Pi : http://www.projetsdiy.fr/blynk-installer-serveur-local-prive-raspberry-pi3-energie-illimitee/
 * - Installer un serveur local sur Orange Pi (Armbian) : http://www.projetsdiy.fr/blynk-installer-serveur-local-prive-orange-pi-armbian-ubuntu-16-04lts/
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * Licence : MIT
 * Copyright (C) 2017 : www.projetsdiy.fr and www.diyprojects.io

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

// Vos paramètres de connexion WiFi - Your WiFi credentials.
char ssid[] = "yourSSID";
char pass[] = "yourPASSWORD";

// Jeton Blynk - Blynk Token
char auth[] = "yourTOKEN";

Servo pan;
Servo tilt;

  Serial.print("move Pan to ");

  Serial.print("move Tilt to ");

void setup()
  Serial.begin(115200); // See the connection status in Serial Monitor
<span class="hljs-built_in">  //Blynk</span>.<span class="hljs-built_in">begin</span>(auth, ssid, pass); <span class="hljs-comment">// You can also specify server:</span> 
<span class="hljs-comment">  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);</span>
  Blynk.begin(auth, ssid, pass, IPAddress(xxx,xxx,xxx,xxx), 8442);

void loop()

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.

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

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.

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.

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version