Arduino Notes - IoT
Arduino Notes - IoT
Definition :
Arduino is a prototype platform (open-source) based on easy-to-use hardware and software. It
consists of a circuit board, which can be programmed (referred to as a microcontroller) and an
open source software called Arduino IDE (Integrated Development Environment), which is
used to write and upload the computer code to the physical board.
Hardware Description :
The Arduino Uno is a microcontroller board based on the ATmega328. It has 14 digital
input/output pins, 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack,
memory and a reset button.
1. Brackets
There are two types of brackets used in the Arduino coding, 1) Parentheses ( ) and 2) Curly
Brackets { }
Parentheses ( )
The parentheses brackets are the group of the arguments, such as method, function, or a code
statement. These are also used to group the math equations.
Curly Brackets { }
The statements in the code are enclosed in the curly brackets. We always require closed curly
brackets to match the open curly bracket in the code or sketch.
2. Line Comment
There are two types of line comments, which are listed below:
● Single line comment - The text that is written after the two forward slashes are
considered as a single line comment. The compiler ignores the code written after the two
forward slashes.
● Multi-line comment - The Multi-line comment is written to group the information for
clear understanding. It starts with the single forward slash and an asterisk symbol (/ *).
It also ends with the / *.
void setup ()
{
pinMode ( 13, OUTPUT); // to set the OUTPUT mode of pin number 13.
}
void loop ()
{
digitalWrite (13, HIGH);
delay (4000); // 4 seconds = 4 x 1000 milliseconds
digitalWrite (13, LOW);
delay (1500); // 1.5 seconds = 1.5 x 1000 milliseconds
}
A. pinMode ( )
The specific pin number is set as the INPUT or OUTPUT in the pinMode () function.
The Syntax is: pinMode (pin, mode)
Where,
pin: It is the pin number. We can select the pin number according to the requirements.
Mode: We can set the mode as INPUT or OUTPUT according to the corresponding pin number.
B. digitalWrite( )
The digitalWrite ( ) function is used to set the value of a pin as HIGH or LOW.
Where,
HIGH: It sets the value of the voltage. For the 5V board, it will set the value of 5V, while for
3.3V, it will set the value of 3.3V.
LOW: It sets the value = 0 (GND).
If we do not set the pinMode as OUTPUT, the LED may light dim.
The syntax is: digitalWrite( pin, value HIGH/LOW)
C. delay ( )
The delay () function is a blocking function to pause a program from doing a task during the
specified duration in milliseconds.
For example, - delay (2000)
Where, 1 sec = 1000 millisecond
Hence, it will provide a delay of 2 seconds.
Case Study :