You are on page 1of 37

Servo Motor

Servo motor working


Servo motor
Attach to PWM pins for Ardino UNO
Sweeps the shaft of a servo motor back and
forth across 180 degrees.
SERVO MOTOR SG90
TowerPro SG-90 Features
Operating Voltage is +5V typically
Torque: 2.5kg/cm
Operating speed is 0.1s/60°
Gear Type: Plastic
Rotation : 0°-180°
Weight of motor : 9gm
pulse width range - 900-2100μsec
Rotation direction: CW ( When 1500-900μsec)
CCW (When 1500-2100μsec)
Stop position:1500 μsec
#include <Servo.h>

Requirement Servo myservo;


int pos = 0; // variable to store the servo position

void setup() {
Hardware Required myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
• Arduino or Genuino
void loop()
Board {
• Servo Motor for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
• hook-up wires myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1)
{ // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Stepper Motor
Driving Modes
Increasing numbers of the poles of the rotor
and the numbers of the pole of the stator
Permanent Magnet stepper

The Permanent Magnet stepper has a


permanent magnet rotor which is
driven by the stators windings. They
create opposite polarity poles
compared to the poles of the rotor
which propels the rotor.
Variable Reluctant stepper motor

The next type, the Variable Reluctant


stepper motor uses a non-magnetizes
soft iron rotor. The rotor has teeth that
are offset from the stator and as we
active the windings in a particular
order the rotor moves respectively so
that it has minimum gab between the
stator and the teeth of the rotor
Hybrid Synchronous motor
This is a front view of a commonly
used hybrid stepper motor which
has 8 poles on the stator that are
activated by 2 windings, A and B.
So if we activate the winding A, we
will magnetize 4 poles of which two
of them will have South polarity
and two of them North polarity.
We can see that in such a way the
rotors teeth are aligned with the
teeth of poles A and unaligned
with the teeth of the poles B.
That means that in the next step
when we turn off the A poles and
activate the B poles, the rotor will
move counter clock wise and its
teeth will align with the teeth of
the B poles.
28-BYJ48 Stepper Motor Name

T h e s p e e d c a n ra n g e
between 0 to 200 for 28-
BYJ48 stepper motors
• The gear ratio is given to be 1:64 • Stride Angle: 5.625°/64
• The shaft that you see outside • Single step angle will be 5.625
will make one complete rotation • for 64 step it will be
only if the motor inside rotates 64*5.625=360
for 64 times. This is because of
the gears that are connected
between the motor and output
shaft, these gears help in
increasing the torque.
stepper motor driver
• To energise the four coils of the
stepper motor we are using the
digital pins 8,9,10 and 11. The
driver module is powered by the
5V pin of the Arduino Board.
Motor has Unipolar 5-lead coil arrangement.
There are four coils which have to be
energized in a particular sequence. The Red
wires will be supplied with +5V and the
remaining four wires will be pulled to
ground for triggering the respective coil. We
use a microcontroller like Arduino energize
these coils in a particular sequence and
make the motor perform the required
number of steps.

8- Orange
9-Yellow
10-Pink
11-Blue
The 28BYJ-48 is a 5-wire unipolar
stepper motor that moves 32 steps
per rotation internally but has a Motor had 32
gearing system that moves the shaft step for 1
by a factor of 64. The result is a
motor that spins at 2048 steps per revolution
rotation. It should be noted that
some of these motors may have a
different gearing system so the
number of steps per rotation of your
motor may not be the same. The Gear Ratio 64:1
28BYJ-48 runs on 5 volts.

motor shaft that


spins at 2048
steps per rotation
#include <Stepper.h>
#define STEPS 32 // create an instance of the stepper class using the steps and pins
Stepper stepper(STEPS, 8, 10, 9, 11);

int val = 0;

void setup() {
Serial.begin(9600);
stepper.setSpeed(200);
}

void loop() {

if (Serial.available()>0)
{
val = Serial.parseInt();
stepper.step(val);
Serial.println(val); //for debugging
}

}
Stepper One step revolution
#include <Stepper.h> // step one revolution in the other direction:
const int stepsPerRevolution = 200; Serial.println("counterclockwise");
Stepper myStepper(stepsPerRevolution, 8, 9, 10, myStepper.step(-stepsPerRevolution);
11);
delay(500);
}
void setup() {
myStepper.setSpeed(60);
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
Stepper One step at a time
#include <Stepper.h> void loop() {
const int stepsPerRevolution = 200; // step one step:
Stepper myStepper.step(1);
myStepper(stepsPerRevolution, 8, 9,
Serial.print("steps:");
10, 11);
Serial.println(stepCount);
int stepCount = 0;
void setup() { stepCount++;
Serial.begin(9600); delay(500);
} }
HC-SR501 PIR Sensor Module
PIR Sensor
• when a human or animal body will get in the range of the sensor it will
detect a movement because the human or animal body emits heat
energy in a form of infrared radiation. That’s where the name of the
sensor comes from, a Passive Infra-Red sensor. And the term “passive”
means that sensor is not using any energy for detecting purposes, it just
works by detecting the energy given off by the other objects
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int val = 0; // variable for reading the pin status

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH)
{ // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
}
else
{
digitalWrite(ledPin, LOW); // turn LED OFF
}
}
Temperature AND Humidity sensor
AM2302/DHT22 output calibrated digital signal. It applies exclusive digital-signal-collecting-technique and
humidity sensing technology, assuring its reliability and stability. Its sensing elements is connected with 8-
bit single-chip computer.
Power's voltage should be 3.3-5.5V DC. When power is supplied to sensor, don't send any instruction to the
sensor within one second to pass unstable status. One capacitor valued 100nF can be added between VDD
and GND for wave filtering.
#include <DHT.h>;
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(10000);
}

You might also like