labsheet 3_modified[1]
labsheet 3_modified[1]
LABSHEET-2 (CO1)
Ground
Output
VCC
Fig. 1. Potentiometer
1
1. Pulse Width Modulation:
Pulse Width Modulation, or PWM, is a technique for getting analog results with
digital means. Digital control is used to create a square wave, a signal switched
between on and off. This on-off pattern can simulate voltages in between full-on
(5 Volts) and off (0 Volts) by changing the portion of the time the signal spends
on versus the time that the signal spends off. The duration of "on time" is called
the pulse width. To get varying analog values, you change or modulate, that
pulse width. If you repeat this on-off pattern fast enough with an LED, for
example, the result is as if the signal is a steady voltage between 0 and 5v
controlling the brightness of the LED
Duty Cycle
When the signal is high, we call this "on time". To describe the amount of "on
time", we use the concept of duty cycle. The duty cycle is measured in
percentage. The percentage duty cycle specifically describes the percentage of
time a digital signal is on over an interval or period. This period is the inverse of
the frequency of the waveform.
If a digital signal spends half of the time on and the other half off, we will say
the digital signal has a duty cycle of 50% and resembles an ideal square wave. If
the percentage is higher than 50%, the digital signal spends more time in the
high state than the low state and vice versa if the duty cycle is less than 50%.
100% duty cycle would be the same as setting the voltage to 5 Volts (high). 0%
duty cycle would be the same as grounding the signal.
3. Servomotor
Standard servo motors are actuators that allow for precise control of position
(angle). A typical characteristic is that the angle of the motor is 0 - 180 degrees.
With other words, it can make one half of a rotation.
Servo motors have three wires: power, ground, and signal. The power wire is
typically red and should be connected to positive pole (+) of your power source.
The ground wire is typically black or brown and should be connected to the
negative pole (-) of your power source.The signal pin is typically yellow or orange
and should be connected to PWM pin on the board.
3
Experiment 1: To get analog reading from the serial monitor using potentiometer
Circuit diagram:
Circuit Explanation:
The middle pin of the potentiometer is connected to the analog input pin (A0 to A5) on
the Arduino. The other pins are connected to 5V and GND respectively. The output
voltage is directly proportional to the rotated angle of the movable contact. When the
movable contact is turned all the way in one direction (nearest by GND), voltage at the
analog pin is reading 0V, which corresponds to 0 input level. When the movable contact
is turned all the way in other direction (nearest by 5V), voltage at the analog pin is
reading 5V, which corresponds to 1023 input level. The analog input levels then map to
a range from 0 to 255.
4
Block Code:
Programming Code:
// C++ code
void loop()
{
pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 255); Serial.println(pot);
delay(1000); // Wait for 1000 millisecond(s)
}
OUTPUT
5
Result: As the movable contact of the potentiometer is turned, the output value is
printed on the serial monitor.
Circuit diagram:
Circuit Explanation:
6
The middle pin of the potentiometer is connected to the analog input pin (A0 to A5) on
the Arduino. The other pins are connected to 5V and GND respectively. The output
voltage is directly proportional to the rotated angle of the movable contact. When the
movable contact is turned all the way in one direction (nearest by GND), voltage at the
analog pin is reading 0V, which corresponds to 0 input level. When the movable contact
is turned all the way in other direction (nearest by 5V), voltage at the analog pin is
reading 5V, which corresponds to 1023 input level. An external led is connected to
digital pin(0-13) on breadboard. When the voltage at analog pin corresponds to greater
than or equal to 165 input level, the LED starts to glow.
Block Code:
Programming Code:
// C++ code
int pot = 0;
void setup()
{
pinMode(A3, INPUT);
pinMode(12, OUTPUT);
}
void loop()
{
pot = analogRead(A3);
if (pot >= 200) {
digitalWrite(12, HIGH);
} else {
7
digitalWrite(12, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Output:
Hardware Output:
Result:
8
The led connected to pin 12 starts blinks and potentiometer is connected to Arduino pin
becomes greater than to a value(200) and intensity can be controlled by rotating
potentiometer.
Circuit diagram:
Circuit Explanation:
Three potentiometers are required perform this experiment. The circuit connection of
each potentiometer is done as mentioned below.
The middle pin of the each potentiometer is connected to the analog input pin (A0 to
A5) on the Arduino. The other pins are connected to 5V and GND respectively. The
output voltage is directly proportional to the rotated angle of the movable contact.
When the movable contact is turned all the way in one direction (nearest by GND),
voltage at the analog pin is reading 0V, which corresponds to 0 input level. When the
movable contact is turned all the way in other direction (nearest by 5V), voltage at the
analog pin is reading 5V, which corresponds to 1023 input level. An external RGB led is
connected to a digital pin on breadboard. When the voltage at analog pin corresponds
to greater than or equal to 165 input level for any of the potentiometer, the LED starts to
glow with corresponding color that is connected to digital pin on Arduino.
9
Block Code:
Programming Code:
// C++ code
//
int pot1 = 0;
int pot2 = 0;
10
int pot3 = 0;
void setup()
{
pinMode(A1, INPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(A3, INPUT);
pinMode(A5, INPUT);
}
void loop()
{
pot1 = analogRead(A1);
if (pot1 >= 160) {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
} else {
digitalWrite(10, LOW);
}
delay(15); // Wait for 15 millisecond(s)
pot1 = analogRead(A3);
if (pot2 >= 160) {
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(12, HIGH);
} else {
digitalWrite(11, LOW);
}
delay(15); // Wait for 15 millisecond(s)
pot1 = analogRead(A5);
11
if (pot3 >= 160) {
digitalWrite(12, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
} else {
digitalWrite(12, LOW);
}
delay(15); // Wait for 15 millisecond(s)
}
Output:
Hardware Output:
12
Result:
When the movable contacts(potentiometers) are rotated, when anyone of the
potentiometers reaches the value greater or equal to 200, then the corresponding color
of the RGB LED glows.
Circuit diagram:
13
Circuit Explanation:
The middle pin of the potentiometer is connected to the analog input pin (A0 to A5) on
the Arduino. The other pins are connected to 5V and GND respectively. The output
voltage is directly proportional to the rotated angle of the movable contact. When the
movable contact is turned all the way in one direction (nearest by GND), voltage at the
analog pin is reading 0V, which corresponds to 0 input level. When the movable contact
is turned all the way in other direction (nearest by 5V), voltage at the analog pin is
reading 5V, which corresponds to 1023 input level.
The 1st and 2nd pins of the servo motor are connected to ground and 5V respectively,
while the 3rd pin is connected to a digital output pin (0-13) on breadboard. When the
stimulation starts the servo motor rotates at a n angle from 0 to input value and
backwards.
Block Code:
14
Programming Code:
//
#include <Servo.h>
int pot = 0;
int i = 0;
int j = 0;
int k = 0;
Servo servo_12;
void setup()
{
pinMode(A1, INPUT);
servo_12.attach(12, 500, 2500);
}
void loop()
{
pot = analogRead(A1);
for (pot = 0; pot <= 180; pot += 1) {
servo_12.write(pot);
delay(15); // Wait for 15 millisecond(s)
for (pot = 180; pot >= 0; pot -= 1) {
servo_12.write(pot);
delay(15); // Wait for 15 millisecond(s)
}
}
}
Output:
15
Hardware Output:
Result:
When the stimulation starts, the servo motor connected to pin 12 on Arduino board
starts rotating from zero to the value of the potentiometer connected to analog pin (A0
to A5)` and backwards.
16
Inference:
1. From above experiments we learnt and got an idea about how to make
connections using potentiometer and servo motor
2. And also learnt working principles of potentiometer.
3. We performed experiments taking analog pins as inputs and learnt to write some
new codes.
4. Potentiometer consist of three terminals two of which are connected to the ends
of the resistive element and the third is connected to a movable contact that can
slide along the resistive element.
5. Potentiometer is used in electrical circuit that is used to manually change
oscilloscope zoom levels, brightness, volume etc…
6. Servo motor has the angle of the motor is 0 - 180 degrees. With other words,
it can make one half of a rotation,
7. In servo motor red is connected : 5v;
Brown is connected to :GND;
Orange :PWM;
17