360 continues servo
This tutorial instructs you
-
How to use a Continuous servo motor with esp32.
-
How to control a Continuous servo motor using buttons.
Video Tutorial
you can watch this video tutorial
Hardware Required
1 | × | ESP-WROOM-32 Dev Module | |
1 | × | Micro USB Cable | |
1 | × | Servo Motor | |
3 | × | Buttons | |
1 | × | Breadboard | |
n | × | Jumper Wires |
About this project
Introduction to Continuous Servo Motor
The standard servo motor is a motor that can rotate between 0° and 180°. and you can review our tutorial about it here.
Its internal gearing provides a high torque power pack in a small and inexpensive package.
That combination of small size and large torque also make servos attractive to use as replacements for standard DC motors in the design of small devices like tiny toys and robots. This prompted several people to modify standard analog servos by removing the potentiometer to allow the servo to spin a full 360 degrees.
Manufactures got the message and now offer “continuous rotation servo motors”, essentially servos with the servomechanism disengaged.
In a continuous rotation servo motor the speed and direction of the shaft rotation is controlled by the same PWM signal that is used in a conventional analog servo motor.
Servo Motor Pinout
The servo motor has three pins:
-
GND pin:(brown or black) connects this pin to GND (0V)
-
VCC pin: (red) connects this pin to VCC (5V)
-
Signal pin: (yellow or orange) receives the PWM control signal from an ESP32's pin.
How Servo Motor Works
After connecting VCC pin and GND pin to 5V and 0V, respectively, we can control the servo motor by generating proper PWM signal to signal pin.
The direction is determined by the width of PWM signal.
The direction is determined as follows:
-
If PWM's width = WIDTH_MIN, the servo motor rotates at full speed counter-clockwise.
-
If PWM's width = WIDTH_MAX, the servo motor rotates at full speed clockwise.
-
If PWM's width is between WIDTH_MIN and WIDTH_MAX, the servo motor rotates slower until it STOP then rotates in the opposite direction.
Introduction to Button
please review our tutorial about Button
ESP32 - Servo Motor
We can control the servo motor by connecting the servo motor's signal pin to an ESP32's pin, and programming to generate PWM on the ESP32's pin.
Thanks to Arduino Servo library, controlling servo motor is a piece of cake. We even do NOT need to know how servo motor works. We also do NOT need to know how to generate PWM signal. We JUST need to learn how to use the library.
-
Click here to download the ESP32_Arduino_Servo_Library. You should have a .zip folder in your Downloads folder
-
Unzip the .zip folder and you should get ESP32-Arduino-Servo-Library-Master folder
-
Rename your folder from ESP32-Arduino-Servo-Library-Master to ESP32_Arduino_Servo_Library
-
Move the ESP32_Arduino_Servo_Library folder to your Arduino IDE installation libraries folder
-
Finally, re-open your Arduino IDE
How To Program For Servo Motor
-
Include the library:
#include <Servo.h>
Servo myServo;
Servo myServo1; Servo myServo2;
myServo.attach(9);
myServo.write(0);
myServo.write(90);
Wiring Diagram
Schematic Diagram
Image is developed using Fritzing. Click to enlarge image
Breadboard Connections
ESP32 Code
#include <Servo.h> Servo myservo; // create servo object to control a servo void setup() { myservo.attach(21); // attaches the servo on pin 4 to the servo object pinMode(4,INPUT_PULLUP); pinMode(16,INPUT_PULLUP); pinMode(17,INPUT_PULLUP); } void loop() { if(digitalRead(4)==LOW) { myservo.write(10); // tell servo to rotate at ccw delay(15); // waits 15ms for the servo to reach the position } if(digitalRead(16)==LOW) { myservo.write(90); // tell servo to STOP delay(15); // waits 15ms for the servo to reach the position } if(digitalRead(17)==LOW) { myservo.write(170); // tell servo to rotate at cw delay(15); // waits 15ms for the servo to reach the position } }
Quick Steps
- power up your board
- Open Arduino IDE
- Select the right board
- Select the right port
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to ESP32
- Press and keep pressing the button several seconds
- See the changes you made
Book Tutorial
We are considering to make the book tutorials. If you think the book tutorials are essential, you can download it. download book
See Also
References
※ NOTE THAT:
Some components works on 3.3v and others works on 5v!