0% found this document useful (0 votes)
70 views

Arduino IDE Integrated Development Environment

The document provides an overview of the Arduino IDE and common programming concepts for the Arduino board. It discusses the Arduino sketch which is the program uploaded and run on the board. Key functions include setup() and loop() which initialize the board and provide the main program flow. It also covers configuring pins as inputs or outputs, reading/writing digital and analog values, delay functions, and basic programming structures like if/else statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Arduino IDE Integrated Development Environment

The document provides an overview of the Arduino IDE and common programming concepts for the Arduino board. It discusses the Arduino sketch which is the program uploaded and run on the board. Key functions include setup() and loop() which initialize the board and provide the main program flow. It also covers configuring pins as inputs or outputs, reading/writing digital and analog values, delay functions, and basic programming structures like if/else statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Arduino IDE –

Integrated Development
Environment
PREPARED BY:
CHRISTOPHER JOHN I. GAYTA, ECE, ECT
Arduino Sketch
Arduino sketch is the name that setup()
Arduino uses for a program.
It’s the unit of code that is loop()
uploaded to and runs on an
Arduino board.
Running the first code in Arduino
UNO
Setup () and Loop () Functions
void setup() void loop()
{ {

} }
executed only once when run continuously from top
the sketch is run to bottom and then back
to the top
{
is the opening brace of the
functions that tells that all
statements starting from here
are inside the function.

}
is the closing brace of the
function.
;
is used to terminate
the statement.
Serial.begin(9600);
This statement sets up
the speed of the serial
port to 9600 baud.
Serial.println(“Hello World”);

In this statement, any text


can be put between the
opening and closing quotes
(” “) and it will be
displayed in the serial
monitor window.
ACTIVITY
CREATE A SKETCH (PROGRAM) THAT WILL
DISPLAY THE FOLLOWING ON THE SERIAL
MONITOR
YOUR NAME AND SCHOOL (ONLY ONCE)
YOUR FAVORATE FOOD (CONTINUOUSLY)
VARIABLES
int count = 0;

void setup()
{ A variable is a place to
Serial.begin(9600); store a piece of data. It has
}
a name, a value, and a type.
void loop() For example, this statement
{
count = count + 1;
(called a declaration):
Serial.println(count);
}
Global variables are
declared outside any
function, and they can be
accessed (used) on any
function in the program.

Local variables are declared inside a function, and can be used


only inside that function. It is possible to have local variables with
the same name in different functions.
Global variables are
declared outside any
function, and they can
be accessed (used) on
any function in the
program.
Local variables are
declared inside a
function, and can be
used only inside that
function. It is possible to
have local variables
with the same name in
different functions.
VARIABLE DATATYPE
DATATYP DESCRIPTION
E
ASCII value of characters like alphabets, symbols etc. It can also
char store a signed number that is in range of -128 to 127. Character
literals are written in single quotes like 'a', '#' etc
int signed integer value that is in range of -32,768 to 32,767
signed integer value that is in range of -2,147,483,648 to
long
2,147,483,647
integer or a value with decimal point (say 12.15) that is in range of
float
-3.4028235E+38 to 3.4028235E+38
bool 1 or 0
How to name a Variable?
• Variables can consist of both uppercase (A-Z) and lowercase(a-z) letters.
• Variables can contain numbers 0 to 9, but cannot start with a number.
• Variables may not have the same names as Arduino language keywords, e.g.
you cannot have a variable named float.
• Variables must have unique names, i.e. you cannot have two variables with the
same name.
• Variable names are case sensitive, so Count and count are two different
variables.
• Variables may not contain any special characters, except the underscore (_).
int LEDpin = 13;
LEDpin variable will have a value of 13
DATATYPE:
int
int var = val;
var variable will have same value with val

int var = 32768;


The maximum value of the int is 32767. If the value is
over the max, it will recirculate on the min. var
variable will have a value of -32768.

int var = true;


True has a value equivalent to 1. So var variable will
have 1 value.
int var = 13.4; DATATYPE:
var variable will have a value of 13
int
int var = 13.9;
var variable will have a value of 13

int var = -52.9;


var variable will have a value of -52

int var = 5 + 4/6;


var variable will have a value of 5
bool var = 1; DATATYPE:
var variable will have a value of 1
bool
bool var = 0;
var variable will have a value of 0

bool var = true;


var variable will have a value of 1

bool var = false;


var variable will have a value of 0
bool var = 8; DATATYPE:
var variable will have a value of 1
bool
bool var = 0.1;
var variable will have a value of 1

bool var = -32;


var variable will have a value of 1

bool var = 0;
var variable will have a value of 0
DATATYPE:
float var = 0.1;
float
var variable will have a value of 0.1

float var = 0.12;


var variable will have a value of 0.12

float var = -0.3333;


var variable will have a value of 0.3333
String var = “Hello World”; DATATYPE:
var variable will have a value of “Hello World”
String
String var = String(‘a’);
var variable will have a value of “A”

String var = String(“This is a string”);


var variable will have a value of “This is a string”
int var1 = 123; DATATYPE:
String
String var2 = String(var1);
var2 variable will have a value of “123”

String var = String(13);


var variable will have a value of “13”
CONFIGURING
A DIGITAL PIN
AS AN OUTPUT
pinMode(pin, OUTPUT/INPUT);
Inorder to declare a digital pin as an output, that pin
should be configured as OUTPUT using pinMode function
available on Arduino IDE

pin is the digital pin number you want to initialize as


output.
int LED_BUILTIN = 9

void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
digitalWrite(pin, HIGH or LOW)
write a digital pin, to a HIGH or LOW value

Ifthe pin has been configured as an OUTPUT with


pinMode(), its voltage will be set to the corresponding
value: 5V for HIGH, 0V for LOW.
digitalRead(pin);
Reads the value from the specified digital
pin, either HIGH or LOW.
Analog Output
through PWM
Pulse Width Modulation
PWM or Pulse Width Modulation is a
technique for getting an analog output
using digital signals.
analogWrite(pin, value);
0% brightness| analogWrite(pin, 0)
25% brightness | analogWrite(pin, 64)
50% brightness | analogWrite(pin, 127)
75% brightness | analogWrite(pin, 191)
100% brightness | analogWrite(pin, 255)
analogRead(pin);
delay();
Pauses the program for the amount of time
(in milliseconds) specified as parameter.
delay(1000); // waits for a second
map();
Recalibrates a number from one range to
another.
Since we used the term “Range”, this
means that the numbers are from varying
values or ANALOG signals.
map();
Ex. Val= analogRead(val);
Val = map (Val, 0, 1023, 0, 255)

The val variable received signals with values of range 0-


1023 but you want to scale it to 0-255.

map (variable, old low, old high, new low, new high);
COMPARISON OPERATOR
BOOLEAN OPERATOR
if STATEMENT

The if statement checks for a


condition and executes the
proceeding statement or set of
statements if the condition is
‘true’.
If-else STATEMENT

The else statement is added in if


statement. It checks for a condition
and executes the proceeding
statement or set of statements if the
condition is false.
else-if

The else statement is added in if statement. It checks for a condition


and executes the proceeding statement or set of statements if the
condition is false.
RECAP/SUMMARY
Serial.begin(9600);
void setup() void loop() - To initialize the
{ { serial monitor
Serial.println(“ “);
} } - Displays in the serial
monitor whatever is in
pinMode(pin, OUTPUT/INPUT) the open and close
- Declares the digital pin number and double apostrophe
whether you want it as an OUPUT or
INPUT
RECAP/SUMMARY
digitalWrite(pin, HIGH/LOW); digitalRead(pin);
- Sets the pin to HIGH (turns on) - Reads the state of the pin
or LOW (turns off) whether its in HIGH or LOW
analogWrite(pin, value); analogRead(pin);
- Gives the pin varying value - Reads the value being sent to
ranging from 0 (always off, the pin, usually, by sensors.
minimum state) to 255 (always
on, maximum state) delay(value);
- Pauses for a time set by the
value in millisecond
Thank you
for
listening!

You might also like