![](https://static.wixstatic.com/media/b31662_fb2a600df37c4568a6df31f5806d5601~mv2.jpg/v1/fill/w_980,h_551,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/b31662_fb2a600df37c4568a6df31f5806d5601~mv2.jpg)
In this tutorial to create a project where you control a servo motor angle from 0 to 180 degrees using a web interface with an image that rotates based on mouse clicks, you’ll use WebSocket communication to send angle coordinates to the ESP32, which will then adjust the servo motor accordingly. Below is a detailed guide to help you build this project.
Components Required
ESP32 Development Board
Servo Motor SG90
Power Supply (e.g., 5V battery or external power adapter)
Breadboard and Jumper Wires
Circuit Diagram
![](https://static.wixstatic.com/media/b31662_2c76d78b402f4bdeb2bb2da2d336399a~mv2.png/v1/fill/w_885,h_702,al_c,q_90,enc_auto/b31662_2c76d78b402f4bdeb2bb2da2d336399a~mv2.png)
![](https://static.wixstatic.com/media/b31662_6993dd0ebd54477f8f55460bbce9e7e0~mv2.jpg/v1/fill/w_980,h_653,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/b31662_6993dd0ebd54477f8f55460bbce9e7e0~mv2.jpg)
Setup Arduino IDE for ESP32
Install the ESP32 Board Package:
Open Arduino IDE.
Go to File > Preferences.
Add the following URL to the "Additional Board Manager URLs" field: https://dl.espressif.com/dl/package_esp32_index.json.
Go to Tools > Board > Boards Manager, search for ESP32, and install it.
![](https://static.wixstatic.com/media/b31662_13c367b1d9704679b6506b6c4b7e4fe6~mv2.jpg/v1/fill/w_980,h_653,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/b31662_13c367b1d9704679b6506b6c4b7e4fe6~mv2.jpg)
2. Connect the Servo Motor
Wiring:
Connect the servo’s power (red) and ground (black/brown) wires to the 5V and GND pins on the ESP32.
Connect the signal (yellow/orange) wire to a PWM-capable GPIO pin on the ESP32 (e.g., GPIO 19).
Power Consideration:
Ensure the servo is adequately powered. Use an external power supply if the servo requires more current than the ESP32 can provide.
3. Install Required Libraries
Install Servo Library:
Open Arduino IDE, go to Sketch -> Include Library -> Manage Libraries, search for Servo, and install it.
Install WebSocket Library:
After installed the libraries, restart your Arduino IDE.
4. Write the ESP32 Code
Here’s the code to handle WebSocket communication and control the servo:
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
AsyncWebServer server(80);
#include <ESP32Servo.h>
#include <WiFi.h>
#include <WebSocketsServer.h>
#include "index.h"
#define SERVO_PIN 19
Servo servo;
const char* ssid = "TPLink";
const char* password = "95001121379884265554";
WebSocketsServer webSocket = WebSocketsServer(81);
void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Serial.printf("[%u] Disconnected!\n", num);
break;
case WStype_CONNECTED:
{
IPAddress ip = webSocket.remoteIP(num);
Serial.printf("[%u] Connected from %d.%d.%d.%d\n", num, ip[0], ip[1], ip[2], ip[3]);
}
break;
case WStype_TEXT:
//Serial.printf("[%u] Received text: %s\n", num, payload);
String angle = String((char*)payload);
int angle_value = angle.toInt();
Serial.println(angle_value);
servo.write(angle_value);
break;
}
}
void setup() {
Serial.begin(9600);
servo.attach(SERVO_PIN); // attaches the servo on ESP32 pin
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.printf("WiFi Failed!\n");
return;
}
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Initialize WebSocket server
webSocket.begin();
webSocket.onEvent(webSocketEvent);
// Serve a basic HTML page with JavaScript to create the WebSocket connection
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
Serial.println("Web Server: received a web page request");
String html = HTML_CONTENT; // Use the HTML content from the index.h file
request->send(200, "text/html", html);
});
server.begin();
}
void loop() {
webSocket.loop();
}
![](https://static.wixstatic.com/media/b31662_f695d50e212645d9ad8c6ae0f5ce65cd~mv2.jpg/v1/fill/w_980,h_509,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/b31662_f695d50e212645d9ad8c6ae0f5ce65cd~mv2.jpg)
5. Create the Web Interface
Here’s the HTML for the web interface and Base64 for image data url. This will send the angle coordinates to the ESP32 when you click on the image:
Base 64
https://www.base64-image.de/ to convert the Image to Base64 online and use the result string as data URI, img src, CSS background-url, and others. Sometimes you have to send or output an image within a text document (for example, HTML, CSS, JSON, XML), but you cannot do this because binary characters will damage the syntax of the text document. To prevent this, for example, you can encode image to Base64 and embed it using the data URI.
The Allowed image types are JPG, PNG, GIF, WebP, BMP and SVG and allowed image 1mb size.
To embed a Base64-encoded image in HTML, use the data URI scheme in the src attribute of the <img> tag. Here's an example:
<!DOCTYPE html>
<html>
<head>
<title>Base64 Image Example</title>
</head>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgAAAAASUVORK5CYII=" alt="Base64 Image">
</body>
</html>
.
Here the index.h file
const char *HTML_CONTENT = R"=====(
<!DOCTYPE html>
<html>
<head>
<title>ESP32 Websocket Controlled Servo Motor</title>
<meta name="viewport" content="width=device-width, initial-scale=0.7">
<style>
body { text-align: center; }
canvas { background-color: #ffffff; }
</style>
<script>
var canvas_width = 401, canvas_height = 466;
var pivot_x = 200, pivot_y = 200;
var bracket_radius = 160, bracket_angle = 0;
var bracket_img = new Image();
var click_state = 0;
var last_angle = 0;
var mouse_xyra = {x:0, y:0, r:0.0, a:0.0};
var ws;
bracket_img.src = " data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZEAAAGRCAMAAACT/35lAAAC2VBMVEUAAAD///8bGBj////28vL///8iHR7MzMwfHB3+/v7BwcHr6+va2tr////h4eEdGRkiICDj4+Pw8PAXFBUdGhseGxzY2NjJycnf398hHR4sKSrFv78gHB0nJCVFQkS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AAAABJRU5ErkJggg==";
function init()
{
var servo = document.getElementById("servo");
servo.width = canvas_width;
servo.height = canvas_height;
servo.style.backgroundImage = "url(' data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA0QAAAPLCAMAAABIIbkRAAABX1BMVEX///8hHyAqU1knUVUjHyEqUlQeHh4kTlAsT1IkUVchGx0lUlIrVFYsUVgqTlYVGhsbFhkxT1IfT1MsVVk2VlgvWFsXFRYdGhsvUFYkVVUxVFgcISElVlomTVUxS08nHyExMTEoS0wrQ0MtRUkYIycjLjEfSEopNzgPGBglJSUSHiN7e3sePEBifYAjSU8ZJiYhQ0YmGxuDlZkqWFscNTkTHx/2+PglRkgiS0ssUEwaQUMvTEc1SUgxXF9TbXAMDQ19kZSBm50SPD+LnqSntbZAXmLw8/MpSlFqgobr7u7N1dYaRkdYdHcpOT4vHSA4V1/h5+g4T1UrKStNaGxJYmYbGyHc4eI9WVu5xcc4EBE9PT3U3N1ZWVkpMzG3t7ctGhfBy81gc3d2iYt1j5JKTEyxvr9oen5lRkcvCQSWpqpmZWR5lp1QOjqbr7SBX12rra1uU1GQkZF/gYJxcG9ehZDBGHQIAAAvOElEQVR42uzBgQAAAACAoP2pF6kCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGD27e+1aSgM4/jhvIS3JekgSQ+oeIT541zFw8GMthYr2rl1nYVVJnPgzeZUGOKN//+FrWZeKLOnSdaIPJ/CYBvLsouHb9K1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUJPe6fk7t7MzMMZwoEZRIbjG0eJ7w5nw8PJpxml63fGi36jC1SfBKpFSLu75/Yl7TFFh5WHvRAEPBjxwLn5+uS8AVpnOjrv9zJFSShJ7mNjFiJ4LDy+2x0zLYyYJr0YFa9mPCcPhU88RdQ37C37IB+OdrDu7EAB/dzjLXL8VpWlumUOK0l/Ub/LC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fEUmk1qMKI9IuItcQEUVvxxKF9xe4fcUl3mNPJF8RMbkRQ0Q4eIn8m0Q6HXF6vcEVNw0Yk69sXaLVxZyu3hNR5HYs0fS8IblxY7xy44obe0eeca45uyOqzogodluXSCFQF5FriIiit22JiOjCiBQRoXaJfElEtEdElohQu0QieS4mTRUC4v2MKMusUpX7TMTNGyO3sUSJpGkuRERE+IMlSh1zTSFwfqlLRNhjieSaexwpsETf2bubFCeiMArDXblU0rFjSUOL3SLGsbMMHLgC9yC4/22YH0RJcuCrLsykngeyhJcDqXureO0SbTb9qn/ssES8doleNqvVDxFZIib8O9fa6lFEF1Yionpi4WGzaU9PHZaIsRENbb3Xhof+uW36jjN9//boUxuG9fvDw9Zub+sA6uyJaFREi7OIdjsRIaJxS7Q4i6jbiWj2RDRtibrt1qW8uRPR1CUS0eyJaMISHRva7n7eMWsimrxEb0Q0cyKavEQfRDRzIhq9RC+niL4ul8vu4NuvO2ZNRCOXSESIyBIhojpLxBUiGsEScY2IxrBEXCGiESwR14hoDEtE8L8v5YkoRbTYV9TaIaL2T0Tvvtwxa2cRLUQkIqa9Y2H/E5GIsEQnIiKwRFUi4jpLVCYiAktUJSKus0RlIiK4xRLdtyaiC9/v29DauvVtMQxPfyNaimjmLpdIRCLCEh2JiMASVYmIxBIViYjAElWJiMQSFYmIwBJViYgbCEvUt3X7+LnjIqL7YWitnS7liYi8RCISEZboSEQElqhKRCSWqEhEBJaoSkQklqhIRASWqEpEJDdZovWziGJEfz7yJSLSEolIRFiiIxERWKIqEZFYoiIREViiKhGRWKIiERFYoioRETmxUCMiIicWakREYomKRERgiapERGKJikREYImqRERiiYpERGCJqkREYomKRERgiapERGKJikREYImqRERiiYpERGCJqkREYomKRERgiapERGKJikREYImqRERiiYpERGCJqkREYomKRPSbvTtmjSKKwjA84+6GZSdZAkLUam3VysZ2OwuLgBYWQbRJJf7/2jG7FgnnwMlekuY+z/yGl2+4MHNJWKIqEZGxREUiImGJqkRExhIViYiEJaoSERlLVCQi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hdcKxuR+EeOYjgu83RO3AO07/93KCXFuBdFDx95i2zFCClmcnOeNZvjIO4lia/hL3ztUM7O+bFzXObEAv6Fr2EaxnGt6a1vbyaMEEIIIYQQQgghX9iDAwEAAAAAIP/XRlBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVlfbgkAAAAABA0P/XzrAAAAAAAAAAAAAAAAAAAAAAAAAAPAIaM/TqJuLcOAAAAABJRU5ErkJggg==')";
servo.style.backgroundPosition = "center";
servo.style.backgroundSize = "contain";
servo.addEventListener("touchstart", mouse_down);
servo.addEventListener("touchend", mouse_up);
servo.addEventListener("touchmove", mouse_move);
servo.addEventListener("mousedown", mouse_down);
servo.addEventListener("mouseup", mouse_up);
servo.addEventListener("mousemove", mouse_move);
var ctx = servo.getContext("2d");
ctx.translate(pivot_x, pivot_y);
rotate_bracket(0);
ws = new WebSocket("ws://" + window.location.host + ":81");
document.getElementById("ws_state").innerHTML = "CONNECTING";
ws.onopen = function(){ document.getElementById("ws_state").innerHTML = "Connected" };
ws.onclose = function(){ document.getElementById("ws_state").innerHTML = "Closed"};
ws.onerror = function(){ alert("websocket error " + this.url) };
ws.onmessage = ws_onmessage;
}
function ws_onmessage(e_msg)
{
e_msg = e_msg || window.event; // MessageEvent
alert("msg : " + e_msg.data);
}
function rotate_bracket(angle)
{
var servo = document.getElementById("servo");
var ctx = servo.getContext("2d");
ctx.clearRect(-pivot_x, -pivot_y, canvas_width, canvas_height);
ctx.rotate(angle / 180 * Math.PI);
ctx.drawImage(bracket_img, -pivot_x, -pivot_y);
ctx.rotate(-angle / 180 * Math.PI);
}
function check_range_xyra(event, mouse_xyra)
{
var x, y, r, a, rc_x, rc_y, radian;
var min_r, max_r, width;
if(event.touches)
{
var touches = event.touches;
x = (touches[0].pageX - touches[0].target.offsetLeft) - pivot_x;
y = pivot_y - (touches[0].pageY - touches[0].target.offsetTop);
min_r = 60;
max_r = pivot_x;
width = 40;
}
else
{
x = event.offsetX - pivot_x;
y = pivot_y - event.offsetY;
min_r = 60;
max_r = bracket_radius;
width = 20;
}
/* cartesian to polar coordinate conversion */
r = Math.sqrt(x * x + y * y);
a = Math.atan2(y, x);
mouse_xyra.x = x;
mouse_xyra.y = y;
mouse_xyra.r = r;
mouse_xyra.a = a;
radian = bracket_angle / 180 * Math.PI;
/* rotate coordinate */
rc_x = x * Math.cos(radian) - y * Math.sin(radian);
rc_y = x * Math.sin(radian) + y * Math.cos(radian);
if((r < min_r) || (r > max_r))
return false;
if((rc_y < -width) || (rc_y > width))
return false;
return true;
}
function mouse_down()
{
if(event.touches && (event.touches.length > 1))
click_state = event.touches.length;
if(click_state > 1)
return;
if(check_range_xyra(event, mouse_xyra))
{
click_state = 1;
last_angle = mouse_xyra.a / Math.PI * 180.0;
}
}
function mouse_up()
{
click_state = 0;
}
function mouse_move()
{
var angle;
if(event.touches && (event.touches.length > 1))
click_state = event.touches.length;
if(click_state > 1)
return;
if(!click_state)
return;
if(!check_range_xyra(event, mouse_xyra))
{
click_state = 0;
return;
}
angle = mouse_xyra.a / Math.PI * 180.0;
if((Math.abs(angle) > 90) && (angle * last_angle < 0))
{
if(last_angle > 0)
last_angle = -180;
else
last_angle = 180;
}
bracket_angle += (last_angle - angle);
last_angle = angle;
if(bracket_angle > 90)
bracket_angle = 90;
if(bracket_angle < -90)
bracket_angle = -90;
rotate_bracket(bracket_angle);
if(ws.readyState == 1)
ws.send(Math.floor(90 - bracket_angle) + "\r\n");
debug = document.getElementById("debug");
debug.innerHTML = Math.floor(90 - bracket_angle);
event.preventDefault();
}
window.onload = init;
</script>
</head>
<body>
<h2>
ESP32 Web Image Controlled Servo Motor<br>
<canvas id="servo"></canvas>
<p>
WebSocket : <span id="ws_state" style="color:#248580">null</span><br>
Angle : <span id="debug" style="color:Red">90</span>
</p>
</h2>
</body>
</html>
)=====";
6. Upload and Test
Upload the Code:
Connect your ESP32 to your computer, select the correct board and port in the Arduino IDE, and upload the code.
Access the Web Interface:
Open the Serial Monitor to get the ESP32's IP address. Enter this IP address into your web browser to access the web interface.
Test and Debug:
Click on the image on your web interface. The servo should move according to the horizontal position of the click, translating it into an angle between 0 and 180 degrees.
If the servo does not respond as expected, check your wiring, ensure the web interface is properly sending the angle, and verify WebSocket communication in the browser’s developer tools.
Demo:
Conclusion
With this setup, you can control a servo motor's angle using mouse clicks on an image rotate in a web interface. The ESP32 receives angle data via WebSocket and adjusts the servo position accordingly. Customize the image and refine the code as needed to suit your project’s requirements!
Comments