Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Controlled Servo Motor Circuit

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled Servo Motor Circuit

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)

Servo

Wiring Details

ESP32 (30 pin)

Servo

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.