Arduino Servo Motor Control with Potentiometer | Example Code | English Subtitle

preview_player
Показать описание
Arduino Servo Motor Control with Potentiometer | Example Code | English Subtitle
Code : code is on the comment below.
Please Subscribe my Channel. ThankYou!
Рекомендации по теме
Комментарии
Автор

#include <Servo.h>

// Define the pin for the potentiometer and servo
const int potPin = A0; // Connect potentiometer to analog pin A0
const int servoPin = 9; // Connect servo signal pin to digital pin 9

// Define the range of potentiometer and servo
const int potMin = 0; // Minimum value of potentiometer
const int potMax = 1023; // Maximum value of potentiometer
const int servoMin = 0; // Minimum angle of servo (0 degrees)
const int servoMax = 180; // Maximum angle of servo (180 degrees)

Servo myServo;

void setup() {
// Attach servo to its pin
myServo.attach(servoPin);
}

void loop() {
// Read the position of potentiometer
int potValue = analogRead(potPin);

// Map the potentiometer value to servo range
int servoAngle = map(potValue, potMin, potMax, servoMin, servoMax);

// Control the servo motor
myServo.write(servoAngle);

// Add a small delay to prevent rapid changes
delay(15); // Adjust the delay as needed
}

doit.
welcome to shbcf.ru