Circuit Documentation
Summary of the Circuit
This circuit consists of an ESP32 microcontroller and a servo motor. The ESP32 is a versatile microcontroller with a wide range of GPIO pins suitable for various applications, including driving servo motors. In this circuit, the ESP32 is used to control the position of the servo motor through one of its digital pins. The servo motor is powered directly from the ESP32's voltage input pin and is controlled via a PWM signal.
Component List
ESP32 (30 pin)
- Description: A 30-pin microcontroller with Wi-Fi and Bluetooth capabilities.
- Purpose: Acts as the central processing unit of the circuit, generating PWM signals to control the servo motor.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3.
Servo
- Description: A motor capable of precise position control.
- Purpose: Responds to PWM signals from the ESP32 to move to the desired position.
- Pins: GND, VCC, PWM.
Wiring Details
ESP32 (30 pin)
- Vin: Connected to the VCC pin of the Servo to provide power.
- D23: Connected to the PWM pin of the Servo to send control signals.
- GND: Connected to the GND pin of the Servo to complete the power circuit.
Servo
- VCC: Connected to the Vin pin of the ESP32 to receive power.
- PWM: Connected to the D23 pin of the ESP32 to receive control signals.
- GND: Connected to the GND pin of the ESP32 to complete the power circuit.
Documented Code
The following code is written for the ESP32 microcontroller to control the servo motor. The code is responsible for sweeping the servo motor back and forth between 0 and 180 degrees.
#include <ESP32Servo.h>
static const int servoPin = 23;
Servo servo1;
void setup() {
Serial.begin(115200);
servo1.attach(servoPin);
}
void loop() {
for(int posDegrees = 0; posDegrees <= 180; posDegrees++) {
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
for(int posDegrees = 180; posDegrees >= 0; posDegrees--) {
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
}
Filename: sketch.ino
This code initializes the serial communication at a baud rate of 115200 and attaches the servo motor to pin D23 of the ESP32. In the loop function, the servo is instructed to move from 0 to 180 degrees and then back to 0 degrees, with a delay of 20 milliseconds between each degree change. The current position in degrees is printed to the serial monitor during the sweep.
