Servo motor is small machine part.
It can turn to exact position.
People use it in many things like robots, CNC machines and factory machines.
This post for Simple Servo Motor Controller Circuit using Arduino show how to control servo motor using Arduino.
It also use push buttons, capacitors, resistors and IC 7809 for power.
Coding:
#include <Servo.h>
Servo myservo; // Create a servo object
int servoPin = 9; // Pin connected to the servo signal
int button1Pin = 2; // Pin connected to the first push button
int button2Pin = 3; // Pin connected to the second push button
int angle = 0; // Initial servo angle
void setup() {
myservo.attach(servoPin); // Attach the servo to the specified pin
pinMode(button1Pin, INPUT); // Set the push button pins as input
pinMode(button2Pin, INPUT);
}
void loop() {
int button1State = digitalRead(button1Pin);
int button2State = digitalRead(button2Pin);
if (button1State == HIGH) {
angle += 1; // Increment the angle
if (angle > 180) {
angle = 180; // Limit the angle to 0-180 degrees
}
} else if (button2State == HIGH) {
angle -= 1; // Decrement the angle
if (angle < 0) {
angle = 0; // Limit the angle to 0-180 degrees
}
}
myservo.write(angle); // Set the servo's position
delay(15); // Delay for smooth movement
}
Code explanation:
- Code set start angle, button pins and servo pin.
- In setup() button pins set as input and servo are connected to servo pin.
- In loop() code check button press.
- If button 1 is pressed angle goes up and if button 2 is pressed angle goes down.
- Angle stay between 0 and 180.
- myservo.write() set servo to new angle.
Circuit Working:
Parts List:
Component | Quantity |
---|---|
Resistors | |
1/4 watt 100k | 2 |
Capacitor | |
100μF 25V | 1 |
Semiconductors | |
Arduino Uno board | 1 |
IC 7809 | 1 |
Servo Motor | 1 |
Tactile Switches | 2 |
In this article servo and other parts can get power from 9V using IC 7809.
Servo and Arduino must share same ground.
Arduino uses PWM (Pulse Width Modulation) to control servo position.
Servo angle changes by pulse width.
Write Arduino code to read buttons and move servo.
For example press one button servo goes one way and press other the servo goes the other way.
Arduino check button1 and button2.
When button is pressed input pin read LOW is connected to ground.
When no button is press then pull-up resistor make pin read HIGH.
Ensure voltage regulator work good with less noise the better servo will work.
Resistor and capacitor help give clean and steady power to the circuit.
How To Build:
To build a Simple Servo Motor Control Circuit using Arduino following are the connections steps to follow:
- Collect all parts shown in circuit diagram.
- Use IC 7809 to give stable 9V DC to Arduino.
- Connect servo ground wire to Arduino ground pin.
- Connect 5V from Arduino to servo power pin.
- Connect servo signal pin (PWM) to Arduino pin 9.
- Connect 100μF 25V capacitor with one side to 5V and other to ground.
- Connect button1with one leg to pin 2 and other leg to ground.
- Connect button2 with one leg to pin 3 and other leg to ground.
- Connect 100k resistor between pin 2 and 5V.
- Connect another 100k resistor between pin 3 and 5V.
Conclusion:
This article for Simple Servo Motor Controller Circuit using Arduino show to move servo motor.
By using buttons, resistors, capacitor and IC 7809 make circuit more strong and useful.
This circuit is good for many projects.
References:
Control a servo motor with a 2 connection toggle switch (on/off switch)