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

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

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Module: Arduino as Signal Generator

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

Lab 2: Blinkie Lab. Objectives. Materials. Theory

Arduino Lesson 1. Blink. Created by Simon Monk

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

Lesson 3: Arduino. Goals

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

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

Coding with Arduino to operate the prosthetic arm

Welcome to Arduino Day 2016

Part 1: DC Concepts and Measurement

1Getting Started SIK BINDER //3

FABO ACADEMY X ELECTRONIC DESIGN

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

EE 110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Lab 0: Course Introduction

LED + Servo 2 devices, 1 Arduino

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

smraza Getting Start Guide Contents Arduino IDE (Integrated Development Environment)... 1 Introduction... 1 Install the Arduino Software (IDE)...

INTRODUCTION to MICRO-CONTROLLERS

INTRODUCTION to MICRO-CONTROLLERS

Rodni What will yours be?

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

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

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

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

EGG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

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

TWEAK THE ARDUINO LOGO

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

Practical Assignment 1: Arduino interface with Simulink

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

INTRODUCTION to MICRO-CONTROLLERS

Understanding the Arduino to LabVIEW Interface

Pulse Width Modulation and

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

Training Schedule. Robotic System Design using Arduino Platform

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

Milli Developer Kit Reference Application Published on Silver Spring Networks STAGE (

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

Arduino Microcontroller Processing for Everyone!: Third Edition / Steven F. Barrett

LESSONS Lesson 1. Microcontrollers and SBCs. The Big Idea: Lesson 1: Microcontrollers and SBCs. Background: What, precisely, is computer science?

ISSN: [Singh* et al., 6(6): June, 2017] Impact Factor: 4.116

Arduino An Introduction

CPSC 226 Lab Four Spring 2018

Portland State University MICROCONTROLLERS

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

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

Arduino Platform Capabilities in Multitasking. environment.

CONSTRUCTION GUIDE IR Alarm. Robobox. Level I

Application Note AN 157: Arduino UART Interface to TelAire T6613 CO2 Sensor

ASCOM EF Lens Controller

The Motor sketch. One Direction ON-OFF DC Motor

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

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

WEEK. Learning Objective. Materials to Prepare LESSON

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

CONSTRUCTION GUIDE Capacitor, Transistor & Motorbike. Robobox. Level VII

Lab 4 Rev. 1 Open Lab Due COB Friday April 6, 2018

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

Saturday Academy Program

Name & SID 1 : Name & SID 2:

Application Note. Communication between arduino and IMU Software capturing the data

ARDUINO / GENUINO. start as professional. short course in a book. faculty of engineering technology

Using the S5U13781R01C100 Shield Graphics Library with Atmel Studio

Assignments from last week

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

1 Day Robot Building (MC40A + Aluminum Base) for Edubot 2.0

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Lab Timer: Blinking LED Lights and Pulse Generator

Arduino Setup & Flexing the ExBow

Lab 5: Inverted Pendulum PID Control

ZX Distance and Gesture Sensor Hookup Guide

PWM CONTROL USING ARDUINO. Learn to Control DC Motor Speed and LED Brightness

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

CONSTRUCTION GUIDE Robotic Arm. Robobox. Level II

Getting Started with the micro:bit

GETTING STARTED WITH THE MSP430 LAUNCHPAD BY ADRIAN FERNANDEZ, DUNG DANG

Arduino: Sensors for Fun and Non Profit

ARDUINO / GENUINO. start as professional

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

WEEK. Learning Objective. Materials to Prepare. Summary of Class LESSON

Motors and Servos Part 2: DC Motors

Lesson 13. The Big Idea: Lesson 13: Infrared Transmitters

School of Engineering Mechatronics Engineering Department. Experim. ment no. 1

EE 210 Lab Exercise #3 Introduction to PSPICE

Total Hours Registration through Website or for further details please visit (Refer Upcoming Events Section)

Downloading a ROBOTC Sample Program

Application Note AN 102: Arduino I2C Interface to K 30 Sensor

Sten-Bot Robot Kit Stensat Group LLC, Copyright 2013

Security in a Radio Controlled Remote Switch

Lab 13: Microcontrollers II

Touch Potentiometer Hookup Guide

Community College of Allegheny County Unit 4 Page #1. Timers and PWM Motor Control

EGG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

O Reilly Ebooks Your bookshelf on your devices!

BEYOND TOYS. Wireless sensor extension pack. Tom Frissen s

Figure 1. Digilent DC Motor

RUNNYMEDE COLLEGE & TECHTALENTS

Transcription:

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs 10-11 Introduction to Arduino In this lab we will introduce the idea of using a microcontroller as a tool for controlling the output of the circuit based on the digital or analog input to the device, and based on the codes that we can write and compile into the microcontroller. We will use Arduino Uno R3 as an 8-bit and simple microcontroller. In the beginning of the semester students were asked to purchase their Arduino kits which include the Arduino Uno R3 microcontroller, and a box of components and cables, which would allow students to perform Arduino-related experiments both in the lab and at home. The Arduino kit also includes a breadboard for fast and easy circuit assembly. In addition to the kit, students are encouraged to purchase a paperback copy of the book Arduino for Dummies and/or Arduino Projects for Dummies. These books can be obtained online for about $15. For the next two weeks we will be performing experiments (called sketches ) directly out of these books. Arduino for Dummies, by John Nussey (2013) Arduino Projects for Dummies, by Brock Craft (2013) There are a large number of online resources and inexpensive books for Arduino. Once you become familiar with the basic principles of this microcontroller, you can quickly build more sophisticated projects on your own at home. The pin-out of Arduino Uno R3 is shown below: 1

Introduction to Arduino In this lab you will become familiar with the physical attributes of Arduino Uno R3, its various input/output pins and input power and output power ports. During this lab and the next two labs we will only scratch the surface of Arduino s capabilities. These labs are intended to make students familiar with some of the enormous capabilities and applications of microcontrollers. More detailed treatment of the subject will be given in the Microcontrollers course EE 310 for junior EE students. These lab experiments are also intended to make students appreciate the reasons why they are required to take programming courses (in particular C and C++ languages). Finally, the introduction of the Arduino experiments are meant to assist students to have a broader array of choices for selecting their final project for the present introductory course in electronics. As we have mentioned in the past, the one-unit EE110 course is a survey of introductory topics in electronics hardware and due to the limited available time we may not cover any of the topics in great detail. Moreover, the subject of microcontrollers cover both hardware and software. Clearly during the two sessions allocated to this topic we will not be able to cover the programming component of the subject in any great detail. Therefore in order to demonstrate some of the capabilities of the Arduino microcontrollers, we will copy and paste the programming codes from the available sources. In the meantime we will maintain our emphasis on the hardware aspects of the device. Students can take advantage of the huge number of the available online sketches by cutting and pasting or modifying the existing codes. In order to write original codes for specific microcontroller applications, students will need to become more familiar with related programming languages. Today we will download the driver for the device and perform the very simple sketch of making an LED blink. Students can change the blinking speed once they have set up the experiment. The book Arduino for Dummies is an excellent introductory book that explains almost everything a beginner user of Arduino needs to know. The book comes in 20 chapters. Chapter 1: Read this chapter to learn about the background information regarding the Arduino boards. Chapter2: In this chapter various Arduino boards are introduced. Find your way around Arduino UNO R3. Chapter3: Learn how to download and install Arduino driver application. Chapter 4: Download Blinking LED sketch from the Arduino examples of the application and run the experiment. Adjust blinking speed as described at the end of this experiment. Chapters 5-8: These chapters provide some basic reading material about electricity and circuitry. Students should be familiar with most of these topics. However, reading the material would be a good review for the beginners. Chapter 5: Tools of the Trade 2

Chapter 6: A primer on Electricity and Circuitry Chapter 7: Inputs, Outputs and Communication Chapter 8: Motion and Sound; Using Motors For a very basic understanding of Arduino, students are encouraged to read the first 8 chapters of the book. Your instructor will describe how to download the driver onto your laptop computers and perform the Blinking LED sketch. For a better understanding of Arduino, students are also encouraged to perform the following experiments at their own pace at home: 1. Using Pulse Width Modulation 2. LED Fade Sketch 3. Button Sketch 4. Analog Input Sketch 5. Digital Read Serial Sketch 6. Analog Out Serial Sketch 7. Spinning a DC Motor 8. Motor Speed Control Sketch Experiments 7 and 8 involve motors. Clearly, the micro controller is not configured to deliver the necessary current for running a motor. It is therefore necessary to use a relay or a transistor switch for this purpose. Students will learn to integrate the use of an npn transistor in driving a DC motor. The Arduino kits also include stepper motors. However, the use of stepper motors are outside of the scope this course and students are encouraged to do sketches involving stepper motors on their own. Introduction to Arduino Installation and Programming You will connect your Arduino to your laptop using a USB cable and download the application software. The USB connection provides both power to your Arduino and you can send and receive data through the serial port. The Arduino board is able to recognize if you are receiving power from a computer USB, battery, or an external power supply. In order to use the board without connecting to a computer, you will connect it to a 7-12 V DC power supply through the barrel connector. Alternatively you can use the power input pins (below POWER label) to supply power to the board. The power wires are inserted into V and GND pins to supply 7-12 DC Volts. Connecting higher voltages is not recommended. The serial USB port may be used for programming, debugging, reporting data to other programs your computer, and communicating with the Internet. The Integrated Development Environment of Arduino (IDE) is displayed by the IDE control menu (see the image below). At the top right of the screen you see a magnifying glass icon. Clicking on this icon will open a window that displays the serial communication channel that the Arduino is using. Once programmed, the Arduino will print statements to this window. The serial monitor and 3

communication window is usually used for displaying data from sensors and for debugging purposes. The programming code is entered in the script editor window and then compiled. If no errors detected, then it is uploaded to the board. The New Sketch, Open Sketch and Save Sketch buttons function as usual. To download the Arduino application program to your computer visit the following Arduino sites. Windows Computers Visit https://www.arduino.cc/en/guide/windows or search online Mac OS Visit https://www.arduino.cc/en/guide/macosx or search online Understanding Arduino Code As we mentioned before, in the next couple of experiments is to cover the basics and become familiar with the Arduino environment. We will tweak some parts of the codes and monitor the outcome of the changes. Students can use the available resources to learn to write more advanced codes on their own. The following categories of codes are commonly used in Arduino programming. Comments; Libraries; Variable declarations; Setup; Loop; User-defined functions Comments: In the comments section you describe what the code is supposed to do. Libraries: You need to select which library folder you intend to use. Variable Declarations: Specify the variables you intend to use and their initial values. 4

Setup: Here you define how the Arduino will be used and define/setup pins and communications. The word void appears before Setup. The code is written after the open curly bracket { and it is always concluded by closing the bracket }. Loop: This is where you place the main instructions for your code. The loop is executed after setup. Any code between the curly brackets { } is processed sequentially and then repeated again for as many times as the user wishes. User-defined functions: These are created by the user who wishes them to perform certain specific tasks. Note that after the code is uploaded into Arduino, it may not be retrieved. Therefore, it is important to be organized and keep a record of your codes and sketches. Blink Sketch This is a very simple practice sketch that you will use to become familiar with the basic concepts of Arduino. From the application menus choose File à Examples à Basics à Blink and load this demo sketch. The code is shown in the following figure. Comments consisting of several lines start after /* and are concluded with */. Single line comments are written after // and at the end concluded with ;. You will be reminded by Arduino compiler if you make a syntax error. 5

The Blink sketch is already installed in your device. When you power up your device you will notice a blinking LED which is labeled L and is located to the right of the Label AREF. The blinking LED indicates that your board is working properly. However, here we will use this very simple code to understand a few basic concepts. Note 1: Your computer needs to know what kind of Arduino board you are using. From the IDE menu choose Tools à Board and then select the board you are using. Note 2: You will need to specify the port that your Arduino is connected to. Choose Tools à Serial port. After you have selected your board and serial port, then you can click on the upload button. You will see two KEDs labeled TX (transmitting) and RX (receiving) turn on for a moment. If everything is done properly, then your code will begin to run automatically. Brand new Arduinos may already have this sketch installed. In order to see something different you can change the length of delay time (-----delay) in the code. Comments: Add some comments between the symbols /* and */ and if you just wish to limit your statement to a single line, add your comment after the symbol //. You can write a date and the name of the authors and any other statement that you wish to see whenever you view the codes. The line int led = 13; defines an integer variable (led) and assigns number 13 to it using the = sign. Connect your LED to pin 13 and it will light up according to the void set up () { instructions. Note that pin 13 is in the DIGITAL section of the board. The short end of the LED is connected to the GND. Next we need to tell Arduino if our selected pin would be used as an output or input using the pinmode( ) function. Since we would like the LED connected to pin 13 to turn on, we need to define this pin as an output so current through it is delivered to the LED and then to the GND. This assignment is done using the command pinmode(led, OUTPUT). Essentially, we are telling Arduino to use the pin that we previously labeled as led as an output. As we mentioned earlier, the setup statement must be concluded with a curly bracket }. Note that some digital pins are marked with the sign which means they can deliver analog output through Pulse Width Modulation (PWM). The void loop( ) { instructions define more details on how you expect the LED to behave. In this particular case we would like the LED to have a digital state which means that it is either on or off. We assign a digital state to pin 13. This is done by writing digitalwrite(led, HIGH);. It means that a 5 V voltage will be delivered to pin 13. If you wish for the LED to turn off at some point, you will need to instruct Arduino accordingly by writing digitalwrite(led, LOW);, which drops the voltage delivered to pin 13 to zero. Naturally, you would want to turn the LED off after a certain delay time. Therefore after the HIGH statement and before the LOW statement you insert a delay time. Arduino measures time in ms. You will insert a delay of 1000 ms if you wish the LED to remain on for one second. The code is delay(1000);. You have probably noticed that each statement is followed by the symbol ; which indicates the end of that 6

instruction line. The compiler will remind you of an error if you forget to terminate an instruction line with a semicolon. Next you need to specify for how long you wish the LED to remain in the off position. This is done by adding a second delay command delay(1000). Of course you can choose a different delay for the off position. For example, the LED may be on for one second and off for 2 seconds. Do not forget to conclude the loop statements using the curly bracket }. You notice that the script editor uses different colors for various parts of the codes. Assuming that you have already selected the type of your board and the address of your laptop s port, you are ready to upload the code from your computer to the board. The IDE will remember the type of your board and the port s address for future experiments. Click the upload button (the right arrow). You should see that the computer is communicating with the board through the TX and RX LEDs. Your LED connected to pin 13 will start blinking as soon as the code is transmitted to the board. Exercise: You can now go back to the Blink code and change the delay times and have fun! Congratulations! You are now ready to copy the code for other examples and do more sophisticated experiments. In the event that you wish to use your Arduino independent of your computer, you will need to use an external battery or power supply. If so, you should pay attention to the power supply s voltage and current output depending on what external device (such as a motor) you wish to run with the Arduino. A 7-12 V power supply would be appropriate for most applications. In case you wish to connect motors and many LEDs, then your power supply should be capable of delivering sufficient current. Interesting projects: See chapter 4 of the book Arduino Projects for Dummies for a project titled The All-Seeing Eye, which is a band of ten LEDs that turn on in a back and forth cycle. You should have all the resistors and materials needed for this project in your kit. This book also includes several other interesting projects. For example, chapter 5 is about Making a Light Pet. You can use any of these projects for your final project presentations. 7