LED + Servo 2 devices, 1 Arduino

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

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

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

ABCs of Arduino. Kurt Turchan -

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

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

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

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

Using Servos with an Arduino

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

Pulse Width Modulation and

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?

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

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

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

CONSTRUCTION GUIDE Robotic Arm. Robobox. Level II

Arduino and Servo Motor

The USELESS BOX. Procedure:

Lab 2: Blinkie Lab. Objectives. Materials. Theory

Arduino: Sensors for Fun and Non Profit

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

Lab 2.4 Arduinos, Resistors, and Circuits

Arduino Sensor Beginners Guide

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

Objective of the lesson

HOW TO BUILD A CAR PARK WITH INTEL GALILEO!

Lesson 3: Arduino. Goals

Lesson4 Obstacle avoidance car

Two Hour Robot. Lets build a Robot.

Assignments from last week

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

Lab 06: Ohm s Law and Servo Motor Control

Arduino Lesson 1. Blink. Created by Simon Monk

FABO ACADEMY X ELECTRONIC DESIGN

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

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

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

Internet of Things Student STEM Project Jackson High School. Lesson 3: Arduino Solar Tracker

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

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

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

Arduino Setup & Flexing the ExBow

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Project 27 Joystick Servo Control

1. Controlling the DC Motors

Robotic Arm Assembly Instructions

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

Lecture 4: Basic Electronics. Lecture 4 Brief Introduction to Electronics and the Arduino

Analog Feedback Servos

The Motor sketch. One Direction ON-OFF DC Motor

Part (A) Using the Potentiometer and the ADC* Part (B) LEDs and Stepper Motors with Interrupts* Part (D) Breadboard PIC Running a Stepper Motor

Using Transistors and Driving Motors

Control Robotics Arm with EduCake

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

EET 1150 Lab 6 Ohm s Law

PLAN DE FORMACIÓN EN LENGUAS EXTRANJERAS IN-57 Technology for ESO: Contents and Strategies

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

Arduino Advanced Projects

Workshop 9: First steps in electronics

Arduino Digital Out_QUICK RECAP

Project #6 Introductory Circuit Analysis

Arduino An Introduction

Sunday, November 4, The LadyUno Sound Unit

Basic Electronics Course Part 2

Name & SID 1 : Name & SID 2:

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Lets start learning how Wink s bottom sensors work. He can use these sensors to see lines and measure when the surface he is driving on has changed.

Breadboard Primer. Experience. Objective. No previous electronics experience is required.

CONSTRUCTION GUIDE Light Robot. Robobox. Level VI

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

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

Lecture 6. Interfacing Digital and Analog Devices to Arduino. Intro to Arduino

// Parts of a Multimeter

TWEAK THE ARDUINO LOGO

INTRODUCTION to MICRO-CONTROLLERS

MATERIALS TO GATHER. Electronic Parts

Experiment 1: Robot Moves in 3ft squared makes sound and

Build a Mintronics: MintDuino

Check out from stockroom:! Servo! DMM (Digital Multi-meter)

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

Sidekick Basic Kit for Arduino V2 Introduction

CPSC 226 Lab Four Spring 2018

URM37 V3.2 Ultrasonic Sensor (SKU:SEN0001)

INTRODUCTION to MICRO-CONTROLLERS

INTRODUCTION to MICRO-CONTROLLERS

Microcontrollers and Interfacing

WEEK. Learning Objective. Materials to Prepare LESSON

Understanding the Arduino to LabVIEW Interface

Blink. EE 285 Arduino 1

Lab 5: Arduino Uno Microcontroller Innovation Fellows Program Bootcamp Prof. Steven S. Saliterman

DC Motor and Servo motor Control with ARM and Arduino. Created by:

LEDs and Sensors Part 2: Analog to Digital

Figure 1. Digilent DC Motor

Part 1. Using LabVIEW to Measure Current

Internet of Things Student STEM Project Jackson High School. Lesson 2: Arduino and LED

Experiment 4.B. Position Control. ECEN 2270 Electronics Design Laboratory 1

DC Motors. come in all shapes and sizes. You probably have 3-4 on you right now. the two motors in the kit

Transcription:

LED + Servo 2 devices, 1 Arduino Learn to connect and write code to control both a Servo and an LED at the same time. Many students who come through the lab ask if they can use both an LED and a Servo on their projects. While this is not something we typically allow in a short building time, it is something that is possible with a bit of coding and a few more wires. Arduino Breadboard (large or small, I used large) 1 LED 2 red wires 1 resistor (100 300 ohms) 2 black wires 1 Servo (I used a full rotation Servo, but you could also use a regular Servo) 1 white wire

1. We ll start by connecting our wires and we ll focus on connecting the Servo first. First, connect a red wire from 5V on the Arduino to the red connection of the Servo. 2. Next, connect a black wire from GND to the black connection of the Servo.

3. Next, connect a white wire from Pin 9 to the white connection of the Servo (mine is yellow instead of white). 4. Now that the Servo is connected, we can focus on the LED. Connect a red wire from Pin 13 to the positive rail on the breadboard (or the red row).

5. Next connect a black wire from GND to the negative rail (or the black row). 6. Next, we need a resistor to make sure we don t burn out our LED. Connect the resistor from the positive rail (or the red row) to another row (I used row 17 or you could use the blue row).

7. Lastly, connect the LED. The long leg (positive) will go in the same row as the resistor (17 for me, maybe blue for you) and the short leg (negative) will go in the negative rail (or black row). 1. Start by opening Arduino and deleting the text to start with a blank document. Don t forget to select the right port! It may be tempting to just copy and paste the Servo code and LED Blink code into one document, and that is essentially what this looks like, but there are some details that I think it is better if we go over slowly.

2. Whenever we use a Servo, we need to include the Servo library. To do this, go to Sketch, Include Library, Servo. This will bring up #include <Servo.h>. 3. Next, we need to name our Servo, just like in the Servo lesson, so again I will call it myservo. Remember, you can name your Servo whatever you want, just be sure to use that name throughout your entire code. 4. We are also going to name our LED. This may be a new term for you. We ll say that the word led refers to the integer number 13. Because 13 is an integer, we call this an int.

5. Now that we have defined our variables, we re ready to do our setup. Because we are using 2 devices, a Servo and an LED, we need to setup both. These two lines are very similar to the setups of the Servo and LED Blink code but all in one setup since you can only have 1 setup per sketch. 6. Next we can write our loop. As I said before, it may be tempting to copy and paste the 2 codes together. If you tried that you would end up with the following: void loop() { delay(1000); //wait 1 second delay(1000); //wait 1 second myservo.write(0); //spin the big servo to the left delay(2000); myservo.write(180); //spin the big servo to the right delay(2000); } Although this will work, it will not have the desired effect on your LED and Servo. The LED will turn on, stay on for a second, then turn off, but because it runs through all the lines of code before starting over from the top, the light will stay off for 5 seconds (1000 + 2000 + 2000). Same thing with the Servo. It will start out not moving, then will spin to the left for 2 seconds and then to the right for 4 seconds (2000 + 1000 + 1000). If you want the light to blink on and off every second and the Servo to change directions every second, you will need to do both actions (for the LED and the Servo) before each delay. It should look like the code below.

Congratulations! You should now have an LED Blinking and a Servo spinning back and forth in unison. Feel free to change the delay or make the Servo spin slower by changing the value in myservo.write( ); (see Programming a Servo for more information). If you re having issues with your code, review all the lines of code in my example code to make sure you didn t miss something or refer to the Troubleshooting document for more help. If your LED is not working, be sure that all of your connections have been made properly and then try a different LED. If your Servo is not working, make sure that all of your wires are in the correct pins and that the red black and white wires are in the right order on the servo attachment. If that looks correct, you may want to try another Sevro.

I m going to give you some other combinations of blinking and spinning that I d like you to try to figure out on your own as challenge problems. The solutions are posted below, but try doing them yourself first. 1. Try to make your LED continue to blink at the same rate (on for 1 second, then off for 1 second) and have your Servo spin only one way (instead of both ways)? This would allow you to change the rate of the blinking without changing the motion of the Servo. 2. Try to make your LED Blink fast (say a delay of 100) and your Servo spin both ways for 1 second each direction? 3. Try to incorporate the LED Fade code with a Servo? You may want to start by having the Servo only spinning one way and then try to have it change directions with the rate of the fade. Note: For most of these challenges I only posted the loop since the variables and setup are the same. I also posted comments that you do not need to write into your code. Challenge 1 Solution: void loop() { myservo.write(0); //spin the big servo to the left delay(1000); //wait 1 second delay(1000); //wait 1 second } You can always change the delay to be longer or shorter. This will change the rate at which your light blinks, but because you only told your Servo to spin to the left and never gave any other directions it will continue to spin to the left no matter the value of the delay. Challenge 2 Solution: We need to have the delay for the servo be longer than the delay for the LED, but we can t treat them like separate things because the delay makes the entire program wait. So the loop should look something like this: void loop() { myservo.write(0); //spin the big servo to the left delay(100); //servo delay = 100 delay(100); //servo delay = 200 delay(100); //servo delay = 300 delay(100); //servo delay = 400 delay(100); //servo delay = 500

} delay(100); //servo delay = 600 delay(100); //servo delay = 700 delay(100); //servo delay = 800 delay(100); //servo delay = 900 delay(100); //servo delay = 1000 myservo.write(180); //spin the big servo to the right delay(100); //servo delay = 100 delay(100); //servo delay = 200 delay(100); //servo delay = 300 delay(100); //servo delay = 400 delay(100); //servo delay = 500 delay(100); //servo delay = 600 delay(100); //servo delay = 700 delay(100); //servo delay = 800 delay(100); //servo delay = 900 delay(100); //servo delay = 1000 If you wanted the servo to spin longer, then you would need to add more of the on/off lines in between telling it different positions. Remember that using copy (Ctrl + C) and paste (Ctrl + V) is very helpful if you are repeating lines of code over and over again. Challenge 3 Solution: I started with the LED Fade example and then added in the Servo code to make the Servo spin only one way. Making the Servo change directions is a harder task, but may be easier once you complete Servo Sweep Challenge #2 #include <Servo.h> Servo myservo; int led = 11; int brightness = 0; int fadeamount = 5; void setup() { myservo.attach(9); pinmode(led, OUTPUT); }

void loop() { myservo.write(0); analogwrite(led, brightness); brightness = brightness + fadeamount; if (brightness == 0 brightness == 255) { fadeamount = -fadeamount ; } delay(30); }