Professional Documents
Culture Documents
Servo Motor
Servo Motor
Servo Motor
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
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.
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);
}