loading

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:

https://hackaday.io/project/12873-rob-da-alegria-joy-robot

https://www.facebook.com/robodaalegria/

https://github.com/ferauche/RoboAlegria

Step 1: Electronics

For this project you'll need the following components:

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.

<p>Hi, my serial monitor output is this;</p><p>AT+RST</p><p>OK</p><p>WIFI DISCONNECT</p><p>ets Kan 8 2013,sst cause:2, boot mode:(3,6)</p><p>load 0x40100000,6tail 0</p><p>chksum 0x63</p><p>lo`d 0x3ffe8etail 0</p><p>chkux2tail 0</p><p>Ai-Thinkdr Technologx Co. Ltd.</p><p>ready</p><p>AZ&yen;&uml;&Otilde;=DQŠj</p><p>C!j&yen;L&oslash;WIFI CONOECTED</p><p>AT&yen;&uml;&bull;&copy;P&Otilde;&sup2;&Otilde;*&ordf;&Ecirc;&sup2;&rsquo;&Acirc;&rsquo;bj�&aacute;:&aring;]dyCvd9&quot;</p><p>WHFI DIS&uml;&Ecirc;&Ecirc;&ordf;&Ocirc;(UH&oslash;</p><p>AT+CHFSR</p><p>+CIFSR:STAIP,&quot;193.168.0.48&quot;</p><p>+CIFSR:STAM@C,&quot;5c:cf:7f;8e:</p><p>AZ&yen;&uml;R&Otilde;&ordf;&Otilde;Šj</p><p>C&egrave;j&shy;H&oslash;AT+CIPSERVDR=1,80</p><p>OK</p><p>9 : ( 1&OElig;&atilde;&oelig;&iuml;&ldquo;p&fnof;&OElig;&oacute;&OElig;</p><p>each time it's slightly different. I've tried several baud rates and none seem to work. Does anyone have a solution to this? Also, sometimes I get an IP address from the monitor, in this case 193.168.0.48 but when I use this in the browser the servo does nothing (I'm only using one servo on Pin 9). Thanks!</p>
Do you know if your baudrate is set to 115200kbps? Software serial library doesn't work well at that speed and, even though you can read the messagens, it displays that noises sometimes.<br>If that's the case, maybe you should change the baudrate of your ESP8266 to something slower (9600kbps would be great).<br>
<p>Hi Igor, I believe that's what I have done (I am completely new to the ESP8266). I used the code from a previous comment below:</p><p>&quot;Try this :</p><p>//start serial communication<br>Serial.begin(9600);<br>esp8266.begin(115200);<br>sendData(&quot;AT+CIOBAUD=9600\r\n&quot;, 2000, DEBUG);<br>esp8266.begin(9600); <br>// Remove Reset <br>//sendData(&quot;AT+RST\r\n&quot;, 2000, DEBUG); //reset module&quot;</p><p>and this has fixed the issue. The servo now moves! Thanks for the quick response!</p>
<p>You're welcome!</p>
<p>Some of the serial monitor messages is not understandable:this is mine:</p><p>AT+RST</p><p>OK</p><p>WIFI DISCOONECT</p><p> ets Jan 8 2013,rst cause:2, boot mode:(3,7)</p><p>load 0x40100000,oٹ</p><p>tail 4</p><p>chksum 0x88</p><p>loa&sbquo;&sbquo;&bull;mtail 4</p><p>chkx tail 8cutb IDSi&brvbar;پ&cent;صة&sbquo;</p><p>َn't use rtc mem data</p><p>slڈگoجے</p><p>Ai-Thinkdr Technolog&frac34; Co.,Ltd.</p><p>re`d^CلAT+CWMODQOLCC،C،jھH&uuml;AT+CWJAP=&quot;Mohamlad is awesolest&quot;,&quot;andinovehim100pescentsure&quot;</p><p>AT+CIFSR</p><p>+CIFSR:STAIP,&quot;192.168.43/188&quot;</p><p>+CIFSR:STAMAC,&quot;60:01:94:0KAT+CIPLUX=1</p><p>OK</p><p>AT+CIPSERVES=1,80</p><p>OK</p><p>also the motor doesn't turn properly.it sometimes moves and sometimes doesn't.what is the solution?</p>
My ESP8266 module also display some strange characters sometimes.<br>Regarding the motor, I believe it's a problem regarding the speed of the network. If you send a lot of commands quickly, the ESP8266 might lose some of the packages. So maybe you'd adapt the code, to reduce the number of packages between you computer and the Arduino.<br>Maybe change it so that the motor gives &quot;x&quot; turns on each buttom click, instead of allowing a continuous movement.
<p>The servo doesn't work and I have this massege :</p><p>AT+RST</p><p><br>O C@�&bdquo;I DISCONNECT<br>bB&times;&dagger;P&hellip;&Otilde;&Ecirc;&Eacute;&yen;SN&Ecirc;&Eacute;&yen;SN&Acirc;I�&euml;&quot;B&bdquo;o&bdquo;Ak�&Aacute;&aring;C&uuml;&AElig;&uuml;&euro;&divide;<br>A K+&Euml;k&laquo;&Eacute;�Technology Co.,Ltd.</p><p>ready<br>&agrave;&agrave;&uuml;&agrave;&uuml;&agrave;&uuml;&agrave;&uuml;&agrave;&uuml;&agrave;&agrave;&uuml;&agrave;&uuml;AT+CWMODE=1</p><p><br>OK<br>&uuml;&uuml;bB&Oslash;&dagger;&Ocirc;&hellip;&Ntilde;&Ecirc;&Eacute;&Yacute;J&oelig;&Ecirc;&Yacute;&Yacute;J&oelig;&Acirc;I�&ecirc;O&quot;4qA&circ;B&AElig;&micro;</p><p>what is the problem? , please help </p>
<p>Maybe your ESP8266 module runs on a different baudrate. This might be the reason you are receiving those strange symbols.</p><p>Try to change the baudrate of the serial communication between the Arduino and the ESP8266 on line 42 (esp8266.begin(19200);).</p>
thanks servo is already running. whether we can control via smartphone? I have tried but can not.
<p>It worked on my Android smartphone. I copied the html file + jquery to the phone and opened it using Firefox browser.</p>
I have tried with my smartphone but do not want to walk servo, esp8266 also led her not blinking does not indicate that there is communication between the smartphone and esp8266. do you have a solution?
<p>Did you connect both (your smartphone and the ESP8266) in the same wi-fi network (same wireless router)?</p>
yes I am already connected to the same wifi. but it still can not. whether there are additional applications to run in a smartphone?
<p>Did it work when you opened the html interface on your browser's desktop?Did you copy both the html file an jquery file to the same folder?</p>
html can be opened in firefox my smartphone but for the servo control can not, I have servo move through a browser, but it would not work at all. I also have to put the file html and jquery are in the same folder.
thanks. Sorry I want to ask . ip already out on the serial monitor but why servo can not it work?
<p>So we actually need 3 x 10 kohm resistors (instead of 2 x 1 kohm + 1 x 10 kohm), right? It would be helpful for newbie if you maintain consistency between the component list &amp; diagram</p>
<p>I agree on you that the consistency between the diagram and the component list is important. So I revised the list from 2 x 1kohm + 1 x 10kohm to 3 x 10kohm resistors.</p><p>Those 1 kohm resistors where used in a voltage divider, to reduce Arduino's TX voltage. So we might use almost any two resistors with the same value in this voltage divider.</p>
Thanks. I just tried it but couldn't make it work. The esp8266 couldn't connect to wifi (debugged through serial monitor). Its led is constantly red. Is because I only use arduino uno USB as power?<br>
<p>My ESP8266 module has two LEDs: a red one for power indication (always on) and a blue one for communication stutus (turns on when the module is receiving or transmitting data). If your module is the same, did you verify if this blue LED blinks? What does the serial monitor display when you reset your Arduino?</p>
<p>I just noticed that mine has 2 LEDs too. But besides the red one, the blue one only blinks 2-3 times whenever I reset my arduino then it stays off. These are the only messages shown in my serial monitor:</p><p>AT+RST</p><p>&eacute;J&thorn;&yuml;AT+CWMODE=1</p><p>I&Eacute;&Ocirc;&yuml;&yuml;AT+CWJAP=&quot;ssid&quot;,&quot;password&quot;</p><p>I&Eacute;R&ograve;&ucirc;&ocirc;&ugrave;&uacute;&yacute;”&yuml;&eacute;&Ocirc;&yuml;</p>
<p>Ups, wait, I got those messages only after I add &quot;Serial.print(command);&quot; inside &quot;sendData&quot; function. Otherwise I only got these strange characters:</p><p>&eacute;K&yacute;&yuml;&ograve;&Ocirc;&yuml;I&Eacute;J&eacute;&uacute;&ugrave;&ugrave;&uacute;&yuml;&yacute;&eacute;&Ocirc;&yuml;</p>
<p>Maybe it's because your ESP8266 works at a different baudrate than that configured in Arduino. The baudrate configured in the code was 19200. Sometimes the ESP8266 comes at 115200.</p><p>Try changing the baudrate (from &quot;esp8266.begin(19200);&quot; to &quot;esp8266.begin(115200);&quot;, for instance) and check if those strange characters change to something understandable.</p><p>Regarding the blue LED, it's blinking three times because the Arduino is sending three commands: reset, set station mode and connect your wi-fi router. If the baudrate is actually wrong, the ESP8266 is receiving something data, but isn't able to understand it.</p>
<p>It still shows strange characters when I uses &quot;esp8266.begin(115200);&quot;:</p><p>&aacute;&micro;–‡#&ETH;&quot;Ri#&oslash;&aacute;&yen;&Otilde;|5&quot;&Aacute;&iquest;V&Oslash;Ri&Ouml;*k&aacute;&yen;&Otilde;|)0\&Aring;&oacute;}&Icirc;&ntilde;Ÿ&oacute;%</p><p>&yuml;xW&ugrave;^}&ugrave;L&Ocirc;&quot;</p><p>&ordf;”&yen;&Aring;</p><p>Is there any other possible baud rate? Or is there any way to check if my esp8266 is defective? Thanks for your help</p>
<p>Other usual baudrates are 9600 and 57600. Maybe you could try them.</p>
<p>Thanks. It works fine.</p><p>I try this &quot;curl http://ip/?sr1=80&quot; and the data is received but there is no ACK '?) and the command never ends. </p>
<p>Try this : </p><p>//start serial communication<br> Serial.begin(9600);<br>esp8266.begin(115200);<br> sendData(&quot;AT+CIOBAUD=9600\r\n&quot;, 2000, DEBUG);<br>esp8266.begin(9600); <br>// Remove Reset <br> //sendData(&quot;AT+RST\r\n&quot;, 2000, DEBUG); //reset module</p>

About This Instructable

9,946views

75favorites

License:

More by IgorF2:Solar Charged Battery Powered Arduino Uno Wi-fi controlled FPV rover robot (with Arduino, ESP8266 and stepper motors) Controlling LED matrix array with Arduino Uno (Arduino powered robot face) 
Add instructable to: