Documente Academic
Documente Profesional
Documente Cultură
Little theory
• Servo Motors are used where there is a need for
accurate shaft movement or position.
• Not proposed for high speed applications. These are
proposed for low speed, medium torque and accurate
position application.
• These motors are used in robotic arm machines, flight
controls and control systems.
• A servo motor is a combination of DC motor, position control system,
gears.
• The position of the shaft of the DC motor is adjusted by the control
electronics in the servo, based on the duty ratio of the PWM signal the
SIGNAL pin.
• Simply speaking the control electronics adjust shaft position by controlling
DC motor. This data regarding position of shaft is sent through the SIGNAL
pin. The position data to the control should be sent in the form of PWM
signal through the Signal pin of servo motor.
Servo commands
• servo.attach(pin)
Attach the Servo variable to a pin.
• servo.write(angle)
Writes a value to the servo, controlling the shaft accordingly.
• servo.writeMicroseconds(uS)
Writes a value in microseconds (uS) to the servo, controlling the shaft
accordingly.
• servo.read()
Read the current angle of the servo (the value passed to the last call to
write()).
• servo.attached()
Check whether the Servo variable is attached to a pin.
• servo.detach()
Detach the Servo variable from its pin.
• http://arduino.cc/en/Reference/Servo
Pin configuration
Connection with arduino
Test program 1
• Go to FILES -> Examples -> servo-> Sweep
Test program 2
• // Include the Servo library
• #include <Servo.h>
• // Declare the Servo pin
• int servoPin = 9;
• // Create a servo object
• Servo Servo1;
• void setup()
• {
• // We need to attach the servo to the used pin number
• Servo1.attach(servoPin);
• }
• void loop()
• {
• // Make servo go to 0 degrees
• Servo1.write(0);
• delay(1000);
• // Make servo go to 90 degrees
• Servo1.write(90);
• delay(1000);
• // Make servo go to 180 degrees
• Servo1.write(180);
• delay(1000);
• }
Test program 3
#include <Servo.h>
void setup()
{
myservo.attach(7); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and
1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
LDR (light dependent resister)
Bluetooth interface
• Arduino Pins Bluetooth Pins
• RX (Pin 0) ———-> TX
• TX (Pin 1) ———-> RX
• 5V ———-> VCC
• GND ———-> GND
• void setup() {
• pinMode(ledPin, OUTPUT);
• digitalWrite(ledPin, LOW);
• Serial.begin(38400); // Default communication rate of the Bluetooth module
• }
• void loop() {
• if(Serial.available() > 0){ // Checks whether data is comming from the serial port
• state = Serial.read(); // Reads the data from the serial port
• }
• if (state == '0') {
• digitalWrite(ledPin, LOW); // Turn LED OFF
• Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
• state = 0;
• }
• else if (state == '1') {
• digitalWrite(ledPin, HIGH);
• Serial.println("LED: ON");;
• state = 0;
• }
• }
LDR intyerface
• Arduino board
• LDR
• 5V SPDT Relay
• 9V Battery and connector
• Connecting wires
• 100K resistor
code
• int sensorPin = A0; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from
the sensor
void setup()
{
Serial.begin(9600); //sets serial port for communication
}
void loop()
• {
sensorValue = analogRead(sensorPin); // read the value from
the sensor
Serial.println(sensorValue); //prints the values coming from the
sensor on the screen
delay(100);
}
•
Interface relay with Arduino and LDR
/*
• Arduino Beginner's Project - No More Darkness This project allows you to automtically turn ON lights or other devices,
• whenver there isn't sufficient light in a room or environment. It uses an LDR (Light Dependent Resistor) to sense the light intensity. Connections:
• LDR --> One leg to Vcc and the other to both analog pin 0 and to the GND via 100K resistor
• Relay --> Connect one pin of the coil to digital pin 2 and the other to GND.
• */
• void setup() {
• pinMode(2, OUTPUT); //pin connected to the relay
• Serial.begin(9600); //sets serial port for communication
• }
• void loop()
• {
• // read the value from the sensor:
• sensorValue = analogRead(sensorPin);
• Serial.println(sensorValue); //prints the values coming from the sensor on the screen
• if(sensorValue < 700) //setting a threshold value
• digitalWrite(2,HIGH); //turn relay ON
• else
• digitalWrite(2,LOW); //turn relay OFF
• delay(100);
• }
schematic