Intro to Arduino Revision #2

66
Intro to Arduino Class Deezmaker 3D Printer Store and Hackerspace Taught by Quin Etnyre July 26, 2014

description

Intro to Arduino class taught by Quin from Qtechknow at the Deezmaker Hackerspace July 2014. Revised from previous slides to include helpful tools, more pictures, and many more projects for the students! Curriculum is for both kids and adults. Feel free to use, share, and remix as part of the Creative Commons Attribution-ShareAlike 4.0 International open source license.

Transcript of Intro to Arduino Revision #2

Page 1: Intro to Arduino Revision #2

Intro to Arduino Class !

Deezmaker 3D Printer Store and Hackerspace

Taught by Quin Etnyre

July 26, 2014

Page 2: Intro to Arduino Revision #2

Thank you to SparkFun for sharing the original presentation!

Page 3: Intro to Arduino Revision #2

What is Open Source?

• Release your design files to the public • Free access for anyone who wants to learn • Everyone gains knowledge, companies or

hobbyists • You are able to remake/remix the project to suit

your own needs • When you credit the original designer

Page 4: Intro to Arduino Revision #2

What is the Arduino?Intended for anyone to create interactive projects

“Strong Friend” Created in Ivrea, Italy in 2005 by Massimo Banzi & David Cuartielles

Open Source Hardware Atmel 8-Bit Processor

Coding is easy for anyone to learn

Page 5: Intro to Arduino Revision #2

Why do I want an Arduino?

Arduino is a 8-bit prototyping system that is easy for the modern developer, designer, hacker, kid, or someone that has no experience in this type of genre to use.

! But why is important to all of us?

Page 6: Intro to Arduino Revision #2

Schedule• Introduction to Arduino and Installing Software • Project 1 • Electronics Concepts • Project 2 • Arduino IDE in Depth • Project 3 • Break • Project 4 • Explaining More Code • Project 5, 6, & 7 • Project Time with more ArduSensors

Page 7: Intro to Arduino Revision #2

Kit Contents

Page 8: Intro to Arduino Revision #2
Page 9: Intro to Arduino Revision #2

Arduino IDE

The Arduino IDE (Integrated Development Environment) is where we develop our code, and upload the code to the Arduino Leonardo board. You can download the latest software here:

!Arduino 1.0.5:

bit.ly/arduinoide

Page 10: Intro to Arduino Revision #2

Downloading Code

!

bit.ly/deezmakercode !

Put the downloaded folder on your desktop

Page 11: Intro to Arduino Revision #2

Arduino Drivers

Mac: Click Red ‘X’ !!Windows XP / 7 / 8: !!!Windows XP / 7 Secondary Option: http://bit.ly/

arduino-windows

Page 12: Intro to Arduino Revision #2
Page 13: Intro to Arduino Revision #2
Page 14: Intro to Arduino Revision #2

Board Type

Page 15: Intro to Arduino Revision #2

Serial Port / COM Port

Page 16: Intro to Arduino Revision #2

Which COM/Serial Port?Mac: /dev/tty.usbmodemfd131 !

Interchangeable #: !Windows: COM# Device Manager: !Start>Control Panel>System & Security>Device Manager>Ports

Page 17: Intro to Arduino Revision #2

What’s a Breadboard?

Page 18: Intro to Arduino Revision #2

Circuit 1: Basic Blink

Page 19: Intro to Arduino Revision #2

19

Page 20: Intro to Arduino Revision #2

Add more LEDs!

Page 21: Intro to Arduino Revision #2

Arduino ShieldsLCD Touch RGB LED WiFi

Page 22: Intro to Arduino Revision #2

ArduSensors - ‘Mini Shields’

Page 23: Intro to Arduino Revision #2

Concepts of Electronics

• Polarity • Power / Voltage and Ground • Analog and Digital • Inputs and Outputs • PWM • Arduino IDE Review • Analog Inputs

Page 24: Intro to Arduino Revision #2

Polarity

Polarity is when there are two or more different sides (or leads) of a component that have different qualities that can not be reversed.

! Examples: batteries, LEDs, buttons

Page 25: Intro to Arduino Revision #2

Power / Voltage and Ground (GND)

Use only 5V or 3.3V in your projects

Power+

-Circuit

Page 26: Intro to Arduino Revision #2

Analog and Digital• All Arduino signals are either Analog or Digital • All computers can only understand Digital • Digital Pins D0 - D13 on Arduino • Special pins that are ADC enabled (analog to

digital converter) we can connect sensors to • Analog Pins A0 - A5 on Arduino

Page 27: Intro to Arduino Revision #2

I/O, or Input/Output

Input is any signal entering an electrical system/Arduino. !Output is any signal exiting an electrical system.

Page 28: Intro to Arduino Revision #2

OutputOutput is always Digital

!To Output a Digital signal (On or Off) use this code: !digitalWrite (pinNumber, value);

!Where value is HIGH (on) or LOW (off), both in caps

Page 29: Intro to Arduino Revision #2

Output

To ‘Fade’ an LED or to output a voltage in-between 0V and 5V, use PWM

!Use this code to output an ‘analog’ signal: analogWrite (pinNumber, value); Where value is a number 0 - 255. (0V to 5V) !PWM is available on Arduino Leonardo digital pins 3, 5, 6, 9, 10, 11, and 13, and marked with a ‘~’.

Page 30: Intro to Arduino Revision #2

OutputOutput is always Digital, even when it’s P.W.M.

!For P.W.M. the Arduino pin turns on, then off very fast

!!P.W.M. Signal @ 25% P.W.M. Signal @ 75% P.W.M. Signal rising

Page 31: Intro to Arduino Revision #2

Circuit 2:

31

Page 32: Intro to Arduino Revision #2

Arduino IDE in Depth

• Parts of the Sketch • setup() • loop() • Comments • Analog Input

Page 33: Intro to Arduino Revision #2

Parts of the Sketch

Page 34: Intro to Arduino Revision #2

void setup() {}

34

Page 35: Intro to Arduino Revision #2

!!

void loop ( ) { } !!

!

!!

!

!!

Page 36: Intro to Arduino Revision #2

Example of Comment:

Page 37: Intro to Arduino Revision #2

Comments

• Comments are ignored by the compiler/verifier

• Comments can be anywhere • Starts with a // for a one-line comment • Starts with a /* and ends with a */ for a

multiple-line comment • Great ways to remind you what you did, teach

other people what that code means

Page 38: Intro to Arduino Revision #2

Analog Input• To connect an analog Input to your Arduino, use

Analog Pins #A0 - A5 !• To get an analog reading, use the code: analogRead(pinNumber); !• Analog Input varies from 0 to 1023 on an Arduino

Page 39: Intro to Arduino Revision #2

Circuit 3: Analog Reading

Page 40: Intro to Arduino Revision #2
Page 41: Intro to Arduino Revision #2

Break

Page 42: Intro to Arduino Revision #2

Digital Sensors/Digital Input• Digital Input could be a switch or a button • To connect digital input to your Arduino use Digital

Pins # D0 – D13 • Digital Input needs a pinMode command (in setup): pinMode(pinNumber, INPUT); Make sure to use caps for INPUT • To get a digital reading: digitalRead(pinNumber); • Digital Input values are only HIGH (On) or LOW

(Off)

Page 43: Intro to Arduino Revision #2

Digital Sensors/Digital Input• Digital sensors are more straight forward than

Analog !• No matter what the sensor, there are only two

settings: On and Off !• Voltage signal for LOW (off) will be 0V, and HIGH

(on) will be 5V

Page 44: Intro to Arduino Revision #2

Parts for Circuit 4:

Arduino Leonardo Breadboard Pushbutton (2) LED (2) Resistor - 10K Ohm (2) Resistor - 330 Ohm (2) Jumper Wires

Page 45: Intro to Arduino Revision #2

Circuit 4: Buttons

Page 46: Intro to Arduino Revision #2
Page 47: Intro to Arduino Revision #2

`

Page 48: Intro to Arduino Revision #2
Page 49: Intro to Arduino Revision #2

OperatorsThe equals sign

!= is used to assign a value

!== is used to compare values

!&& is “and”

!|| is “or”

Page 50: Intro to Arduino Revision #2

Variables

Basic variable types: !

Boolean (on or off) Integer (a number) Character (a letter)

String (a phrase)

Page 51: Intro to Arduino Revision #2

Declaring Variables

Boolean: boolean variableName; !

Integer: int variableName; !

Character : char variableName; String: stringName [ ];

Page 52: Intro to Arduino Revision #2

Assigning Variables

Boolean: variableName = true; or variableName = false;

Page 53: Intro to Arduino Revision #2

Assigning Variables

Boolean: variableName = true; or variableName = false;

Integer: variableName = 32767; or variableName = -32768;

Page 54: Intro to Arduino Revision #2

Assigning Variables

Boolean: variableName = true; or variableName = false;

Integer: variableName = 32767; or variableName = -32768;

Character : variableName = ‘A’; or stringName = “Deezmaker”;

Page 55: Intro to Arduino Revision #2

Circuit 5: ArduSensor + LED

Page 56: Intro to Arduino Revision #2
Page 57: Intro to Arduino Revision #2

Setup void setup ( ) {

pinMode (13, OUTPUT); }!

!

!

Inputs & Outputs are declared in setup, this is done by using the

pinMode function This particular example declares digital pin # 13 as

an output, remember to use CAPS

Page 58: Intro to Arduino Revision #2

!!

If Statements if ( this is true ) { do this; }

!

!

!!

Page 59: Intro to Arduino Revision #2

!!

Basic Repetition !

for (int count = 0; count<10; count++) { //for action code goes here //this could be anything }

Page 60: Intro to Arduino Revision #2

Circuit 6: LED Bounce

Page 61: Intro to Arduino Revision #2
Page 62: Intro to Arduino Revision #2
Page 63: Intro to Arduino Revision #2

Circuit 7: Meter

Page 64: Intro to Arduino Revision #2
Page 65: Intro to Arduino Revision #2
Page 66: Intro to Arduino Revision #2

Project Time with more ArduSensors