Learning Electronics for Beginners: How to do an Arduino Servo project controlled by a potentiometer
Introduction
Hello! Welcome to our blog for today.
Here, you'll find all the information you need on kids' projects, ranging from basic to intermediate and advanced levels, with the aim of making you an expert in Electronics. Our primary focus is to provide you with comprehensive and easy-to-follow guidance on using Arduino microcontroller , allowing you to complete each step with confidence and become an advanced user.
Requirements
Arduino board
Breadboard
Jumper wires
Potentiometer
Servo motor
How it works
This project enables us to manipulate the servos' position within the range of 0 to 180 degrees, while also enabling us to adjust the servo's rotation speed. The servo motor comprises three terminals, namely the signal, power, and ground. To connect the servo motor to the Arduino board, we link the power pin of the servo motor to the PWM pin of the Arduino. In this instance, we have linked the power terminal to pin 9 on the Arduino UNO R3 board.
Building the Circuit
This circuit is pretty Straightforward.
Follow the table below to get the best experience.
Connect the signal terminal of the servo motor to the 5V pin of the Arduino board.
You can connect the power terminal of the motor to a digital PWM pin on the Arduino board. (Pin 9)
Attach the ground terminal of the servo motor to the GND pin on the Arduino board.
One of the outer pins of the potentiometer should be linked to the GND pin of the Arduino board, while the other outer pin should be connected to the 5V pin on the board.
The middle terminal of the potentiometer should be joined to the analog input pin A1 on the Arduino board.
Sensor Pin | To Arduino Board |
Signal Pin of Servo | 5V of Arduino |
VCC of Servo | PWM Digital pin 9 |
GND of servo | GND of Arduino |
Center pin of Potentiometer | A1 |
Outer pin (right) | +5V |
Outer pin (left) | GND |
Actual Circuit
Code /Arduino sketch
#include <Servo.h>
Servo myservo;
// It creates a servo object, which is used to control the servo
int potentioPIN = A1; // specified analog pin used to connect the potentiometer Which is in Analog pin A1
int value; // value initialized to the variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // servo connected to pin 9 of the Arduino board to the servo object
}
void loop()
{
value = analogRead(potentioPIN);
// reads the value of the potentiometer (value between 0 and 1023)
value = map(value, 0, 1023, 0, 180);
// scale it to use it with the servo (value between 0 and 180)
myservo.write(value);
delay(1000); // it will wait for 1 second for the
// It will set the position of the motor according to the scaled value
value = map(value, 1023, 0, 180, 0);
// reads the value of the potentiometer (value between 1023 and 0)
myservo.write(value);
// scale it to use it with the servo (value between 180 and 0)
// the motor will rotate in reverse direction
delay(1000);
// delay time in milliseconds
//after 1500 millisecond it will again rotate from 0 to 180 degree
}
Video /Demo
Need to explore more ?
May need to add some LEDs whenever the motor is being controlled at different angles, to light ON and OFF.
The concept of lighting LEDs on some thresholds is well covered in: one of projects for kids. Click here to explore.
STEM Summer camp in DC and Maryland
You are looking for a nice 2024 summer camp for this year for your children focusing on STEM (Learn how to code, make robots, use 3D printing, droning and more) in the Washington DC, Maryland and Northern Virginia area. Come join us in Takoma Park Maryland where your children can learn and have fun.
Check the following link for more details and the dates:
Online after-school focused on STEM
You and your children are looking for nice activities to have fun and learn new things and skills. Come join us for online classes such as:
Python coding for kids and teens
Coding for elementary school students
Make video games
Electronics
Digital modeling (Create cars, rockets, rings, etc) for 3D printing and much more with the following link: Online after-schools
Other cute things to make and hand-crafts for kids (tutorials)
If you are looking for more cool Arduino and STEM project ideas to do with your kids, take a look at these other activities:
Newsletter, follow, subscribe, and like the social media
If you like online STEM activities, consider subscribing to the newsletter and social media for updates, and don't miss any STEM events. Don't forget to subscribe to the newsletter at the bottom of our website ''www.makersgeneration.net'' for more events, tutorials, and freebies.
Subscribe to the Facebook group if you have yet registered. Content and tutorials are shared daily: Create and build STEM projects for kids
We can be reached at: contact@makersgeneration.net if any questions.
See you on soon.
Comments