Controlling a servo motor through LAN
We controlled an LED remotely. The same program can be extended to control a micro servo motor. But buttons inside the webpage cannot give real control on an analog motor. So, we will use a slider/range input to control the micro servo motor.
HTML code
Open Cloud9 IDE and create a new file named servo.html
. Write the following code in servo.html
.
The code for servo.html
is as follows:
<!DOCTYPE html> <html> <head> <script src="/socket.io/socket.io.js"></script> <script> var socket = io.connect(); function pwm(value){ socket.emit('pwm',value); } </script> </head> <body> <div> <label for="servo">Servo:</label> <input type="range" name="servo" id="servo" value="50" min="0" max="180" onChange="pwm(value);"> </div> </body> </html>
This HTML code is similar to the code from the led.html
file. Here, we used range instead of buttons...