CTECH
CTECH
ARDUINO
• Arduino is a prototype platform (open-
source) based on an easy-to-use hardware
and software.
• It consists of a circuit board, which can be
programed (referred to as a microcontroller)
and a ready-made software called Arduino
IDE (Integrated Development Environment),
which is used to write and upload the
computer code to the physical board.
KEY FEATURES
• Able to read analog or digital input signals
from different sensors and turn it into an
output
• Can be controlled by sending a set of
instructions via Arduino IDE
• Does not need an extra piece of hardware
in order to load a new code onto the board VARIABLES
• Simplified version of C++ • Arduino data types and constants
BOARD TYPES
• Arduino boards based on ATMEGA328
microcontroller.
• Arduino boards based on ATMEGA32u4 FUNCTIONS
microcontroller.
• Arduino boards based on ATMEGA2560
microcontroller. [Digital I/O] digitalRead ()
• Arduino boards based on AT91SAM3X8E Description Reads the value from a specified digital
pin, either HIGH or LOW
microcontroller. Syntax digitalRead (pin)
ARDUINO PROGRAM STRUCTURE Parameters pin: the Arduino pin number you want to
• Arduino programs can be divided in three read
Returns HIGH or LOW
main parts: Structure, Values, and
Functions.
STRUCTURE [Digital I/O] digitalWrite ()
Description Write a HIGH or LOW value to a digital pin
• Software structure consists of two main Syntax digitalWrite (pin, value)
functions: Parameters pin: the Arduino pin number
value: HIGH or LOW
setup() function Returns Nothing
• setup() function is called when a sketch
starts.
[Digital I/O] pinMode ()
• will only run once, after each power up or Description Configures the specific pin to behave
reset of the Arduino board. either as an input or an output
loop() function Syntax pinMode (pin, mode)
Parameters pin: the Arduino pin number to set the
• the loop() function does precisely what its mode of
name suggests, and loops consecutively, mode: INPUT, OUTPUT or
INPUT_PULLUP
allowing your program to change and
Returns Nothing
respond.
FUNCTION
[Analog I/O] analogRead ()
• for controlling the Arduino board and Description Reads the value from the specified analog
performing computation pin
Syntax analogRead (pin)
Parameters pin: the name of the analog input pin to
read from
1
AMOLO 10 - EINSTEIN
CTECH 10.1 | 2023-2024
Returns The analog reading on the pin. •data type that takes up one byte of
Data type: int
memory that stores a character value
• but characters are stored as numbers
[Analog I/O] analogWrite () using ASCII Chart
Description Writes an analog value (PWM wave) to a
pin UNSIGNED CHAR
Syntax analogWrite (pin, value) • encodes number from 0 to 255
Parameters pin: the Arduino pin to write to; allowed
data types: int
BYTE
value: the duty cycle: 0 (always off) and • stores 8-bit unsigned number, 0 to 255
255 (always on);
allowed data types: int. INT
Returns Nothing • stores a 16-bit (2-byte) value
UNSIGNED INT
[Time] delay () • nstead of storing negative numbers,
Description Pauses the program for the amount of time however, they only store positive
(in milliseconds) specified as parameter.
(thousand ms = one sec) values, yielding a useful range of 0 to
Syntax delay(ms) 65,535
Parameters ms: the number of milliseconds to pause;
allowed data types: unsigned long
WORD
Returns Nothing • a word stores a 16-bit unsigned number
LONG
[Time] delayMicroseconds () • extended size variables for number
Description Pauses the program for the amount of time storage, and store 32 bits (4 bytes),
(in microseconds) specified by the
parameter. from -2,147,483,648 to 2,147,483,647.
(million us = one sec) UNSIGNED LONG
Syntax delayMircroseconds (us)
Parameters us: the number of microseconds to pause;
• unlike standard longs, unsigned longs
allowed data types: unsigned int will not store negative numbers, making
Returns Nothing their range from 0 to 4,294,967,295
SHORT
[Time] micros () • stores a 16-bit (2-byte) value. This
Description Returns the number of microseconds since yields a range of -32,768 to 32,767
the Arduino board began running the
current program. This number will overflow
FLOAT
(go back to zero), after approximately 70 •data type for floating-point number is a
minutes.
Syntax time = micros ()
number that has a decimal point
Parameters None DOUBLE
Returns Returns the number of microseconds since
the Arduino board began running the
• double implementation is exactly the
current program. Date type: unsigned same as the float, with no gain in
precision
o
Inside a function or a block, which is
ARDUINO DATA TYPES called local variables.
VOID o In the definition of function
parameters, which is called formal
• used only in function declarations;
parameters.
function is expected to return no
o Outside of all functions, which is
information to the function from which it
called global variables.
was called
LOCAL VARIABLES
BOOLEAN
• Variables that are declared inside a function
• holds one of two values, true or false or block are local variables. They can be
CHAR used only by the statements that are inside
2
AMOLO 10 - EINSTEIN
CTECH 10.1 | 2023-2024
the functions, usually at the top of the are not equal then
program. The global variables will hold their condition
becomes true.
value throughout the lifetime of your less than < Checks if the (A < B)
program. value of left is true
operand is less
than the value of
right operand, if
yes then condition
becomes true.
greater > Checks if the (A > B)
than value of left is not
operand is true
greater than the
value of right
operand, if yes
then condition
becomes true.
less than or <= Checks if the (A <= B)
equal to value of left is true
operand is less
than or equal to
the value of right
ARDUINO OPERATORS operand, if yes
OPERATORS then condition
becomes true.
• An operator is a symbol that tells the greater >= Checks if the (A >= B)
compiler to perform specific mathematical or than or value of left is true
logical functions. equal to operand is
greater than or
equal to the value
ARITHMETIC OPERATORS of right operand, if
• Assume variable A holds 10 and variable B yes then condition
becomes true.
holds 20
Operator Operator Description Example
name simple BOOLEAN OPERATORS
assignment = Stores the value A=B • Assume variable A holds 10 and variable B
operator to the right of
the equal sign in holds 20
the variable to
the left of the Operator Operator Description Example
equal sign. name simple
addition + Adds two A+B and && Called Logical (A && B)
operands will give AND operator. If is true
30 both the
subtraction - Subtracts A – B will operands are
second operand give -10 non-zero then
from the first then condition
multiplication * Multiply both A*B will becomes true.
operands give 200 or || Called Logical (A || B) is
division / Divide B/A will OR Operator. If true
numerator by give 2 any of the two
denominator operands is non-
modulo % Modulus B%A will zero then then
Operator and give 0 condition
remainder of becomes true.
after an integer not ! Called Logical !(A &&
division NOT Operator. B) is
Use to reverses false
3
AMOLO 10 - EINSTEIN
CTECH 10.1 | 2023-2024
4
AMOLO 10 - EINSTEIN