This is the Arduino Uno: This is the Arduino motor shield: Digital pins (0-13) Ground Rail

Similar documents
Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Prototyping & Engineering Electronics Kits Basic Kit Guide

Make your own secret locking mechanism to keep unwanted guests out of your space!

KNOCK LOCK MAKE YOUR OWN SECRET LOCKING MECHANISM TO KEEP UNWANTED GUESTS OUT OF YOUR SPACE! Discover: input with a piezo, writing your own functions

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

Sten-SLATE ESP Kit. Description and Programming

Lab 2.2 Ohm s Law and Introduction to Arduinos

IME-100 ECE. Lab 3. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

Halloween Pumpkinusing. Wednesday, October 17, 12

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

Connecting Arduino to Processing

Lecture 7. Processing Development Environment (or PDE)

Arduino Prof. Dr. Magdy M. Abdelhameed

Thumb Joystick Retail. Tools and parts you'll need. Things you'll want to know. How does it work? Skill Level: Beginner. by MikeGrusin March 22, 2011

Arduino IDE Friday, 26 October 2018

Introduction To Arduino

RoastLogger Arduino/TC4 driver installation for Windows 9/10/13 By John Hannon (JackH) at Homeroasters.org

micro:bit Lesson 2. Controlling LEDs on Breadboard

4Serial SIK BINDER //77

keyestudio Keyestudio MEGA 2560 R3 Board

Arduino Programming and Interfacing

<Table of content> <Parts and description> <Circuit board Guide> <Pins> <Basics of Coding> <Intro to Arduino> <Intro> <Downloading Arduino IDO>

Adafruit DS3231 Precision RTC Breakout

Create your own wireless motion sensor with

Introduction to Programming. Writing an Arduino Program

Robot Eyes. DAY 3 Let's Make a Robot

University of Hull Department of Computer Science C4DI Interfacing with Arduinos

Objectives: Learn how to input and output analogue values Be able to see what the Arduino is thinking by sending numbers to the screen

Serial.begin ( ); Serial.println( ); analogread ( ); map ( );

Introduction to Arduino (programming, wiring, and more!)

The Big Idea: Background: About Serial

Lab 4 - Asynchronous Serial Communications

TA0139 USER MANUAL ARDUINO 2 WHEEL DRIVE WIRELESS BLUETOOTH ROBOT KIT

MAKE & COLLABORATE: SECRET KNOCK LOCK

Introduction to Arduino

Robotics/Electronics Review for the Final Exam

TA0013 ARDUINO RFID UNO STARTER KIT

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

Building your own special-purpose embedded system gadget.

Basic Electronic Toolkit for under $40

Robotics Adventure Book Scouter manual STEM 1

Create moving images in forward and reverse with your Arduino when you connect a motor to an H-bridge and some still images BATTERY POTENTIOMETER

Procedure: Determine the polarity of the LED. Use the following image to help:

Touch Board User Guide. Introduction

Lab 4: Interrupts and Realtime

Counter & LED (LED Blink)

Monitor your home remotely using the Arduino

Connecting Arduino to Processing a

Smart Objects. SAPIENZA Università di Roma, M.Sc. in Product Design Fabio Patrizi

USB Type A Female Breakout Hookup Guide

Digital Pins and Constants

Development Routines of TF LiDAR on Arduino

1/Build a Mintronics: MintDuino

How to use the Zduino LEE Module with the Trainer Board

Physics 120/220. Microcontrollers Extras. Prof. Anyes Taffard

Arduino 05: Digital I/O. Jeffrey A. Meunier University of Connecticut

Lab 0: Wire Wrapping Project: Counter Board

Light Dependent Resistor Circuit by VK4ION

Index. Jeff Cicolani 2018 J. Cicolani, Beginning Robotics with Raspberry Pi and Arduino,

Experiment 4.A. Speed and Position Control. ECEN 2270 Electronics Design Laboratory 1

Necessary software and hardware:

Arduino Lesson 15. DC Motor Reversing

IME-100 Interdisciplinary Design and Manufacturing

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

Goal: We want to build an autonomous vehicle (robot)

Bill of Materials: Turn Off the Lights Reminder PART NO

Arduino Package Tracker

Ardusat Space Kits in the Classroom

This tutorial will show you how to take temperature readings using the Freetronics temperature sensor and an Arduino Uno.

IME-100 ECE. Lab 4. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

Random Spooky LED Eyes

The ICU-Duino Arduino Shield!

Rotary Encoder Basics

IR Breakbeam Sensors. Created by lady ada. Last updated on :32:59 PM UTC

Rover 5. Explorer kit

Strain gauge Measuring Amplifier GSV-1A8. Instruction manual GSV-1A8, GSV-1A8USB, GSV-1A16USB

Arduino Micro Breadboard Laboratory Interface Processor (Micro BLIP) User Manual

Freeduino USB 1.0. Arduino Compatible Development Board Starter Guide. 1. Overview

AndyMark Arduino Tutorial

A Hacker s Introduction to the Nokia N900

Hardware Overview and Features

HUB-ee BMD-S Arduino Proto Shield V1.1

ZX Distance and Gesture Sensor SMD Hookup Guide

LilyPad ProtoSnap Plus Hookup Guide

inches Hardware Guide For Intel Galileo

Arduino 07 ARDUINO WORKSHOP 2007

RS422/RS485 Shield. Application Note: Multiple RS485 busses. 1 Introduction

Workshop Arduino English starters workshop 2

For reference purposes, you can still find all documents (past and current):

ECE 2036 Lab 4 Setup and Test mbed I/O Hardware Check-Off Deadline: Thursday, March 17, Name:

Introduction to Arduino Diagrams & Code Brown County Library

Lab-3: LCDs Serial Communication Analog Inputs Temperature Measurement System

THE COMPLETE ALL IN ONE ROBOT 360 NANO BOT

Lab 4: Determining temperature from a temperature sensor

Introduction to Arduino Diagrams & Code Brown County Library

Transcription:

Reacting to Sensors In this tutorial we will be going over how to program the Arduino to react to sensors. By the end of this workshop you will have an understanding of how to use sensors with the Arduino and create an interactive sculpture. This is the Arduino Uno: USB Port Power Socket Motor Shield Arduino This is the Arduino motor shield: Digital pins (0-13) Bread Board 5V Rail Arduino Proto Shield Ground Rail Analog pins (0 5) Digital pins (14 19) The Proto shield is a bare white board that gives us access to a bread board. It also has a 5V and GND rail. We can use these to easily wire up sensors without soldering. 1

Reacting to Sensors / Arduino IDE This is the Arduino Software, called the IDE (Integrated development environment) Verify: Check code for errors New: Open new file Save: Save current file Upload: Put code on to your Arduino Open: Open a saved file Serial Monitor: Read and write data to and from your Arduino Editor: Where you can type your code Console: Notifies you of any errors when compiling or uploading The line inside the editor that your cursor is on Type of Arduino and on what serial port it is connected to With this computer program you will be able to write code and upload it to the Arduino Uno. By following these steps you will have your Arduino driven sculpture set up in no time. All the while we encourage you to explore and play with the provided code 2

Reacting to Sensors / Starting your program Open the Arduino IDE that was illustrated earlier. An icon like the one on the right here should be on your desktop. If not, navigate to where programs are generally installed or ask your instructor for assistance. Once open navigate to File and Save As, giving your program a unique name. It can be ReactingToSensors, KnightRider or whatever you like. Before we continue navigate to Sketch and then Include Library. At the very bottom of the next drop down list you should find a library named Artbotics. If not please ask you instructor for assistance. The top left of the IDE, just above the Editor; you should see a tab with the name of your file. Underneath that at the top of the Editor you should see. This line imports the Artbotics library of commands to be used in your program. It gives you access to objects with prewritten code that will make driving the car easier. Make sure to go back and do the previous step if you don t see this or else you will run into trouble later on. 3

Reacting to Sensors / Button 1 Follow these steps to wire your button/ switch to your Arduuino Step 1 Step 2 Step 3 Step 1: Take the yellow wire and plug it into the same column on the breadboard as your switch and the other end into digital pin 7 Step 2: Take the red wire from the button and plug it into 5v Take the black wire from the button and plug it into the breadboard Step 3: Take the resistor and plug it into the same column on the breadboard as your switch and plug the other end into GND The line Button button(7) is an object that lets you use a button or switch. The number that is being passed (7) refers to the pin on the Arduino where the button will be plugged into. A Motor object was also added to control the motor on terminal A. Button button(7); void setup() void loop() 4

Reacting to Sensors / Button 2 Button button(7); Now update your void loop() function to match the code on the right. If statement If block void setup() void loop() if(button.getbuttonstate()) Inside the void loop() function is if(button.getbuttonstate()), this is referred to as an if statement. It creates conditions that determine when certain pieces of code will execute. If statements generally take on this form: if(boolean statement)code to execute if true Boolean statements are logic statements that can only be, true(high) or false(low). For example, if(3 > 2)True code to execute, 3 is obviously greater then 2, making this statement true, so the code within the curly braces will be executed. Any code following the if block will always be executed but code inside the if block (shown above within the curly braces ) will only execute when the if statement is true. The condition that is being used for the if statement is button.getbuttonstate(). It will return true if the button is being pressed, or false if the button is not being pressed. In the following code example, the code in the if block will be executed when the if statement reads that the button is being pressed. If the button is not being pressed the if statement will skip the code inside the if block. 5

Reacting to Sensors / Button 3 Update your code to match what is shown on the right. Button button(7); void setup() When the button is pressed a sequence of instructions can be written to rotate a motor with various duration, power, and direction settings. void loop() if(button.getbuttonstate()) motora.rotate(2, 2, HIGH); motora.rotate(2, 2, LOW); Duration Power Direction Now that you have your button wired and your code set up press the verify button to compile your code. Plug the USB cable into the Arduino, then press the upload button. When the IDE is finished uploading the program, unplug the USB cable from the Arduino and continue. While the program is running the motor should rotate twice when you press the button. 4 Follow these steps to wire your range sensor to the Arduino Plug the red wire from the range sensor into 5V, black into GND, and yellow into analog pin 2 (A2) 6

Reacting to Sensors / Range Sensor 5 To use a sensor (rather than a button) a value must be reached to trigger it. For example, a range sensor might give a value of around 400 when an obstacle is a foot away from its emitter. So in that case you would use 400 as the trigger value. To check the trigger value of your sensor go back to the IDE and create a new program. Go to File and New, then File and Save As, naming the file whatever you like. Make sure to include the Artbotics library under Sketch and Include Library. Update your code to match what is shown on the right. Sensor is another object in the Arbotics library, and it only requires one Argument, the analog pin 2 (A2). Analog pins are different from digital pins since they can take a range of values as opposed to digital which will only take LOW or HIGH. Sensor rangesense(a2); void setup() void loop() Update your code to match what is shown on the right. In the void setup() function, Serial is an object which will allow you to communicate with the Arduino. Serial.begin() is a function that sets up the Arduino to transmit data over the USB port. 9600 is the transfer rate for sending data. Sensor rangesense(a2); void setup() Serial.begin(9600); void loop() Update your void loop() function to match what s shown on the right. print is a common function used to print data out to a console. Serial can print anything to the console for example Serial.print( Hello World ); would print hello world each time the instruction was called. Instead print will print out the value from rangesense.getreading(); which is a function that will return an integer between 0 and 1023 based on the distance of an object in front of the sensor. Sensor rangesense(a2); void setup() Serial.begin(9600); void loop() Serial.print(rangeSense.getReading()); Serial.print("\n"); delay(500); delay() is just being used to keep the function call Serial.print from flooding the Serial console since it will be running in a loop very quickly otherwise. Note: Serial.print("\n"); is printing "\n", this is an Escape Character used to tell the console to start printing on the next line ( \n = new line, \t = tab, ) 7

Reacting to Sensors / Range Sensor 6 Press the verify button to compile your code. Plug the USB cable into the Arduino, then press the upload button. When the IDE is finished uploading the program leave the USB cable plugged into the Arduino and continue. With your code uploaded and the USB cable still plugged into the Arduino hit the Serial Monitor button. This will open a console that will start listing numbers every half second. The numbers correspond to the values of the range sensor. Note: Choose the 9600 baud, as that is what reflects in our code Place your hand in front of the sensor until it is about 1 foot away. Write down a rough estimate of the value that you see. It should be approximately 300. This number may vary depending on battery life. The number should increase as you move your hand closer, and decrease as you move your hand further away. Update your void loop() and void setup() functions to match what is shown on the right. In the if statement the boolean statement is rangesense.getreading() >= 300. Whenever the sensor reads a value greater than or equal to 300 it will return true and turn the motor on for 2 seconds at a time. If it continues to read a value of 300 or higher than the motor should continuously spin. #include<artbotics.h> Sensor rangesense(a2); void setup() voidloop() if(rangesense.getreading() >= 300) motora.rotate(2, 3, HIGH); Press the verify button to compile your code. Plug the USB cable into the Arduino, then press the upload button. When the IDE is finished uploading the program, unplug the USB cable from the Arduino and continue. Switch the power pack on the Arduino on and pass your hand over the sensor. The motor should turn on for at least 2 seconds after waving your hand over the sensor. 8

Driving and Drawing / Light Sensor 7 Follow these steps to wire your light sensor to the Arduino note: image not to scale Step 2: Take the red wire from the light sensor and plug it into 5v Take the black wire from the light sensor and plug it into the breadboard. Step 2 Step 3 Step 1: Connect black and red alligator clips to the light sensor s terminals. Step 3: Take the resistor and plug it into the same column on the breadboard as your light sensor and plug the other end into GND Step 4 Step 4: Take the yellow wire and plug it into the same column on the breadboard as your light sensor and the other end into Analog pin 2 Open a new file by going to File and New, then go to File again and Save As, typing whatever you like for the name. Update your code to resemble what is shown on the right. Sensor lightsensor(a2); is the object that will read values from the light sensor that you hooked up to analog pin 2 (A2). In the function void loop(), the print call on the Serial object will be used to read the values from the light sensor to find it s trigger value. #include<artbotics.h> Sensor lightsensor(a2); void setup() Serial.begin(9600); void loop() Serial.print(lightSensor.getReading()); Serial.print("\n"); delay(500); Press the verify button to compile your code. Plug the USB cable into the Arduino, then press the upload button. When the IDE is finished uploading the program unplug the USB cable from the Arduino and continue. 9

Driving and Drawing / Light Sensor 8 With the USB cable still plugged into the Arduino hit the Serial Monitor button. This will open a console that will start listing numbers every half second. The numbers correspond to the values of the light sensor. Note: Choose the 9600 baud, as that is what reflects in our code Now cover the sensor with your hand such that very little light is on it. Take a note of the approximate value you are reading and continue. The value should increase as it gets lighter and decrease as it gets darker. Update your void loop() and void setup() functions to match what is shown on the right. Replace 100 with the value you obtained on the previous step. Sensor lightsensor(a2); void setup() void loop() if(lightsensor.getreading() <= 100) motora.rotate(2, 150, HIGH); Press the verify button to compile your code. Plug the USB cable into the Arduino, then press the upload button Shown above. When the the Artbotics IDE is finished library uploading was not added the Missing program, to our #include code. unplug You <Artbotics.h> the will USB get cable an error from inside the Arduino the and continue. console that says car was not declared in this scope inside the void loop() function. Add to the top of your code. Remember, Car is an object or Switch prewritten the power code. In pack order of the to access Arduino that on code and cover we need the to light include sensor it. with using your #include hand. The motor should turn <libraryname.h> on and stay on for at least 2 seconds after removing your hand from over the sensor. 10