Monday, March 25, 2019

Servo Motor with esp32 Electricalkida Pedometer electricalkida


The Servo moter is used to move the motor of any angle.This is Tower Pro SG-91 Micro Servoit is used for robotic,open toll gate,move the shaft of arm etc.It is very light. mounting hardware.
we can control the position the servo’s shaft in various angles from 0 to 180ยบ. Servos are controlled using a pulse width modulation (PWM) signal. This means that the PWM signal sent to the motor will determine the shaft’s position.
We control the PWM capabilities of the ESP32 by sending a 50Hz signal with the appropriate pulse width.




Wiring Of Servo Motor to ESP32

S.NO
SERVO MOTOR
ESP32
1
GND
GND
2
POWER
5V
3
SIGNAL
G4
Table 3.2.3.1: Connection of servo motor to esp32
 Programing:
#include <Servo.h>


static const int servoPin = 4;

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);
    }
}

We Control the Servo motor by potentimeter:
programming:
#include <Servo.h>

static const int servoPin = 4;
static const int potentiometerPin = 32;

Servo servo1;

void setup() {
    Serial.begin(115200);
    servo1.attach(servoPin);
}

void loop() {
    int servoPosition = map(analogRead(potentiometerPin), 0, 4096, 0, 180);
    servo1.write(servoPosition);
    Serial.println(servoPosition);
    delay(20);
}

No comments:

Post a Comment

ESP 32 FreeRTOS Task Create in Dual Core

ESP 32 FreeRTOS, LED Turn On and Turn Off: In This Artical i will explain you, how to  use FreeRTOS in ESP32 Board- Projects 1- Create three...