0% found this document useful (0 votes)
24 views11 pages

Embedded Systems Report Lab 6

Embedded systems report

Uploaded by

SOPHIA JERARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views11 pages

Embedded Systems Report Lab 6

Embedded systems report

Uploaded by

SOPHIA JERARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Embedded Systems Report Lab 6

Made by: Essoufia EL JERARI Grp A1


Supervisored by: Adnane ADDAIM

1
Table of Contents
Introduction..................................................................................................................................3
Part we will need...........................................................................................................................3
BreadBoard Layout........................................................................................................................4
Theory...........................................................................................................................................5
Servo motor interfacing with Arduino........................................................................................5
Control Signal..............................................................................................................................................5
Power.......................................................................................................................................................... 5
Ground........................................................................................................................................................ 6
Arduino Sketch..............................................................................................................................6
Explanation...................................................................................................................................6
Proteus 8 simulation......................................................................................................................7
Arduino servo motor control with potentiometer...........................................................................8
Introduction...............................................................................................................................8
Required Hardware....................................................................................................................8
BreadBoard Layout....................................................................................................................9
Theory.......................................................................................................................................9
Arduino Sketch Code................................................................................................................10
Proteus Simulation...................................................................................................................10
Proteus simulation of controlling the position angle of the servomotor arm by a LDR..................11
Controlling the position angle of the servomotor arm from Serial Monitor...................................11
Arduino Sketch........................................................................................................................12

2
Introduction
In this lab we will control the position of a servo using an angle calculated in your sketch. Servos
are the easiest way to start making motion with a microcontroller. Unfortunately, servos do not
turn 360 degrees but only 180.

Part we will need

Arduino Uno Rev3 ×1

Breadboard 400 point ×1

Dupont Wires ×7

Servo Motor ×1

3
BreadBoard Layout

Theory
A servo motor is a rotary actuator mostly coupled with a shaft or arm. It has a position control
associated with the servo mechanism. It uses a closed-loop control system with error-sensing
negative feedback to correct the performance of a mechanism. A servo motor maintains accurate
control of angular position and speed of motion of the rotor. The Servos have integrated drive
gears and circuit, which precisely control the servo position.

The angular positions of a servo motor are controlled by the pulse width modulation(PWM).The
input pulse train at the control signal will turn the rotor to the desired position. The servo motor
expects a control pulse at every 20 milliseconds (ms). The width of each pulse directs the servo
to turn the shaft to the corresponding angular positions. That is the duration of the positive pulse
in a 20ms total pulse width determines the servo shaft position. For a standard servo, 1ms
positive pulse maintains a 0° and a maximum of the 2ms positive pulse will have a position of
180°. Thus the pulse width between 1ms and 2ms obtains a corresponding position between 0° to
180° angles respectively.

Servo motor interfacing with Arduino

Control Signal
The signal wire commonly has an orange colour. Yellow, white, blue colours are also used for
this connection. One of the Digital pins of Arduino can be used for the signal connection. But, it
is commonly used on PWM pins (3, 5, 6, 9, 10, or 11). The servo is mostly connected to pin 9 on
the Arduino board. Even the servo is not in use, the analogWrite () (PWM) functionality on pins

4
9 and 10 disables by the accessing of the library function (except the Arduino Mega). Thus the
remaining PWM pins can use for analogwrite () (PWM) by connecting servos to the pin 9 or 10.
Power
The power wire mostly has a red colour, which connects to the 5V pin of the Arduino.The Servo
motor requires a considerable amount of power, especially for high power servos. So, for
multiple servos or while using servos along with other pins, it is better to power the servo motor
separately with an external supply. Because the power at the remaining pins would be interrupted
during its operation.For external powering, connect the ground of the arduino commonly with
the -ve terminal of the external power supply. And connect the supply terminal of the servo (+V)
to the +Ve terminal of the external supply.

Ground
The ground wire typically has black or brown colour. It connects to the ground pin of the
Arduino.

Arduino Sketch

#include <Servo.h>

Servo myservo;
int pos=0;

void setup()
{
myservo.attach(9);
}

void loop()
{
for(pos = 5; pos <= 175; pos += 1)
{
myservo.write(pos);
delay(20);
}
for(pos = 175; pos>=5; pos-=1)
{
myservo.write(pos);
delay(20);
}
myservo.detach();

5
}

Explanation
Import the Servo Libary
To use the servo library, you’ll first need to import it. This makes the additions from the library
available to your sketch
#include <Servo.h>
Create a Servo Object
To refer to the servo, you’re going to need to create a named instance of the servo library in a
variable. This is called an object. When you do this, you’re making a unique name that will have
all the functions and capabilities that the servo library ofers. From this point on in the program,
every time you refer to myServo, you’ll be talking to the servo object.
Servo myservo; // create servo object to control a servo

Declare variable to hold the servo angle


Set up a variable for storing the angle of the servo motor is very important.
int angle = 5; // variable to store the servo position
For Loop to move the Servo Motor
You arrived at the void loop() part of the sketch. Since we start at a zero angle you can use a for
loop to go to 175degrees. In the for loop initialization start with the angle, then a condition is
tested. If the tested condition is true the code inside the for loop is executed and the angle is
incremented by 1.
for (angle = 5; angle < 175; angle += 1) // goes from 5 degrees to 175 degrees
{ // in steps of 1 degree
myservo.write(angle); // tell servo to go to position in variable 'angle'
delay(20); // waits 20ms between servo commands
}
Return for loop to original posistion
To move the servo motor back again you need a different for loop. If the angle of the servo
motor is at the max, it will be in an angle of 175 degrees. Therefore, if you want it to go back
you need to decrement. The for condition is met when angle is 175 degrees and greater or equal
to 1 degree. The code will be executed and the angle will be decremented with 1.
or we can use //myservo.detach() to stop the servo motor from operating repeatidly.

Proteus 8 simulation

6
Arduino servo motor control with potentiometer

Introduction
In this tutorial, we are going to control the rotation of a servo with a potentiometer. In contrast to
the previous lab, we will use an analog input to control the servo motor.
Required Hardware

Arduino Uno Rev3 ×1

Breadboard 400 point ×1

Dupont Wires × 10

Servo Motor ×1

10K Potentiometer ×1

7
BreadBoard Layout

Theory
Here we are controlling the angular position of a servo motor using a potentiometer. At every
instant, the servo arm follows the
position of the Knob. The servo
moves clockwise or
counterclockwise (5° – 175°) with
the corresponding angular position
of the potentiometer.

The wiper pin of the potentiometer


is connected to analog input of the
arduino. The terminal(T1) of the
potentiometer is connected to
supply voltage and the other
terminal(T2) to the ground.

By turning the potentiometer, the


input voltage varies in the range of
0 to 5V. The arduino uno has a 10-
bit analog to digital converter. So
the analog input values for the
range 0 to 5 volt is converted into
corresponding decimal values from 0 to 1023.

In the program, we map the values between 0 – 1023 to 5° – 175°. Thus the angle of servo
proportionally increments and decrements with the increase and decrease in input value. That is

8
when the knob is at centre position the servo arm will be at 90°. And will turn towards 5° and
175° when rotating the knob towards GND terminal T2 and 5V terminal T1 respectively. Thus,
every position change in the potentiometer will make the corresponding angular position change
in the servo motor.
Arduino Sketch Code

#include <Servo.h>

Servo servo1;
int potin;
int potpin=A0;
int ServoPin=9;

void setup()
{
servo1.attach(ServoPin);
}

void loop()
{
potin = analogRead(potpin);
potin = map(potin, 0, 1023, 5, 175);
servo1.write(potin);
delay(15);
}

Proteus Simulation

9
Proteus simulation of controlling the position angle of the servomotor arm by a LDR

With keeping the same code as above, the servo motor speed will be controlled by the intensity of
light sensored by the LDRs, and by adjusting the knob of the pot connected to A0 of the arudino.

Controlling the position angle of the servomotor arm from Serial Monitor

This servo motor drive system is a USB based servo controller. That is the servo motor can be
controlled by a computer using Arduino serial communication.

To control the servo position the angles are entered as decimal input values in the range 5° to
175° in the serial monitor of the Arduino IDE.
This Arduino sketch is to control the position and speed of a servo motor using Arduino serial
communication. Here the input decimal values of position and the speed of the shaft movement
can be given through the serial monitor. The values can be separated by entering the position and
the time delay by a comma

10
Arduino Sketch

#include <Servo.h>
int ServoPin=9;
int angle;
Servo myservo;
void setup() {
myservo.attach(ServoPin);
Serial.begin(9600);
}

void loop() {
Serial.print("Enter the angle value=");
while(Serial.available()==0) {}
angle = Serial.parseInt();
Serial.println(angle);
Serial.flush();
delay(1000);
myservo.write(angle);
//myservo.detach();

11

You might also like