Sunteți pe pagina 1din 29

SERVO motor interface

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>

Servo myservo; // create servo object to control a servo


int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

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

• Connect a LED negative to GND of arduino and


positive to pin 13 with a resistance valued
between 220Ω – 1KΩ. And your done with the
circuit
schematic
• Pair your device with HC
05/06 Bluetooth module1) Turn ON HC
05/06 Bluetooth module2) Scan for available
device3) Pair to HC 05/06 by entering default
password 1234 OR 0000
• Install LED application on your android device
• Open the Application
• Press paired devices
• Select your Bluetooth module from the
List (HC 05
• After connecting successfully
• Press ON button to turn ON LED and OFF
button to turn OFF LED
Code to dump
• /*
• * Bluetooh Basic: LED ON OFF - Avishkar
• * Coder - Mayoogh Girish
• * Website - http://bit.do/Avishkar
• * Download the App : https://github.com/Mayoogh/Arduino-Bluetooth-Basic
• * This program lets you to control a LED on pin 13 of arduino using a bluetooth module
• */
• char data = 0; //Variable for storing received data
• void setup()
• {
• Serial.begin(9600); //Sets the baud for serial data transmission
• pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
• }
• void loop()
• {
• if(Serial.available() > 0) // Send data only when you receive data:
• {
• data = Serial.read(); //Read the incoming data & store into data
• Serial.print(data); //Print Value inside data in Serial monitor
• Serial.print("\n");
• if(data == '1') // Checks whether value of data is equal to 1
• digitalWrite(13, HIGH); //If value is 1 then LED turns ON
• else if(data == '0') // Checks whether value of data is equal to 0
• digitalWrite(13, LOW); //If value is 0 then LED turns OFF
• }
• }
Bluetooth Program 2
http://howtomechatronics.com/tutorials/arduino/arduino-and-hc-05-
bluetooth-module-tutorial/#
• #define ledPin 7
• int state = 0;

• 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.
• */

• int sensorPin = A0; // select the input pin for ldr


• int sensorValue = 0; // variable to store the value coming from the sensor

• 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

S-ar putea să vă placă și