Programming a Servo. Servo. Red Wire. Black Wire. White Wire

Similar documents
Programming 2 Servos. Learn to connect and write code to control two servos.

LED + Servo 2 devices, 1 Arduino

Servo Sweep. Learn to make a regular Servo move in a sweeping motion.

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

Coding with Arduino to operate the prosthetic arm

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

100UF CAPACITOR POTENTIOMETER SERVO MOTOR MOTOR ARM. MALE HEADER PIN (3 pins) INGREDIENTS

Using Servos with an Arduino

Learning Objectives. References 10/26/11. Using servos with an Arduino. EAS 199A Fall 2011

FABO ACADEMY X ELECTRONIC DESIGN

CONSTRUCTION GUIDE Robotic Arm. Robobox. Level II

A servo is an electric motor that takes in a pulse width modulated signal that controls direction and speed. A servo has three leads:

Parts List. Robotic Arm segments ¼ inch screws Cable XBEE module or Wifi module

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Rodni What will yours be?

Arduino: Sensors for Fun and Non Profit

Lesson4 Obstacle avoidance car

Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink

Setup Download the Arduino library (link) for Processing and the Lab 12 sketches (link).

Arduino and Servo Motor

Assignments from last week

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

Lab 2: Blinkie Lab. Objectives. Materials. Theory

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

Computational Crafting with Arduino. Christopher Michaud Marist School ECEP Programs, Georgia Tech

URM37 V3.2 Ultrasonic Sensor (SKU:SEN0001)

ABCs of Arduino. Kurt Turchan -

Arduino Setup & Flexing the ExBow

Arduino STEAM Academy Arduino STEM Academy Art without Engineering is dreaming. Engineering without Art is calculating. - Steven K.

Attribution Thank you to Arduino and SparkFun for open source access to reference materials.

Peek-a-BOO Kit JAMECO PART NO / / Experience Level: Beginner Time Required: 1+ hour

Arduino. AS220 Workshop. Part II Interactive Design with advanced Transducers Lutz Hamel

Lesson 3: Arduino. Goals

D - Robot break time - make a game!

The USELESS BOX. Procedure:

Arduino Control of Tetrix Prizm Robotics. Motors and Servos Introduction to Robotics and Engineering Marist School

Objective of the lesson

Control Robotics Arm with EduCake

Workshops Elisava Introduction to programming and electronics (Scratch & Arduino)

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

4WD Mobile Platform SKU:ROB0022

CURIE Academy, Summer 2014 Lab 2: Computer Engineering Software Perspective Sign-Off Sheet

Figure 1. Digilent DC Motor

Create Your Own World

1. Controlling the DC Motors

Lab 06: Ohm s Law and Servo Motor Control

Welcome to Arduino Day 2016

Operating Mode: Serial; (PWM) passive control mode; Autonomous Mode; On/OFF Mode

Arduino Lesson 1. Blink. Created by Simon Monk

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

HOW TO BUILD A CAR PARK WITH INTEL GALILEO!

keyestudio keyestudio Mini Tank Robot

In this project you ll learn how to create a game, in which you have to match up coloured dots with the correct part of the controller.

Demon Pumpkin APPROXIMATE TIME (EXCLUDING PREPARATION WORK): 1 HOUR PREREQUISITES: PART LIST:

A - Debris on the Track

A - Debris on the Track

You'll create a lamp that turns a light on and off when you touch a piece of conductive material

Agent-based/Robotics Programming Lab II

Controlling motors with Arduino and Processing

Yihao Qian Team A: Aware Teammates: Amit Agarwal Harry Golash Menghan Zhang Zihao (Theo) Zhang ILR01 Oct.14, 2016

I.1 Smart Machines. Unit Overview:

The Motor sketch. One Direction ON-OFF DC Motor

Robotic Arm Assembly Instructions

Scratch for Beginners Workbook

Pulse Width Modulation and

UCL Micro:bit Robotics Documentation

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. S4A - Scratch for Arduino Workbook

Module: Arduino as Signal Generator

Understanding the Arduino to LabVIEW Interface

Two Hour Robot. Lets build a Robot.

CONSTRUCTION GUIDE IR Alarm. Robobox. Level I

Lab 5: Inverted Pendulum PID Control

Disclaimer. Arduino Hands-On 2 CS5968 / ART4455 9/1/10. ! Many of these slides are mine. ! But, some are stolen from various places on the web

1Getting Started SIK BINDER //3

Veyron Servo Driver (24 Channel) (SKU:DRI0029)

TETRIX PULSE Workshop Guide

Name & SID 1 : Name & SID 2:

Some prior experience with building programs in Scratch is assumed. You can find some introductory materials here:

An Introduction to Programming using the NXT Robot:

Lab book. Exploring Robotics (CORC3303)

Arduino Digital Out_QUICK RECAP

ServoDMX OPERATING MANUAL. Check your firmware version. This manual will always refer to the most recent version.

The µbotino Microcontroller Board

Introduction. 1 of 44

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Programmable Control Introduction

Project 27 Joystick Servo Control

Practical Assignment 1: Arduino interface with Simulink

TWEAK THE ARDUINO LOGO

Arduino Workshop 01. AD32600 Physical Computing Prof. Fabian Winkler Fall 2014

Analog Feedback Servos

Design with Microprocessors Year III Computer Science 1-st Semester

Motors and Servos Part 2: DC Motors

Getting Started with the micro:bit

Arduino An Introduction

A - Debris on the Track

CNC Router Parts CNC Router Parts 2.2 kw Plug and Play Spindle / VFD System CRP800 Set Up Guide

Using Transistors and Driving Motors

The plan... CSE 6324 From control to actuators Michael Jenkin Office Hours: Sherman 1028 Wed 3-4. From the bottom up...

Transcription:

Programming a Servo Learn to connect wires and write code to program a Servo motor. If you have gone through the LED Circuit and LED Blink exercises, you are ready to move on to programming a Servo. A Servo is a motor that is programmable. There are 2 different types of Servos that we use here in the lab, a full rotation (or continuous) Servo and a regular (or position based) Servo. If you purchased a kit online, it may only have come with a regular Servo, but you could buy a full rotation Servo online for around $10 if you wanted one. Arduino Servo Red Wire Black Wire White Wire 1. Start by opening a new sketch and erasing everything that is already there. Also don t forget to connect to the right port!

2. Coding a Servo is actually quite complicated as it needs a very unique signal in order to make it work. However, others before us have made some shortcuts for us to make it a bit easier. They made a library that we can reference Programming that controls our Servo a Servo more easily. To use this library, go to Sketch -> Include Library and find and click on Servo. It should come up on your screen as #include <Servo.h>. This means that we are including the Servo library in this project. 3. Use your arrow key to arrow down so you are on the next line, and then type in Servo myservo;. This names your servo myservo but you really could call it whatever you want. Please note, if you decide to change the name of your servo, be sure to change it everywhere and not just here! 4. Next press Enter twice to move your cursor down, then type in void setup(){ and press enter. When you press enter, a closed bracket should appear at the bottom of the code. These brackets are like hamburger buns, you can decide what you want to put on your burger, but you always need a top and bottom bun. Anything you type between the open bracket and the closed bracket will be part of the setup.

5. Our set up has one line of code, type in myservo.attach(9);. This means that we will attach the signal wire of our servo to pin 9. Keep this in mind later when we go to connect our wires! Note that we use pin 9 because Programming it has the ~ symbol a next Servo to it which means that it generates the PWM signal needed for the Servo. 6. Use your arrow key to arrow down, and then press Enter twice. We want the closed bracket to remain where it is but our cursor to move down the page. 7. Next we will code the action phase of our servo,. Again, once you have typed this in press enter and you will get a closed bracket at the bottom of the page.

8. The last part of the code is the motion. There are 4 lines of code that will make up the action of our servo. The first line, myservo.write(0); tells the big servo to spin fast to the left and tells the small servo to go to 0 degrees. Programming The next line, a delay(2000); Servo tells the Arduino to wait before reading the next line of code (so the big Servo would keep spinning to the left for 2 seconds and the small Servo would stay at 0 degrees for 2 seconds). Next, myservo.write(180); tells the big servo to spin fast to the right and tells the small servo to go to 180 degrees. The last line, delay(2000); again tells the Arduino to wait for 2 seconds before reading the next line of code (so the big Servo would keep spinning to the right for 2 seconds and the small Servo would stay at 180 degrees for 2 seconds. So the value we put in myservo.write( ); tells it the motion to do and the delay( ); essentially tells it how long to do that motion. 9. Once all of your code is written, upload the code to your Arduino. If you get any errors, see troubleshooting below.

1. Connect your wires to Programming your Servo. The red wire a Servo connects to the red wire, the black wire connects to the black wire, and the white wire connects to the white wire. (Remember, the color of the wire helps us to keep things straight. This is especially true with a Servo where the manufacturer has made red to be positive and black to be negative.) Next, connect these wires to the Arduino. Connect the red wire to Vin or 5V (positive), connect the black wire to GND (negative) and connect the white wire to pin 9 (the signal). Note: in my picture the white wire is actually yellow, but they behave the same. You may also have a brown wire instead of a black wire or an orange wire instead of a red wire, but again they behave the same. Your servo should now be moving. Congratulations! If you have multiple Servos, test them and see how the same code affects the different Servos. If you get an error when you upload, download the Troubleshooting document and try to find a solution. Most common problems: missed semicolons, missed brackets, misspelled words, and not connecting to the board. If your code uploads but the servo does not move, check that your wires are all in the right place. Next, check that your setup looks exactly like the code above. Often students change the number in myservo.attach( ); but if you change this value you will need to move your white wire to that number. You also must choose a number that can generate a PWM signal, these are the numbers with the ~ symbol next to them (3, 5, 6, 9, 10, and 11). 1. Try to make your big servo spin to the left for 3 seconds and to the right for 1 second. 2. Try to make your regular servo go to 0 for 1 second, 45 for 1 second, 90 for 1 second, 135 for 1 second, 180 for 1 second, and then back, stopping at each of the above mentioned degrees for 1 second each. For example, 0, 45, 90, 135, 180, 135, 90, 45, 0, etc. 3. Try to make your big Servo spin slow to the left forever.

4. Try a new function, random! In myservo.write( ); type in random(0, 180) and this will give a random value between 0 and 180, meaning that your regular Servo will go to a random degree and your full rotation Servo Programming will spin a random a Servo direction and speed. Keep the delay big enough to see the effect, either 1000 or 2000, or make the delay random too! Note: Only the loop is shown in the solutions below, as the setup and pre-setup are the same for all solutions. Challenge 1 Solution: myservo.write(0); delay(3000); myservo.write(180); Challenge 2 Solution: myservo.write(0); myservo.write(45); myservo.write(90); myservo.write(135); myservo.write(180); myservo.write(135); myservo.write(90); myservo.write(45); Challenge 3 Solution: myservo.write(80); Challenge 4 Solution: myservo.write(random(0,180)); delay(2000);