SlideShare a Scribd company logo
Code
http://arduino.cc/en/Reference/HomePage
The Arduino Environment
Board Type
Serial Port / COM Port
The Environment
Parts of the Sketch
Comments
• Comments can be anywhere
Comments
• Comments can be anywhere
• Comments created with // or /*
and */
Comments
• Comments can be anywhere
• Comments created with // or /*
and */
• Comments do not affect code
Comments
• Comments can be anywhere
• Comments created with // or /*
and */
• Comments do not affect code
• You may not need comments,
but think about the community!
Operators
The equals sign
= is used to assign a value
== is used to compare values
Operators
And & Or
&& is “and”
|| is “or”
Variables
Basic variable types:
Boolean
Integer
Character
Declaring Variables
Boolean: boolean variableName;
Declaring Variables
Boolean: boolean variableName;
Integer: int variableName;
Declaring Variables
Boolean: boolean variableName;
Integer: int variableName;
Character: char variableName;
Declaring Variables
Boolean: boolean variableName;
Integer: int variableName;
Character: char variableName;
String: stringName [ ];
Assigning Variables
Boolean: variableName = true;
or variableName = false;
Assigning Variables
Boolean: variableName = true;
or variableName = false;
Integer: variableName = 32767;
or variableName = -32768;
Assigning Variables
Boolean: variableName = true;
or variableName = false;
Integer: variableName = 32767;
or variableName = -32768;
Character: variableName = ‘A’;
or stringName = “SparkFun”;
Variable Scope
Where you declare your variables matters
Setup
void setup ( ) { }
The setup function comes before
the loop function and is necessary
for all Arduino sketches
Setup
void setup ( ) { }
The setup header will never change,
everything else that occurs in setup
happens inside the curly brackets
Setup
void setup ( ) {
pinMode (13, OUTPUT); }
Outputs are declare in setup, this is
done by using the pinMode function
This particular example declares digital pin # 13 as an
output, remember to use CAPS
Setup
void setup ( ) { Serial.begin;}
Serial communication also begins in
setup
This particular example declares Serial communication
at a baud rate of 9600. More on Serial later...
Setup, Internal Pullup Resistors
void setup ( ) {
digitalWrite (12, HIGH); }
You can also create internal pullup resistors in setup, to
do so digitalWrite the pin HIGH
This takes the place of the pullup resistors currently on
your circuit 7 buttons
Setup, Interrupts
void setup ( ) {
attachInterrupt (interrupt, function,
mode) }
You can designate an interrupt
function to Arduino pins # 2 and 3
This is a way around the linear
processing of Arduino
Setup, Interrupts
void setup ( ) {
attachInterrupt (interrupt, function,
mode) }
Interrupt: the number of the interrupt, 0
or 1, corresponding to Arduino pins # 2
and 3 respectively
Function: the function to call when the
interrupt occurs
Mode: defines when the interrupt should
be triggered
Setup, Interrupts
void setup ( ) {
attachInterrupt (interrupt, function,
mode) }
•LOW whenever pin state is low
•CHANGE whenever pin changes value
•RISING whenever pin goes from low to
high
•FALLING whenever pin goes from low to
high
Don’t forget to CAPITALIZE
If Statements
if ( this is true ) { do this; }
If
if ( this is true ) { do this; }
Conditional
if ( this is true ) { do this; }
Action
if ( this is true ) { do this; }
Else
else { do this; }
Basic Repetition
• loop
• For
• while
Basic Repetition
void loop ( ) { }
Basic Repetition
void loop ( ) { }
Basic Repetition
void loop ( ) { }
The “void” in the header is what
the function will return (or spit out)
when it happens, in this case it
returns nothing so it is void
Basic Repetition
void loop ( ) { }
The “loop” in the header is what the
function is called, sometimes you make
the name up, sometimes (like loop) the
function already has a name
Basic Repetition
void loop ( ) { }
The “( )” in the header is where you
declare any variables that you are
“passing” (or sending) the function, the
loop function is never “passed” any
variables
Basic Repetition
void loop ( ) { }
Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
//this could be anything
}
Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}
Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}
Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}
Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}
Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}
Basic Repetition
for (int count = 0; count<10; count++)
{
//for action code goes here
}
Basic Repetition
while ( count<10 )
{
//while action code goes here
}
Basic Repetition
while ( count<10 )
{
//while action code goes here
//should include a way to change count
//variable so the computer is not stuck
//inside the while loop forever
}
Basic Repetition
while ( count<10 )
{
//looks basically like a “for” loop
//except the variable is declared before
//and incremented inside the while
//loop
}
Basic Repetition
Or maybe:
while ( digitalRead(buttonPin)==1 )
{
//instead of changing a variable
//you just read a pin so the computer
//exits when you press a button
//or a sensor is tripped
}
Questions?
www.sparkfun.com
6175 Longbow Drive, Suite 200
Boulder, Colorado 80301

More Related Content

PPT
Arduino sectionprogramming slides
PPT
Arduino section programming slides
PDF
Arduino for Beginners
PPTX
Introduction to Arduino Microcontroller
PPTX
Arduino board program for Mobile robotss
PDF
PDF
Arduino reference
PDF
Intro to Arduino Programming.pdf
Arduino sectionprogramming slides
Arduino section programming slides
Arduino for Beginners
Introduction to Arduino Microcontroller
Arduino board program for Mobile robotss
Arduino reference
Intro to Arduino Programming.pdf

Similar to Arduino Section Programming - from Sparkfun (20)

PDF
The IoT Academy IoT Training Arduino Part 3 programming
PDF
Lesson-4-Arduino-Programming-dsBasics.pdf
PPTX
3.1 coding (project)
PPTX
Arduino Functions
KEY
Hello Arduino.
PDF
Programming arduino makeymakey
PDF
arduino
PDF
Arduino programming
PPTX
PPTX
Introduction to the Arduino
PDF
Arduino - Module 1.pdf
PDF
Introduction to Arduino Programming
PPTX
Arduino cic3
PPTX
Arduino course
PDF
arduinocourse-180308074529 (1).pdf
PDF
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
PDF
[Apostila] programação arduíno brian w. evans
PPTX
Ch_2_8,9,10.pptx
PPTX
Audible Objects
PPT
Arduino_CSE ece ppt for working and principal of arduino.ppt
The IoT Academy IoT Training Arduino Part 3 programming
Lesson-4-Arduino-Programming-dsBasics.pdf
3.1 coding (project)
Arduino Functions
Hello Arduino.
Programming arduino makeymakey
arduino
Arduino programming
Introduction to the Arduino
Arduino - Module 1.pdf
Introduction to Arduino Programming
Arduino cic3
Arduino course
arduinocourse-180308074529 (1).pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
[Apostila] programação arduíno brian w. evans
Ch_2_8,9,10.pptx
Audible Objects
Arduino_CSE ece ppt for working and principal of arduino.ppt
Ad

Recently uploaded (20)

PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Cell Structure & Organelles in detailed.
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Business Ethics Teaching Materials for college
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
The Final Stretch: How to Release a Game and Not Die in the Process.
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction and Scope of Bichemistry.pptx
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Onica Farming 24rsclub profitable farm business
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Cell Structure & Organelles in detailed.
Module 3: Health Systems Tutorial Slides S2 2025
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
O5-L3 Freight Transport Ops (International) V1.pdf
Renaissance Architecture: A Journey from Faith to Humanism
UPPER GASTRO INTESTINAL DISORDER.docx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Pre independence Education in Inndia.pdf
Business Ethics Teaching Materials for college
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
NOI Hackathon - Summer Edition - GreenThumber.pptx
How to Manage Starshipit in Odoo 18 - Odoo Slides
Ad

Arduino Section Programming - from Sparkfun