Introduction: Wi-Servo: Wi-fi Browser Controlled Servomotors (with Arduino + ESP8266)
This instructable shows how to control some servomotors remotely in a wi-fi network, using an ordinary internet browser (Firefox, for instance). This might be used in several applications: toys, robots, drones, camera pan/tilt, etc.
The motors were attached to an Arduino Uno, which connects the wi-fi network through a ESP-8266 module. The control interface was designed with HTML and jQuery.
Miguel's tutorial (http://allaboutee.com/2015/01/02/esp8266-arduino-led-control-from-webpage/), which shows how to turn LEDs on/off using ESP-8266, served as inspiration for this post.
The technique shown here is used in one of my projects: "Robô da Alegria":
You might found more about this in one of the following links:
Step 1: Electronics
For this project you'll need the following components:
- Arduino Uno (buy)
- ESP8266 (buy)
- Protoshield (for a more compact version) or an ordinary breadboard (buy)
- 10 kohm resistor (x3)
- Some jumper wires
- SG90 servomotor (x2) (buy)
- A computer (for compiling and uploading Arduino code)
You won't need specific tools for the assembly of this project. All the components can be found online on your favourite e-commerce store. The circuit is powered by the USB port (connected to a computer or a ordinary phone charger), but you may also add an external DC power supply or a battery connected to the Arduino power jack.
Step 2: Assembly
Connect all componets according to the schematic. You'll need some jumper wires to connect the ESP-8266 module and the servomotors. You might use a protoshield (for a more compact circuit), an ordinary breadboard, or design you own Arduino shield.
Plug the USB cable to the Arduino Uno board and proceed to the next step.
Step 3: Arduino Code
Install the latest Arduino IDE. In this project servo.h library was used for the control of the servos. In order to avoid conflict between the wi-fi module and computer's USB port during the upload of the code, softserial library was used. No additional library was needed for communication with ESP-8266 module. Please check the baudrate of you ESP8266 and set it properly in the code.
Some servomotors start to jitter and make strange noises when its position is close to the limits (0 and 180 degrees). To avoid that, the angle was limited between 10 and 170 degrees both in the Arduino code and in the control interface (later).
Unfortunatelly, servo.h library and softserial.h library use the same timer of the microcontroller. This might cause jitter in the servos whenever the Arduino communicates with the ESP-8266. To avoid that, the servos are detached from the Arduino after each command. You might also connect the module to the standard serial pins. In this case, remember to disconnect the module before each upload.
Download Arduino code (wi-servo.ino) and replace the XXXXX by your wifi router SSID and YYYYY by router password. Connect the Arduino board to your computer USB port and upload the code.
Step 4: Interface
A html interface was designed for the control of the servomotors. In this example, two servos were used, but more can be added to the Arduino Uno (I tested up to four motors).
A textbox form is used to enter IP address of the ESP module.
Download Wi-servo.html and jquere.js files and save both in the same folder.
Step 5: Usage
When the Arduino is restarted, it will try to connect your wi-fi network automatically. Use the Serial Monitor to check if the connection was successfull, and to obtain which IP was assigned to your ESP-8266 by your router.
Open the html file in an internet browser (Firefox).
Inform the IP address of your ESP-8266 in the textbox and you'll be ready to go. Select the angle desired for each servo using the sliders. The browser will automatically send a request to the Arduino when you release mouse button, and move each servo.
We have a be nice policy.
Please be positive and constructive.
Hi, your project is very interesting, but my servos dont't work fine. I have tryed to change servos, but they didn't work. But my ESP8266 connects to wifi, in fact it responds at my ping. I don't know what is the problem. i hope you help me :)
Are you using SG90 servos? Those low power servos can be powered from Arduino 5V pin. If you use more power servos, I recommend using an external power soucer.
Did you check the connections between the servo and Arduino pins? Please verify if they are connected to the right I/O pins.