Adobe Scan 01 Apr 2025
Adobe Scan 01 Apr 2025
With the increasing demand for programming, there was a need for a device that could
program electrical devices therefore, Arduino was introduced. Arduino is a board made up of
several interconnected components like microcontrollers, digital pins, analog pins,
power
supplies, and crystal oscillators which give Arduino the ability to program electronic
instruments. You must be familiar with the idea that an Arduino board can be programmed to
illuminate an LED. The Arduino has its hardware and software using which it can
devices. Let us takea look at the Arduino board. program
10
DIGITAL (PO-)
R) ARDUINO
OUNO) (1ON
w.arduino.ce - do in Italy
PONER ANALOG IN
Electronic Signals
communication:
There are two types of signals that are used for
Analog Signal: Analog signals can take any value in
a given continuous range of values.
Generally, analog signals used in Arduino are around 0V.to
SV. The analog pins can take data up
large values as input in the Arduino. These
to8-bit resolution therefore, they are used for taking
signals carry data in avery accurate form without many errors.
which are, high(1") and low(0).
Digital Signal: Digital signals can only take discrete values requires only two values. The
These signals are usually used to Arduino on or off which
known as the binary
collection of two values (0 and 1) can be used to generate asequence transmitted without much
ones. This is how data is
sequence which is a collection of zeroes and
errors.
memory requirement but this can lead to certain errors like quantization
Brackets
There are two types of brackets utilized in Arduino coding, as given below:
Parentheses: When writing a function in IDE, the parentheses brackets are used to include
addition to this,
the argument parameters, such as methods, functions, or code statements. In
the bracket is also used for defining the precedence order while dealing with mathematical
equations. These brackets are represented by ().
Curly Brackets: Curly brackets are used to open and close all the statements in the functions
or out of the functions. Note that a closed curly bracket always follows the open curly
bracket in the code for proper layout. These brackets are denoted by'{}.
Open curly bracket-'{"
Closed curly bracket -'}'
Line Com ment
There are two types of line comments, let us study them individually:
Single-line comment: As the name suggests, the single lines that follow two forward
slashes are known as single-line comments. These statements are known as comments
because the compiler ignores all the characters that come after two forward slashes in a
single line. Comments are hidden when the output is presented. Comments are added for
he sole purpose of comprehension of the code and for writing necessary information for
user reference.
I/ This is aconment
Multi-line comment: The single line comment extends to one line and the Multi-line
comment is used for adding comments in multiple lines. The syntax is a forward slasn
followed by an asterisk symbol (*), ending witha */. It is mostly used for commenting
larger text blocks that are not interpreted by the compiler and solely for reference purposes
of users.
* This is a multiline comment*/
Coding Screen
IT you open the coding screen of your IDE, you will realize that it is divided into two sections
namely, setup) and loop0. The setup segment is the first block and is implemented first for
preparing the necessary environment needed for running other commands. This coding screen
is shown below:
Arduino IDE File Edit Sketch Tools Help
It is important to note that the setup and loop blocks must have statements that are enclosed
within curly brackets. Depending on the type of project you are working on, you can initialize
the setup in setup() anddefine other necessary statements in the loop() block. Let us study each
section individually
For example
void setup (){
Coding statement 1;
Coding statement 2;
Coding statement n;
void loop0{
Coding statement 1;
Coding statement 2;
Coding statement n;
Setup
Setup contains the very beginning section of the code that must be executed first. The pin
modes, libraries, variables, et., are included in the seiup section so that no problem occurs
when the remaining code runs. It is executed only once during the uploading of the program
and after resetting or powering up the Arduino board.
Zero setup () resides at the top of each sketch. When the program runs after completion, it
heads towards the setup section to initialize the setup and include all the necessary libraries all
at once.
Loop
Ihe loop contains statements that are executed repeatedly. Unlike, the setup section there is no
restriction on running this code once, it can run multiple times according to the value of
variables.
Time
The basic unit of measuring time in Arduino programming is amillisecond.
Isec= 1000 milliseconds
Commonly used functions inArduino:
pinMode(pin, mode):
Sets the specified pin to be an input or
output.
pin: Thenumber of the digital pin.
mode: INPUT or OUTPUT.
" digitalWrite(pin, value):
Writes adigital value (HIGH or LOW) to aspecified
digital pin.
pin: The number of the digital pin.
value: HIGH or LOW.
digitalRead(pin):
Reads the digital value (HIGH or LOW) from a specified digital pin.
pin: The number of the digital pin.
analogWrite(pin, value):
Writes an analog value (0-255) to a PWM (Pulse Width Modulation) pin.
pin: The number of the PWM pin.
value: An integer between 0 and 255.
analog pin.
from a specified
a n a l o g R c a d ( p i n ) :
milliseconds.
to delay.
milliseconds
The number of
o milliseconds:
number of milliseconds since the Arduino started running.
millis0: Returns the
started running.
number of microseconds since the Arduino
micros(): Returns the
Serial Communication:
Serial.begin(baudRate):
specified baud rate.
Initializes serial communication at the
baudRate: The baud rate (e.g.,
9600, 115200).
Serial.print(data):
Prints data to the serial monitor.
text, numbers).
data: The data to be printed (e.g.,