INTRODUCTION TO ARDUINO AND LEDS

Similar documents
Microcontroller Programming Beginning with Arduino. Charlie Mooney

Basic Pulse Width Modulation

Introduction to Arduino

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

Arduino Lesson 1. Blink

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

Arduino project. Arduino board. Serial transmission

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

Lab 6 Introduction to Serial and Wireless Communication

4/Really Getting Started with Arduino

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

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

Arduino Lesson 14. Servo Motors

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

Arduino Motor Shield (L298) Manual

Introduction to Arduino

Arduino Lesson 4. Eight LEDs and a Shift Register

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

Basic DC Motor Circuits

Arduino Microcontroller Guide W. Durfee, University of Minnesota ver. oct-2011 Available on-line at

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

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Computer Architectures

Arduino ADK Back. For information on using the board with the Android OS, see Google's ADK documentation.

IR Communication a learn.sparkfun.com tutorial

Advanced LED Controller (LED Chaser)

Arduino Shield Manual

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

Start with Arduino: Introduction to. the Creative Use of. Electronics. Made in Germany. by Stefan Hermann

Arduino Due Back. Warning: Unlike other Arduino boards, the Arduino Due board runs at 3.3V. The maximum. Overview

C4DI Arduino tutorial 4 Things beginning with the letter i

RGB LED Strips. Created by lady ada. Last updated on :00:18 PM EST

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

DEPARTMENT OF ELECTRONICS ENGINEERING

Servo Motor API nxt_motor_get_count nxt_motor_set_count nxt_motor_set_speed

How To Control A Car With A Thermostat

Work with Arduino Hardware

Arduino Lesson 13. DC Motors. Created by Simon Monk

Arduino Shield Manual

Connecting Arduino to Processing a

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

ARDUINO SEVERINO SERIAL SINGLE SIDED VERSION 3 S3v3 (REVISION 2) USER MANUAL

Arduino Lesson 16. Stepper Motors

Controlling a Dot Matrix LED Display with a Microcontroller

Modern Robotics, Inc Core Device Discovery Utility. Modern Robotics Inc, 2015

MANUAL FOR RX700 LR and NR

Timer A (0 and 1) and PWM EE3376

Technical Manual. FAN COIL CONTROLLER COOLING or HEATING ANALOG or PWM Art A

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Neonixie 6 Digit Nixie Clock Controller Introduction and Assembly

1 Coffee cooling : Part B : automated data acquisition

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK

Electronic Brick of Current Sensor

Arduino-Based Dataloggers: Hardware and Software David R. Brooks Institute for Earth Science Research and Education V 1.2, June, , 2015

LCD I 2 C/Serial RX Backpack. Data Sheet. LCD to I2C/Serial RX Backpack I2C or Serial RX communication with Standard 16 Pin LCD modules

Arduino Mega 2560 Crazy kit Manual

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

MeshBee Open Source ZigBee RF Module CookBook

Electronics 5: Arduino, PWM, Mosfetts and Motors

INTRODUCTION TO SERIAL ARM

WA Manager Alarming System Management Software Windows 98, NT, XP, 2000 User Guide

Tire pressure monitoring

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Intro to Intel Galileo - IoT Apps GERARDO CARMONA

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

ANDROID BASED FARM AUTOMATION USING GR-SAKURA

Board also Supports MicroBridge

Arduino DUE + DAC MCP4922 (SPI)

IO Expansion Module User & Installation Manual

GM862 Arduino Shield

Arduino Lesson 5. The Serial Monitor

Ultrasonic Distance Measurement Module

PACKAGE OUTLINE DALLAS DS2434 DS2434 GND. PR 35 PACKAGE See Mech. Drawings Section

S4000TH HART. HART Communication Manual

MIDECO 64-outputs MIDI note decoder USER MANUAL. Roman Sowa 2012

Different Ways of Connecting to. 3DLevelScanner II. A.P.M Automation Solutions LTD. Version 3.0

TwinCAT NC Configuration

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

RB-See-211. Seeedstudio Grove 6-15V, 2A Dual I2C Motor Driver. Grove - I2C Motor Driver. Introduction

Chapter 4: Pulse Width Modulation

Sending Data from a computer to a microcontroller using a UART (Universal Asynchronous Receiver/Transmitter)

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

TSL2561 Luminosity Sensor

HT1632C 32 8 &24 16 LED Driver

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Now you can compile and upload your code supporting highier buffered serial input data. */

EasyC. Programming Tips

Scripting Language Reference. SimpleBGC 32bit

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

CHAPTER 11: Flip Flops

WinLIN Setup and Operation:

Ocean Controls RC Servo Motor Controller

Inwall 4 Input / 4 Output Module

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

An Introduction to MPLAB Integrated Development Environment

EXPERIMENT 2 TRAFFIC LIGHT CONTROL SYSTEM FOR AN INTERSECTION USING S7-300 PLC

Workshop Intel Galileo Board

PhidgetInterfaceKit 8/8/8

Transcription:

INTRODUCTION TO ARDUINO AND LEDS Activity one: Make sure everybody is up and running Arduino 1

Arduino USB Interface Test LED on pin 13 Digital I/O pins power LED Reset tx/rx LEDs ATmega328 External Power Analog Inputs Physical Computing Essentials pinmode(pinnumber, mode); // declare a pin INPUT or OUTPUT digitalread(pinnumber); // read the HIGH/LOW status of pin digitalwrite(pinnumber, value); // force HIGH/LOW voltage analogwrite(pinnumber, value); // PWM for intermediate vals analogread(pinnumber); // read analog pin through ADC 2

Physical Computing Helpers delay(ms); // delay for ms milliseconds millis(); // return total milliseconds since program start Serial.begin(baud); // set up serial communication to host Serial.print(val); // print on monitor (number, char, or string) Serial.println(val); // print with line feed random(min, max); // return random between min, max-1 map(val, fromlo, fromhi, tolo, tohi); // interpolate to range constrain(val, lo, hi); // constrain value to a range Digital Pins Each of the digital pins can be set to one of two values High and Low (logic 1 (+5v) and logic 0 (0v)) digitalwrite(<pin-number>, <value>); digitalwrite(13, HIGH); digitalwrite(13, 1); digitalwrite(13, LOW); digitalwrite(13, 0); 3

Arduino Programming Load Examples - Basics - Blink Arduino SW system Two required functions void setup(){ } void loop(){ } // runs once at init time // loops forever after init 4

Arduino Programming Verify, Upload, New, Open, Save Programming area Notification area Blink Example int led = 13; void setup() { pinmode(led, OUTPUT); } void loop() { digitalwrite(led, HIGH); delay(1000); digitalwrite(led, LOW); delay(1000); } 5

Arduino LED already connected to pin 13 Upload Blink to your Arduino Load Basics -> Blink into IDE Make sure you select the correct board Tools -> Board -> (Uno or Duemilanove) Make sure you select the correct serial port Not the bluetooth ports Click on the upload button Watch for blinky lights during upload 6

LEDs and Resistors www.todbot.com long lead short lead Anode + Cathode - Current flows from Anode to Cathode Lights up when current flows LEDs and Resistors www.todbot.com Arduino long lead short lead Anode + Cathode - Current flows from Anode to Cathode Lights up when current flows Ground 7

LEDs and Resistors www.todbot.com long lead short lead Anode + Cathode - Arduino Current flows from Anode to Cathode Lights up when current flows Ground Current Limiting Resistor Diodes have a forward voltage or diode drop Typically V f is around 0.7v for a diode, and 1.5v to 3.0v for an LED Diodes also have a current limit Typically 20mA for an LED If you don t limit the current, they ll burn out 8

Current-Limiting Resistor Assume Pin10 can supply 5v Assume LED V f is 2.0v (5v - 2v) = 3v remaining for R1 We want 20mA R = V/I = 3v /.020A R = 150Ω Ohm s Law: V = IR In practice, 220Ω - 470Ω will work Wiring an external LED 9

Solderless Breadboad Duemilanove Solderless Breadboard Duemilanove 10

Wiring up an External LED Wiring up an External LED 11

Blink Modifications Change numbers in the code Then upload to Arduino watch for blinky lights Change so that blink is on for 500msec and off for 100msec What happens? Change so that blink is on for 50msec and off for 50msec What happens? Change so that blink is on for 10ms and off for 10ms What happens? Aside: Multiple LEDs Each LED needs its own resistor! You can t share 12

Multiple LED Example Multiple LED Example 13

We just made LEDs blink Big Deal? Most actuators are switched on and off with a digital output The digitalwrite(pin,value); function is the software command that lets you control almost anything LEDs are easy! Motors, servos, etc. are a little trickier, but not much More on that later Arduino has 14 digital pins (inputs or outputs) can easily add more with external helper chips More on that later Moving on www.todbot.com 14

www.todbot.com Pulse Width Modulation analogwrite(pin, value); value can be 0 to 255 Must be one of the PWM pins : pins 3, 5, 6, 9, 10, 11 Don t need to set pinmode to OUTPUT (but won t hurt) load Examples Analog - Fading www.todbot.com 15

Fading Program load Examples Analog - Fading int ledpin = 9; // LED connected to digital pin 9 void setup() { // nothing happens in setup (Why not?) // Answer: Pins default to being OUTPUT. You must define any that you want to use // as INPUT, but if you are using them as OUTPUT you can just assume the default. // Typically, though, it s good practice to define the OUTPUT pins anyway } void loop() { // fade in from min to max in increments of 5 points: for (int fadevalue = 0 ; fadevalue <= 255; fadevalue +=5) { analogwrite(ledpin, fadevalue); // sets the value (range from 0 to 255): delay(30); // wait for 30 milliseconds between brightness steps } } // fade out from max to min in increments of 5 points: for (int fadevalue = 255 ; fadevalue >= 0; fadevalue -=5) { analogwrite(ledpin, fadevalue); // sets the value (range from 0 to 255): delay(30); // wait for 30 milliseconds between dimming steps } Fading Example 16

End of Activity One There are some additional slides that you can look at later There s a summary at the end of the handout Add a diffuser 17

Add a diffuser video. ladyada.net http://www.ladyada.net/learn/arduino/lesson3.html 18

Source vs. Sink for current Sink means pull to ground LED is on when Pin 10 is LOW Source means pull to Vdd LED is on when Pin 10 is HIGH Arduino pins: source/sink a max of 40mA/pin Also 250mA total for ALL pins Random Brightness Write a program to make the LED flicker like a flame Choose a random intensity For a random amount of time Use analogwrite(ledpin, val) to change brightness Main loop repeats itself forever Set the value of the brightness to a random value Wait for a random amount of time repeat The effect looks like flickering 19

Flickering Pseudocode 1. Set the LED to a random brightness 2. Wait for a random amount of time 3. repeat Flickering Pseudocode 1. Pick a random number between 100-255 2. Set LED to that brightness (use analogwrite) 3. Pick another random number between 10-150 4. Wait for that amount of time (in ms) 5. Repeat int brightness; brightness = random(100, 256); 20

Candle Program random(min,max); will return a random number between min and (max-1) randomseed(int); will initialize the random function Not really needed foo = random(10, 200); // assign foo to random number between 10-199 Remember delay(val); // waits for val milliseconds hints int bright; // make a new variable called bright bright = random(100, 256); // set bright to a random value // between 100 and 255 Remember: analogwrite(pin,value); // sets a brightness on a pin // pin is the pin number, value is between 0 255 Candle Program Load Sketchbook - DM - Candle int ledpin = 9; // select pin for LED output int bright = 0; // Variable to hold LED brightness int time = 0; // variable to hold delay time void setup () { randomseed(0); // initialize the random function pinmode(ledpin, OUTPUT); // ledpin should be an output } void loop () { bright = random(100, 256); analogwrite(ledpin, bright); // random brightness value // set the LED brightness } time = random(10,150); // random time in ms delay(time); // delay for that time 21

Candle Program (smaller) Load Sketchbook - CandleSmall int ledpin = 9; // select pin for LED output void setup () { pinmode(ledpin, OUTPUT); // ledpin should be output } void loop () { analogwrite(ledpin, random(100, 256)); // LED brightness delay(random(10,150)); // delay for random time } Silly LED Tricks 22

Summary Whew! Digital Pins use pinmode(<pin>, <INPUT/OUTPUT>) for setting direction Put these in the setup() function pinmode(13, OUTPUT); // set pin 13 as an output use digitalwrite(<pin>, <HIGH/LOW>) for on/off digitalwrite(ledpin, HIGH); // turn on pin LEDpin use analogwrite(<pin>, <val>) for PWM dimming values from 0 255 PWM pins are 3, 5, 6, 9, 10, 11 analogwrite(9, 235); // set LED on pin 9 to somewhat bright More Summary delay(val) delays for val-number of milliseconds milliseconds are thousandths of a sec (1000msec = 1sec) delay(500); // delay for half a second random(min,max) returns a random number between min and max You get a new random number each time you call the function foo = random(10, 255); // assign foo a random # from // 10 to 255 23

More Summary Two required Arduino functions void setup() { } // executes once at start for setup void loop() { } // loops forever statements execute one after the other inside loop, then repeat after you run out int i = 10; // define an int variable, initial value 10 Other types of variables: char 8 bits long - 32 bits unsigned float 32 bit floating point number Still More Summary for (<start>; <stop>; <change>) { } for (int i=0; i<8; i++) { } // loop 8 times // the value of i in each iteration is 0, 1, 2, 3, 4, 5, 6, 7 if (<condition>) { } if (foo < 10) {digitalwrite(ledpin, HIGH);} if (<condition>) { } else { } if (num == 10) { <do something> } else { <do something else> } 24

Last Summary (for now) LEDs turn on when current flows from anode to cathode Always use a current-limiting resistor! Remember your resistor color codes 220-470 ohm are good, general-purpose values for LEDs Drive from Arduino on digital pins Use PWM pins if you want to use analogwrite for dimming Arduino Pin13 long lead short lead Anode + Cathode - Current flows from Anode to Cathode Lights up when current flows Ground Resources http://arduino.cc/en/tutorial/homepage http://www.ladyada.net/learn/arduino/index.html http://todbot.com/blog/bionicarduino/ http://todbot.com/blog/spookyarduino/ http://sheepdogguides.com/arduino/aht0led.htm 25

Contact Information Erik Brunvand School of Computing University of Utah Salt Lake City, UT 84112 elb@cs.utah.edu http://www.cs.utah.edu/~elb 26