This document provides an overview of physical prototyping with an Arduino board. It discusses what an Arduino board is, downloading and installing the Arduino IDE, code structure including the setup function and main loop, how to connect an Arduino to a computer, breadboard layout, common Arduino functions like pinMode and digitalWrite, programming concepts like variables and for loops, and gives an example homework of recreating the Knight Rider car's light effect.
5. ARDUINO USB - LAYOUT
ANALOG PINS 0 TO 5POWER OUTPUTS
RESET SWITCH
POWER CONNECTOR
6 v – 24 v
USB CONNECTOR
DIGITAL PINS 0 TO 13
5
6. DOWNLOAD & INSTALL
Download the IDE from:
http://www.arduino.cc
Make sure you download
the right version for
your operating system
6
7. The IDE
IDE stands for Integrated
Development Environment
Arduino's IDE is completely based
on the Processing IDE since
September 2005
Using the IDE is a 3-step process:
1) Write your code
2) Compile the code
3) Upload to Arduino
7
8. FILE MENU
NEW, SAVE, OPEN,
EXAMPLES…
EDIT MENU
CUT, PASTE, FIND…
TOOLS MENU
COM-PORT SETTINGS,
TOOLS,
BOARD TYPE
8
10. Variables are containers for values.
You can give a variable any name you
like.
The value of a variable can be
changed and used dynamically as
many times as you like.
Variables are good to use when you
use values more than once in your
program.
Arduino Uno has 32 kilobytes of flash
memory and can store up to 1024
bytes as variables.
Code structure
Variable declaration
10
11. The Setup method is used to initiate
the board before the code gets
executed.
This code runs only once when the
reset button has been pressed.
It defines if pins should be used as
inputs or outputs, whether serial
communication is going to be used,
etc.
Code structure
The setup method
11
12. The loop is where the action is!
This is where you write your program
It executes from top to bottom, line by
line, and then starts over (looping back).
Code structure
The program loop
12
13. How to hook up your Arduino to your computer
Check the communication port (COM port)
Windows: COMXX ,
Linux: /dev/ttyUSBXX,
MAC: /dev/cu.usbserial-AXXX.
Did it install correctly?
COM-port number? (remember the port's identity)
Choose right COM port in IDE
Open “LED Blink” example under Examples/1. Basics
Compile and upload to Arduino
A built-in LED at pin 13 should blink
Check out the code and see if you can change the interval
QUICK START-GUIDE
13
14. BREADBOARD LAYOUT
Image taken from booklet by M. Banzi et al.14
The center grid is connected in this way
The outer sides are connected in this way
15. Current (A): is the number of electrons per time and section of cable
Voltage (V): is the difference in the number of electrons between two
points, It only exists in relative terms!, thus we have to “share grounds”
when interconnecting circuits
Resistance (R): reduces the flow of electrons
Current always takes the easiest possible way
If it has the option to pass through cable or resistor, it chooses the cable
In series connection
Rtotal = R1 + R2
A parallel connection
Rtotal = (R3*R4) / (R3+R4)
Voltage, Current & Resistance
15
16. Buttons
Hook up a ”push button” as shown in this diagram:
PRACTICAL EXAMPLE
16
17. Common Arduino methods:
pinMode(pin, MODE);
Sets pin (”pin”) in a specific mode, INPUT or OUTPUT
Normally used in the setup.
digitalWrite(pin, HIGH/LOW);
Will set one of the digital pins on the Arduino board to be either
HIGH (5V) or LOW (0V).
int digitalRead(pin);
Will read one of the digital pins on the Arduino board and will
answer either HIGH (5V) or LOW (0V).
if(statement) {block_code1} else {block_code2};
If the conditional statement is met, block_code1 will run, otherwise
block_code2 will be executed.
for (init; end; increment) {}
Will execute a certain piece of code a certain amount of times.
PROGRAMMING
17
18. for(counter=0; counter<end; counter++){}
1)The FOR loop is a software construct that will execute a
block of code a number of times.
2)The code will be looped until a certain condition is met
3)FOR loops are constructed with an initialization value, a
boolean statement, and a counting statement
4)We use them to iterate a certain action a determined
amount of times
counter initialization
FOR LOOP
condition counter
increment / decrement
18
19. VARIABLES
Predefined Data Types
There are three different variable types:
1) INT – 16 BIT, (-32768 TO 32767)
Port numbers, values read from ports, results from
calculations...
2) CHAR – 8 BIT (1 BYTE), (0 TO 256)
Letters (A-Z), Small values, not suited for calculations,
sending data serially...
3) LONG – 32 BIT, (-2147483648 TO 2147483647)
Results from calculations, counting milliseconds...
The type of variable determines the maximum size of the value
Use the appropriate variable types, because of limited memory
Use variable names that make sense!
NOT myVariable, myValue, port...
INSTEAD firstInput, nbrOfOutputs...
19
20. HOMEWORK: KNIGHT RIDER
Implement the light effect as seen in
KIT, the Knight Rider car
from the iconic 80's TV series
with David Hasselhoff
The light sequence should be activated
when a user presses a button.
20
Editor's Notes
Encourage people to interrupt you so you can help them immediately. Explain they do you a favor.
It’s good to time the duration of the presentation.
In this course you will not learn in a traditional academic way.
We believe that you can learn electronics
Recycle old electronics. Modern electronics is based on 30 year old technology.
Mention shelf in corridor. Leave crap take crap
Explain the 5 comments.
Digital pins operate in 0’s and 1’s On or Off.
Analog pins work as inputs.
Explain link between Arduino and computer: Arduino is able to get control electrical components like LED’s and speakers and Arduino is able to measure values in the physical world.
Measure inputs control outputs
3.3 volts and 5 volt power pins to power electrical components (sensors and actuators)
Vin = maximum 17 volts. Vin is the power from an external power source, used to power motors for example.
Arduino takes between 6 and 17 volts The worst thing that could happen is you fry the chip on the Arduino board.
Talk about programming languages:
Compile into machine code, 0’s and 1’s
Arduino syntax is a mix of C and C#.
It’s a third level language.
Uploading: the process of taking the code and putting it on the arduino board.
The code stays there until new code is uploaded.
All Arduino programs are called sketches. Heritage from Processing environment. Processing was a sketchpad.
Tools menu: COM-port. Set the right port to use the USB port the Arduino is connected to.
Linux: TTY1 or TTY0
Windows: COM4 etc. next one COM5 (unique numbers)
OSX: TTY-USB Serial modem. Always the first one in the list.
Board type: Set correct model. (UNO)
They have different kinds of firmware and bootloaders.
Explain Verify/Compile and Upload
Monitor: Window to receive and send message from and to the computer (serial)
Don’t spend too much time on this slide.
Cooky jar analogy. Variables are containers, you can put stuff in them and give them a name.
Sock drawer: Friday socks , Tuesday socks, etc.
1: Always put your variables on top of everything else.
2: Setup.
In every program you write there have to be two functions: Setup and Loop
Setup kicks off a program.
For instance declare which pins you will use.
From the start Arduino doesn’t know how you want to use them, you have to tell it.
It has to know where to direct power to or on which pin to listen for information.
The setup only runs once.
The arduino runs code line by line, this is why semicolons are used.
3: The loop.
This is where you write your program.
It executes line by line.
When it reaches the bottom it starts over again.
You can skip parts of the code with some special statements.
The point of looping everything over and over again is because we can’t predict the real world.
For instance when someone will press a button. So we keep checking.
Windows: Plugin: Show where the driver is and install it.
OSX + Linux should work out fine.
When kids are done before others ask them to make the LED blink like a heart beat.
Slide 14: Explain what the breadboard is.
Normally you solder connections. But it’s a pain in the ass to do this all the time.
Breadboard is used to quickly test if things work before you actually produce it.
Explain the horizontal and vertical lines. And how power is distributed among them.
Tell them not to remove the sticker on the back of the breadboard
Tell them about current voltage and resistance.
Explain the water analogy.
Electricity works as water.
When you push it through a garden hose the hose acts as resistance.
Same as a wire, it reduces the amount of electrons transfers.
Voltage is the speed of the water and the electricity.
When you try to put too much water through the hose it will burst.
Same goes for electricity.
Important: Ground. Power always has to go back to the source it came from. This is ground.
Skip the part about series and parallel connections. In the bottom corner is the schematic of how to connect a button. We will never be this technical in the workshop.
When you do push the button you open up a connection to ground. Electricity always takes the easiest route back to the power source. Ground is easier than the other connection.
Write the code as a live coding session
Quick recap on code examples.
Explain the for loop.
Make a loop out of the blink LED code.
Use for loop to loop blinking 25 times.
Explain benefits of for loop, repetition of code.
Explain the three parameters.
Explain there are 3 kinds.
Name your variables properly, give them a name that describes what it does or which information it holds.
Show youtube movie of Knight Rider intro song.
Explain the concept of a ground ditch.
Encourage them to ‘cheat’, to make a function out of the blinking led code for the knight rider example.
Give them an explanation of the homework assignment in next class.