Introduction to Arduino

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

FUNCTIONS USED IN CODING pinmode()

keyestudio Keyestudio MEGA 2560 R3 Board

Arduino Prof. Dr. Magdy M. Abdelhameed

FUNCTIONS For controlling the Arduino board and performing computations.

ARDUINO LEONARDO ETH Code: A000022

Introduction to Arduino. Wilson Wingston Sharon

Arduino ADK Rev.3 Board A000069

Alessandra de Vitis. Arduino

More Arduino Programming

Arduino Part 2. Introductory Medical Device Prototyping

IDUINO for maker s life. User Manual. For IDUINO Mega2560 Board(ST1026)

ARDUINO LEONARDO WITH HEADERS Code: A000057

Introduction to Arduino

Lesson 5 Arduino Prototype Development Platforms. Chapter-8 L05: "Internet of Things ", Raj Kamal, Publs.: McGraw-Hill Education

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

Arduino Uno. Arduino Uno R3 Front. Arduino Uno R2 Front

ARDUINO MEGA ADK REV3 Code: A000069

How to Use an Arduino

TANGIBLE MEDIA & PHYSICAL COMPUTING INTRODUCTION TO ARDUINO

E11 Lecture 4: More C!!! Profs. David Money Harris & Sarah Harris Fall 2011

ARDUINO MEGA 2560 REV3 Code: A000067

ARDUINO UNO REV3 Code: A000066

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

EXPERIMENT 7 Please visit to learn all features of arduino before you start the experiments

IDUINO for maker s life. User Manual. For IDUINO development Board.

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

ARDUINO M0 PRO Code: A000111

Introduction to Microprocessors: Arduino

ARDUINO UNO REV3 SMD Code: A The board everybody gets started with, based on the ATmega328 (SMD).

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

Sanguino TSB. Introduction: Features:

ARDUINO YÚN MINI Code: A000108

Introduction to Microcontrollers

ARDUINO YÚN Code: A000008

ARDUINO MICRO WITHOUT HEADERS Code: A000093

Arduino Uno Microcontroller Overview

Arduino: What is it? What can it do?

Arduino - DigitalReadSerial

ARDUINO MINI 05 Code: A000087

Arduino For Amateur Radio

Laboratory 1 Introduction to the Arduino boards

OBSTACLE AVOIDANCE ROBOT

ARDUINO INDUSTRIAL 1 01 Code: A000126

CTEC 1802 Embedded Programming Labs

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

The Arduino Briefing. The Arduino Briefing

TA0297 WEMOS D1 R2 WIFI ARDUINO DEVELOPMENT BOARD ESP8266

USER MANUAL ARDUINO I/O EXPANSION SHIELD

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

Arduino Uno R3 INTRODUCTION

CN310 Microprocessor Systems Design

Lecture 6: Embedded Systems and Microcontrollers

ARDUINO. By Kiran Tiwari BCT 2072 CoTS.

PDF of this portion of workshop notes:

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

BASIC ARDUINO WORKSHOP. Mr. Aldwin and Mr. Bernardo

Bluno Mega 2560 (SKU:DFR0323)

Specification. 1.Power Supply direct from Microcontroller Board. 2.The circuit can be used with Microcontroller Board such as Arduino UNO R3.

Electronic Brick Starter Kit

Arduino Internals. Dale Wheat. Apress

Arduino Programming. Arduino UNO & Innoesys Educational Shield

Arduino Ethernet. Arduino Ethernet Rev. 2 board front view with optional PoE module. (

Microcontrollers for Ham Radio

Lab 2 - Powering the Fubarino. Fubarino,, Intro to Serial, Functions and Variables

Arduinos without (much) programming

IME-100 Interdisciplinary Design and Manufacturing

Arduino provides a standard form factor that breaks the functions of the micro-controller into a more accessible package.

EL Sequencer/Escudo Dos Hookup Guide

Laboratory 5 Communication Interfaces

Computer Architectures

Arduino 07 ARDUINO WORKSHOP 2007

4Serial SIK BINDER //77

Building your own special-purpose embedded system gadget.

Introduction to Microcontrollers Using Arduino. PhilRobotics

ARDUINO PRIMO. Code: A000135

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

ARDUINO BOARD LINE UP

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

Introduction To Arduino

TABLE OF CONTENTS INTRODUCTION LESSONS PROJECTS

Workshop on Microcontroller Based Project Development

Chapter 2 The Basic Functions

Lesson 6 Intel Galileo and Edison Prototype Development Platforms. Chapter-8 L06: "Internet of Things ", Raj Kamal, Publs.: McGraw-Hill Education

Lab 2 - Powering the Fubarino, Intro to Serial, Functions and Variables

Welcome to Apollo. For more information, please visit the website and select Apollo. Default Code

Arduino Programming Part 4: Flow Control

Breeze Board. Type A. User Manual.

Arduino and Matlab for prototyping and manufacturing

Microcontrollers and Interfacing week 8 exercises

User Guide v1.0. v1.0 Oct 1, This guide is only available in English Ce manuel est seulement disponible en Anglais

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

SX1509 I/O Expander Breakout Hookup Guide

Farklı Arduino Boardlar

Seeeduino LoRaWAN. Description

Lab 2.2 Ohm s Law and Introduction to Arduinos

University of Hull Department of Computer Science C4DI Interfacing with Arduinos

Arduino Programming and Interfacing

Arduino Platform Part I

ARDUINO EXPERIMENTS ARDUINO EXPERIMENTS

Transcription:

Introduction to Arduino Paco Abad May 20 th, 2011 WGM #21 Outline What is Arduino? Where to start Types Shields Alternatives Know your board Installing and using the IDE Digital output Serial communication 2 1

What is Arduino? Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. 22 3 Where to start: http://arduino.cc http://www.ladyada.net/learn/arduino(this presentation is based on their tutorials) Google: arduino (5.550.000 hits on April 2011) 4 2

Types of Arduinos Nano Uno Lilypad Mega 2560 Pro BT Mini Fio 5 Shields Shields are boards that sit on top of the Arduino to extend its functionality MIDI Shield microsd 2Gb Module for Arduino Communication Shield (XB, BT, RFID) http://www.cooking-hacks.com 6 3

Shields Shields are boards that sit on top of the Arduino to extend its functionality Motor Driver Shield CAN-BUS Shield Ethernet Shield http://www.cooking-hacks.com 7 Shields Shields are boards that sit on top of the Arduino to extend its functionality Relay Shield Music Shield Input Shield http://www.cooking-hacks.com 8 4

Alternatives TI LaunchPad http://www.ti.com/launchpad 4.30$ C Basic Stamp 2 http://parallax.com 49$ Basic 9 Netduino http://netduino.com 34.95$ C# Bare controllers Picaxe Propeller PIC AVR Alternatives 10 5

What do I need to start? http://arduino.cc/en/main/software 11 Know your board (between 7 and 12V) 12 6

Know your board Microcontroller: ATmega168 / ATmega328 OperatingVoltage: 5V Input Voltage(recommended): 7-12V Input Voltage(limits): 6-20V Digital I/O Pins: 14 (of which6 providepwm output) AnalogInput Pins: 6 DC Currentper I/O Pin: 40 ma DC Currentfor3.3V Pin: 50 ma Flash Memory: 16 KB (ATmega168) or 32 KB (ATmega328) of which 2 KB usedbybootloader SRAM: 1 KB (ATmega168) or 2 KB (ATmega328) EEPROM: 512 bytes (ATmega168) or1 KB (ATmega328) Clock Speed: 16 MHz 13 Options: Power your board USB If Diecimila, select the power type Wall-wart: 2.1mm, center-positive - + Battery 14 7

Options: Take power from your board Voltage input (coming from the wall-wart) Ground (two pins) 5 V (from the regulator, or from the USB) 3.3 V (50mA maximum) 15 Talk to/listen to your board Options: 14 digital input/output pins. 5V, 40mA max, pull up resistor 6 PWM output pins 6 analog input pins. 0-5V, 10 bits (1024 levels) 16 8

Installing the IDE http://arduino.cc/en/guide/windows Download and unzip your IDE from http://arduino.cc/en/main/software Connect the Arduino to a USB port and install the driver (for Windows, in folder arduino\drivers\ftdi USB Drivers) Execute the IDE: 17 Select your board Installing the IDE 18 9

Select your port Installing the IDE You can find out which port to use in the Device Manager: 19 Arduino: The IDE Tab manager Source code Editor Results window 20 10

The toolbar Verify the program (compile) Stop the serial monitor New source code file (sketch) Open sketch Save sketch [Compile and] upload the program Open the serial monitor 21 The serial monitor Computer Arduino Arduino Computer Communication speed 22 11

Digital output: Hello world Open the Blink example File\Examples\1. Basics\Blink 23 Digital output: Hello world /* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinmode(13, OUTPUT); } Mandatory function: executed once, when Arduino boots or resets void loop() { digitalwrite(13, HIGH); delay(1000); digitalwrite(13, LOW); delay(1000); } // set the LED on // wait for a second // set the LED off // wait for a second Mandatory function: executed over and over while Arduino is powered 24 12

Digital output: Hello world Compile it and upload it to the board 25 Digital output: Hello world In initialization, we have to declare how we will use the digital pins: pinmode(pin, INPUT OUTPUT) The pins are input by default We can turn on and off output pins with: digitalwrite(pin, HIGH LOW) We can tell Arduino to take a nap delay(ms) 26 13

Digital output: Exercise 1 Change the delays to turn on the LED during 10 ms and turn it off during 10 ms. What happens? Wave it And if you turn it on for 10 ms and turn it off for 5 ms? 27 Digital output: PWM Side note: we have discovered PWM! wikipedia.org 28 14

Digital output: Exercise 2 Connect another LED with a 1kΩ resistor to the pin 12 (and ground) and simulate a strobe light 29 Serial communications Arduino communicates with the O.S. through USB, using a virtual serial port Arduino shows when it receives or sends serial data, and give access to the TX (transmission) and RX (reception) lines (digital pins 1 and 0) 30 15

Serial communications: output /* * Hello World! * * This is the Hello World! for Arduino. * It shows how to send data to the computer */ void setup() { // run once, when the sketch starts Serial.begin(9600); // set up Serial library at 9600 bps // prints hello with ending line break Serial.println("Hello world!"); } void loop() // run over and over again { // do nothing! } 31 Serial communications: output When the Serial monitor starts, the board resets (you can also use the button in the board) Serial.println("Hello world!") Serial.begin(9600) 32 16

Serial communications: output Serial.println(val) val: an expression of any type Serial.println(val, format) format: DEC, HEX, OCT, BIN, BYTE Serial.print(val) Serial.print(val, format) 33 Serial communications: input int incomingbyte = 0; void setup() { Serial.begin(9600); } void loop() { if (Serial.available() > 0) { incomingbyte = Serial.read(); Serial.print("I received: "); Serial.println(incomingByte, DEC); } } 34 17

Serial communications: input Serial.available() Returns the number of available bytes Serial.read() Returns the next byte, or -1 if there is none available 35 Serial communications: input Exercise: Create a serial cypherer: when arduino receives a character between a and z, it returns the following character (next(z) == a). When it receives something else, it outputs the same character 36 18

The simplest input device is the switch There are many types of switch 37 Before using the Arduino, let s check that all the components work 38 19

/* File\Examples\1. Basics\DigitalReadSerial Reads a digital input on pin 2, prints the result to the serial monitor This example code is in the public domain. */ void setup() { Serial.begin(9600); pinmode(2, INPUT); } void loop() { int sensorvalue = digitalread(2); Serial.println(sensorValue, DEC); } Using a cable, connect pin 2 to GND orto 5V 39 pinmode(2, INPUT); digitalread(pin) pin: the pin to read from Returns the state of the pin (HIGH or LOW) 40 20

A floating input (an unconnected input pin) will return noise (random highs and lows) 41 To read the state of a pushbutton, we may use the following circuit: Where is the problem? 42 21

The actual circuit we use uses a resistor, to pull-down or pull-up the pin, when the switch is open pull-down pull-up 43 Arduino provides a switchable pull-up resistor for digital input pins. It is activated with: pinmode(2, INPUT); digitalwrite(2, HIGH); // pull-up So the circuit is simplified to: 44 22

With a pull-up resistor, when the pushbutton is not pressed the pin reads HIGH, and viceversa 45 Exercise Write a program to activate the LED in the board (pin 13) when the button is pressed 46 23

Exercise Write a program to toggle on and off the LED in the board when the button is pressed 47 Contact bounce 48 24

Contact bounce occurs in state changes, not when the button is being pressed down or when it is not pressed There are several techniques to debounce a switch, but we will use just a delay: int val, val2; val = digitalread(switchpin); delay(10); val2 = digitalread(switchpin); if (val!= val2) return; // Bounce // val contains the settled value 49 25