Cayenne IoT + ESP8266: driving a mini kit Pan-Tilt FPV SG90 in WiFi with a smartphone or tablet

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp
Table of Contents
drapeau france
level advanced

In this new tutorial on Cayenne IoT, we will learn how to control an articulated Pan-Tilt PTZ SG90 system in WiFi. In the previous tutorial, we saw how to do with the Blynk library and application. Cayenne IoT is fairly similar. It is necessary to pass through the servers of which can cause a small delay of latency (quality of Internet connection, server load …).

What do you need ?

Unlike Blynk, Cayenne IoT does not offer (yet?) Local server. It is therefore necessary to have a user account. You can create one directly from or from the iOS or Android app.

If you have purchased a Pan-Tilt PTZ SG90 kit, follow the previous tutorial for installation.

Equipment used

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

esp8266 Wemos D1 miniWemos D1 Mini
chargeur raspbery pi 3 5v 3000ma5/3A micro-usb power supply
mini kit fpv pan tilt sg90Mini Kit FPV Pan Tilt with SG90 servos
jumper dupontJumper Dupont


The circuit is exactly the same as the Blynk version.

mini kit pan tilt servo wemos d1 mini wifi cayenne iot mydevices

Preparing the Device

First, we need to add a Device. Unlike Blynk, Cayenne needs to be connected to the object at any time during setup.

Cayenne proposes to create a Device of type Raspberry or Arduino. This is not a problem, the ESP8266 is very well managed even if it is not in the list.

cayenne mydevices add device raspberry arduino

You can retrieve by email a small code example for Arduino

 cayenne mydevices add arduino device

Select Arduino Uno then WiFi Shield. A Token is generated. From now on, Cayenne is waiting for the Arduino (or the ESP8266 in this case) to connect to the servers before continuing. It is a little frustrating, but it is the current mode of operation.

cayenne mydevices esp8266 wemos d1 mini nodemcu

Prepare the Arduino IDE

Launch the Arduino IDE and open the library manager. In the search field, search the keyword Cayenne. Install the Cayenne library by myDevices. Also install the servo library.

ide arduino install cayenne mydevices library

Arduino Code

Paste the Device Token into the following code and change the connection settings (ssid, password) to your WiFi network. Upload the code and open the serial monitor to make sure everything is going well.

 * Mini Kit Pan/Tilt SG90 + Wemos + Cayenne IoT (
 * 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 <>.
 * Licence : MIT
 * Copyright (C) 2017 : and

#define CAYENNE_PRINT Serial
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
#include <Servo.h>

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

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "yourTOKEN";

Servo pan;
Servo tilt;

  Serial.print("move Pan to ");
  double currentValue = getValue.asInt();
  int position = currentValue ;

  Serial.print("move Tilt to ");
  double currentValue = getValue.asInt();
  int position = currentValue ;

void setup()
  Serial.begin(115200); // See the connection status in Serial Monitor
  Cayenne.begin(token, ssid, pass);

void loop()

Configuring Axis Commands on the Cayenne App

Go back to the Cayenne application. As soon as the ESP8266 has authenticated itself to Cayenne servers, the application will automatically switch to the next screen.

 cayenne iot mydevices authenticate

Click ADD at the center of the screen to add the axis commands. Unlike Blynk, there is no joystick widget. It will be necessary to settle for 2 sliders (which is not really a problem, it is not so simple to control the axes precisely with the joystick: -?). Add a Motor Device.

cayenne mydevices add motor

Then Servo Motor

cayenne mydevices servo motor

Configure it like this

  • Name: Pan or Tilt
  • I/O: Virtual
  • Pin: V0 for Pan, V1 for Tilt (for example)
  • Widget: slider
  • Activate min / max and set 0..180 (degrees)
  • Finish by Save

Do the same for the 2nd axis.

cayenne mydevices pan virtual v0

Here’s what we get

cayenne mydevices sliders pan tilt

Since Cayenne only accepts configuring Devices when connected to the Arduino / ESP8266, the axis control is immediately functional.

If you lose connection to your device, this is the type of message that will appear at the top of the screen

cayenne mydevices device offline

With a small video, it’s simpler 馃槈

On the video, you will notice a slight delay between the movement of a slider and the execution of the command by the ESP8266. Cayenne is a recent project which still presents defects of youth but it will be forgiven quite easily because it is proposed totally free (until when?).

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

Thanks聽for your reading

Did you like this project ? Don't miss any more projects by subscribing to our weekly newsletter!

Are you having a problem with this topic?

Maybe someone has already found the solution, visit the forum before asking your question
We will be happy to hear your thoughts

      Leave a Reply

      Read more
      Recent posts on the Forum
      DIY Projects
      DIY Projects