Arduino Tutorial slides

Download Report

Transcript Arduino Tutorial slides

QSET
ELECTRICAL TEAM
ARDUINO TUTORIAL I
BY: JOSHUA ARDUINI
WHAT IS ARDUINO
• Microcontroller
• Allows for quick prototyping of ideas
• Accepts both digital and analog signals
• Simple to use
• Readily available online support / help / documentation
• Big part of the QSET Rover
DOWNLOADING ARDUINO IDE
1. Go to WWW.ARDUINO.CC
2. Select “Download”
3. Download the appropriate version & follow
instructions
GETTING STARTED
• Ensure Arduino.exe will open
• Navigate to www.123d.circuits.io
• Create an account
• Then select “New Breadboard Circuit”
THE BREADBOARD
• Two sections
• Connected horizontally labelled by + and –
• Each row is a separate piece of wire
• Connected vertically labeled 1 – 60 in this case but
can have more or less
• Each column is a separate piece of wire
• Pattern repeats after the dotted line. This gap
separates the electrical connections.
----------------------------------------
BASIC L.E.D. CIRCUIT
The arrow marks the direction of current flow.
Voltage supply comes directly from the Arduino board (in this example)
V=5V
R = 330 Ω
CREATING THE CIRCUIT ON 123D.CIRCUITS
DEMO
WRITING THE ARDUINO CODE
Typically in 3 main parts
1. Initialization of variables
2. Setting up the hardware to
recognize components
3. Loop instance that runs
indefinitely
1. INITIALIZATION OF VARIABLES
• In this case we only need one variable
• “int” denotes that it is an integer
• led was the chosen name for the
variable
• 13 is the pin we are plugging the LED
into
2. SETTING UP THE HARDWARE TO RECOGNIZE
COMPONENTS
• “Void setup() {“ tells the compiler we
are going to start our setup phase of
code
• “pinMode” tells the compiler that we
need to do a pin assignment. This
instruction has the form:
pinMode(PIN#,mode);
• PIN# - Taken from the #s on the board
• Mode – Tell the compiler if it is going
to be an INPUT or an OUTPUT.
• “}” denotes the end of the setup
function
3. LOOP INSTANCE THAT RUNS INDEFINITELY
• “Void loop() {“ tells the compiler we are going to
start our loop phase of code
• “digitalWrite” tells the compiler that we would like
to set a digital value. 1(current) OR 0(no current).
• This instruction is of the form digitalWrite(PIN#,
Value).
• PIN# - The pin we want to alter
• Value – Whether we want it to be a HIGH(1) or
LOW(0)
• “delay” tells the compiler to wait for a duration of
1000ms (1 second).
3. LOOP INSTANCE THAT RUNS INDEFINITELY CONT.
• Now we do the “digitalWrite” to tell the LED to turn
off and wait 1000ms
• “}” tells the compiler that this is the end of the
instructions that we want to loop
• Once the program has executed the second delay,
it will go up to the beginning of the loop and turn
the LED on again
NOW EXECUTE ON 123D.CIRUITS
DEMO