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
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|
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
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|
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.
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
* 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)
* - 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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
// Vos paramètres de connexion WiFi - Your WiFi credentials.
char ssid = "yourSSID";
char pass = "yourPASSWORD";
// Jeton Blynk - Blynk Token
char auth = "yourTOKEN";
Serial.print("move Pan to ");
Serial.print("move Tilt to ");
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);
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.
- Recycle a remote-controlled car (RC car) with an ESP8266, Shield Motor Wemos d1 mini and Blynk
- Connecting an ESP8266 to Blynk on WiFi with Johnny-Five (Firmata WiFi)
- IoT development based on Orange Pi, Arduino (Firmata), Nodejs, Blynk and Johnny-Five
- Blynk + Node.js + Johnny-Five: drive a Pan-Tilt PTZ SG90 kit on Orange Pi with an Arduino / Firmata
- Blynk + ESP8266: drive a Pan-Tilt PTZ SG90 in WiFi with a smartphone or tablet
- Integrate Blynk IoT connected objects to iOS with Homebridge (HomeKit)