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

Arduino UNO Servo Motor Controller with Speed Adjustment

View and Edit Project In Cirkit DesignerImage of Arduino UNO Servo Motor Controller with Speed Adjustment

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller, a 9V battery, a servo motor, a ProtoSnap Pro Mini Protoboard, and two pushbuttons. The Arduino UNO is powered by the 9V battery and controls the servo motor. The ProtoSnap Pro Mini Protoboard is used for additional connections, and the pushbuttons are used to control the speed of the servo motor.

Component List

Arduino UNO

9V Battery

Servo

ProtoSnap - Pro Mini - Protoboard

Pushbutton (1)

Pushbutton (2)

Wiring Details

Arduino UNO

9V Battery

Servo

ProtoSnap - Pro Mini - Protoboard

Pushbutton (1)

Pushbutton (2)

Code Documentation

Arduino UNO Code

#include <Servo.h>          //include the servo library

int Faster = 2; //this is the faster button. CHANGE THIS!!! make this the actual number its plugged into. 
int Slower = 3; //this is the slower button. AGAIN PLZ CHANGE PLZZZZZZ

int MaxSpeed = 1000;
int Speed = 2000; //starts at 2 seconds delay initially. speed off motor can be the delay, but it shouldn't be below 1000(value of Too fast). the higher the speed, the lower this variable will be. 

Servo myservo; //create servo object

void setup()
{
  pinMode(Slower, INPUT_PULLUP); 
  pinMode(Faster, INPUT_PULLUP);
  myservo.attach(9);        //the servo plugged into pin 9
}

void loop() 
{
  FasterButton();
  SlowerButton();
  Go();
}

void FasterButton()
{
  if((digitalRead(Faster) == LOW) && (Speed > MaxSpeed)) //less in value the speed, the faster it goes. MaxSpeed littlest value "Speed" can have. 
  {
    Speed -= 500;
    delay(500);
  }
}

void SlowerButton()
{
  if(digitalRead(Slower) == LOW)
  {
    Speed += 500;
    delay(500);
  }
}

void Go()
{
  myservo.write(20);
  delay(Speed);
  myservo.write(160); //idk why last time it didn't work but this is for degree position so this is what im putting
  delay(Speed); //goes back and forth FOREVA
}

This code controls the servo motor using two pushbuttons. The Faster button decreases the delay between servo movements, making the servo move faster, while the Slower button increases the delay, making the servo move slower. The servo is connected to pin 9 of the Arduino UNO.