Start Arduino course 04 - Servos

Similar documents
Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Arduino Lesson 16. Stepper Motors

Arduino Lesson 14. Servo Motors

Arduino Lesson 1. Blink

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

Basic Pulse Width Modulation

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Arduino DUE + DAC MCP4922 (SPI)

Lab 6 Introduction to Serial and Wireless Communication

Arduino project. Arduino board. Serial transmission

IR Communication a learn.sparkfun.com tutorial

Arduino Motor Shield (L298) Manual

Arduino Lesson 4. Eight LEDs and a Shift Register

Experiment 8 : Pulse Width Modulation

Arduino Lesson 13. DC Motors. Created by Simon Monk

INTRODUCTION TO SERIAL ARM

Introduction to Arduino

Lesson 8: Simon - Arrays

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

Three Arduino Challenges to Connect the Logical World with the Physical One. ISTE Philadelphia

Microcontroller Programming Beginning with Arduino. Charlie Mooney

Pulse width modulation

Work with Arduino Hardware

DEPARTMENT OF ELECTRONICS ENGINEERING

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

What s going on over there?

Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor

C4DI Arduino tutorial 4 Things beginning with the letter i

Character LCDs. Created by Ladyada. Last updated on :45:29 PM EDT

Servo Info and Centering

CONTENTS. What is ROBOTC? Section I: The Basics

Arduino Lab 1 - The Voltage Divider

Theory and Practice of Tangible User Interfaces. Thursday Week 2: Digital Input and Output. week. Digital Input and Output. RGB LEDs fade with PWM

Timer A (0 and 1) and PWM EE3376

1 Coffee cooling : Part B : automated data acquisition

Basic DC Motor Circuits. Living with the Lab Gerald Recktenwald Portland State University

Basic DC Motor Circuits

2013 G Miller. 3 Axis Brushless Gimbal Controller Manual

Board also Supports MicroBridge

MCP4725 Digital to Analog Converter Hookup Guide

Current Loop Tuning Procedure. Servo Drive Current Loop Tuning Procedure (intended for Analog input PWM output servo drives) General Procedure AN-015

Home Security System for Automatic Doors

1602 LCD adopts standard 14 pins(no backlight) or 16pins(with backlight) interface, Instruction of each pin interface is as follows:

1 of 5 12/31/ :51 AM

Electronics 5: Arduino, PWM, Mosfetts and Motors

Arduino Lesson 5. The Serial Monitor

Working with microcontroller-generated audio frequencies (adapted from the Machine Science tutorial)

ECE 495 Project 3: Shocker Actuator Subsystem and Website Design. Group 1: One Awesome Engineering

Massachusetts Institute of Technology

Lecture 7: Programming for the Arduino

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Lab 3 - DC Circuits and Ohm s Law

Global Motion Technology Inc Web THCSA200. Capacitive sensor plasma & Oxy-fuel Torch Height Control

SYSTEM 45. C R H Electronics Design

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

Arduino Lesson 9. Sensing Light

Sending an SMS with Temboo

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

H-Bridge Motor Control

The self-starting solar-powered Stirling engine

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Programming the VEX Robot

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

A Description of Pulse Width Modulation Motor Control for Model Locomotives

Chapter 4: Pulse Width Modulation

understanding sensors

Pulse Width Modulation (PWM) LED Dimmer Circuit. Using a 555 Timer Chip

Programming the Arduino

Pulse Width Modulation

Programming LEGO NXT Robots using NXC

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

Analog control unit for mobile robots

Tiny Arduino Music Visualizer

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

EE 472 Lab 2 (Group) Scheduling, Digital I/O, Analog Input, and Pulse Generation University of Washington - Department of Electrical Engineering

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

X8 Option 2 - Technology

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

10 tips for servos and steppers a simple guide

Special Lecture. Basic Stamp 2 Programming. (Presented on popular demand)

Flow Charts and Servomotors (background to Lab #2) Things to learn about: flow charts for design. MECH Lecture #2 flow charts & servos rev2

Introduction to Dynamixel Motor Control Using the ArbotiX-M Robocontroller

Arduino Lesson 0. Getting Started

Building a Basic Communication Network using XBee DigiMesh. Keywords: XBee, Networking, Zigbee, Digimesh, Mesh, Python, Smart Home

SainSmart UNO R3 Starter Kit

4/Really Getting Started with Arduino

Pulse Width Modulation Applications

Hands On ECG. Sean Hubber and Crystal Lu

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

CHAPTER 11: Flip Flops

Greatest Common Factor and Least Common Multiple

Welcome to the tutorial for the MPLAB Starter Kit for dspic DSCs

The DC Motor. Physics 1051 Laboratory #5 The DC Motor

CAN-Bus Shield Hookup Guide

Key Words Student Paper, School of Professional Studies

SYSTEM 4C. C R H Electronics Design

Face Recognition Using Robotics

A REST API for Arduino & the CC3000 WiFi Chip

Transcription:

Introduction: In this session you will look at a piece of equipment called a Servo Motor. This is a type motor used to create really precise movement. Unlike DC (Direct Current) motors, which can only be specified to move forward or backward, Servo motors can specify a position to the degree. Goals Servo motor basics. Access the servo library. Control the Servo with a potentiometer. Page 1 - Start Arduino Course: 04 Servos

The Sensors To use a Servo motor, we need two things, we need to be able to power it and to control it. This means they ll be three connections to our Servo motor: Power, Ground and Control. To control Servos, we actually use the same principle for controlling the brightness of our LEDs Pulse Width Modulation. This works by changing the duty cycle of the square wave, and keeping the frequency the same throughout. Pulse Width Modulation (PWM) 5v 25% Duty Cycle 50% Duty Cycle 5v 0v 0v 5v 75% Duty Cycle 0v 04 - Servos Challenge What does the Arduino Pin have to allow if we want to use a servo with it? What symbol does the Arduino use to identify which pins can do this? Page 2 - Start Arduino Course: 04 Servos

Circuit 4.0 - Servo Hardware For this circuit, we are going to make a Servo motor rotate backwards and forwards. We will be defining the amount of degrees to rotate and how long to pause for between each rotation. For this, we will need: 1x Arduino Uno 1x USB cable 1x Servo motor 6x Jumper Wires Page 3 - Start Arduino Course: 04 Servos

Circuit 4.0 - Servo Code Make a new sketch in the Arduino IDE and name this Servo. To use the servo, there is a lot of complex algorithms and conversions to make sure the servo can make these precise movements, so we re going to use the Servo Library which comes included in Arduinos IDE. To use external library, you have to let the Arduino know you want it included in your sketch. To do this we use the <include> function. //include the Servo library in the sketch #include <Servo.h> //create servo object to control a servo Servo servo1; //variable to store the servo position int pos = 0; void setup() //attaches the servo on pin 9 to the servo object servo1.attach(9); } void loop() //goes from 0 degrees to 180 degrees in steps of 1 degree for (pos = 0; pos <= 180; pos +=1) //tell servo to go to position in variable pos servo1.write(pos); //waits 15 milliseconds for the servo to reach the position delay(15); } //goes from 180 degrees to 0 degrees for (pos = 180; pos >= 0; pos -= 1) //tell the servo to go to position in variable pos servo1.write(pos); //waits 15 milliseconds for the servo to reach the position delay(15); } } Page 4 - Start Arduino Course: 04 Servos

Circuit 4.0 - Servo Code Once you have copied the code, press (upload) and watch the results! (compile) and if no errors appear, press At this stage your servo should be rotating backwards and forwards. My code won t compile! Is everything spelt correctly? Are all your lines ending in a semi-colon? Do you have the correct capital letters? Did you close the curly brackets? Let s go through the code understand what every part is doing. Libraries #include <Servo.h> This is how we include the Arduino Servo Library. This makes it possible to use pre-defined functions in our projects that make using the Servo motors and Arduino easier. Servo Object Servo servo1; This is how we make our Servo Object. This allows us to use the library functions. We will now refer to our servo as servo1. Global Variables int pos = 0; These are our global variables for storing the Servo position and Servo pin. This means we can easily keep track of the position and the digital pin we are using for controlling the Servo. These are created outside void setup and void loop so they are accessible in both. void setup() void setup() This is our void setup(). We use curly brackets to define what happens in the setup of our program. This function is called once. Page 5 - Start Arduino Course: 04 Servos

servo1.attach(9); Our Servo needs to be attached to the digital pin we are using to control it. We set this using the number stored in variable servo_pin. This called in void setup() as it only needs to called once. void loop() void loop() This is our void loop(). This is where our main loop for our program happens. We set everything inside void loop() by using curly brackets. Everything within these brackets will loop infinitely. for loop (forwards) //goes from 0 degrees to 180 degrees in steps of 1 degree for (pos = 0; pos <= 180; pos +=1) //tell servo to go to position in variable pos servo1.write(pos); //waits 15ms for the servo to reach the position delay(15); This is our for loop for moving our servo forwards. We use normal brackets to set how many times to loop through everything within our curly brackets. In this instance, we increment the variable pos by 1 until it reaches 180. Everytime we increment pos, we use Servo library function write(). Variable pos is then used to set the Servo Position. We use delay() with a value of 15 to pause the loop for 15 milliseconds. This gives the Servo time to reach it s position. for loop (backwards) //goes from 180 degrees to 0 degrees for (pos = 180; pos >= 0; pos -= 1) //tell the servo to go to position in variable pos servo1.write(pos); //waits 15ms for the servo to reach the position delay(15); This for loop is for moving our Servo position backwards. This works exactly the same as the previous for loop, but instead of moving from 0 to 180, it sets the Servo Position from 180 to 0. This loop happens after the first, so variable pos can first reach 180, then will decrease to 0. Page 6 - Start Arduino Course: 04 Servos

Circuit 4.0 - Servo Challenge How would you change the speed of your Servo? What happens when we remove the delay in our for loops? Why? What other digital pins could I use to control a Servo with? How do we know this? What could you make with your Servo? Page 7 - Start Arduino Course: 04 Servos

Circuit 4.1 - Servo + Potentiometer Hardware Can you try and control the Servo with a potentiometer? For this, we will need: 1x Arduino Uno 1x USB cable 1x Servo motor 8x Jumper Wires 1x Potentiometer Try and work the code out for yourself Remember back to how we read data from a potentiometer, it uses Analog Readings. That means you will need to scale your Analog Input data to the Servo position data. For this you can use the Arduino function map(). This function is an easy way of scaling a value to another range. int outcome - map(int input, int min_input, int max_input, int min_output, int max_output); What is the input? What is the minimum and maximum value the input can have? What is the minimum and maximum value the outcome should have? Page 8 - Start Arduino Course: 04 Servos