0% found this document useful (0 votes)
7 views42 pages

iot_file

The document is a practical file for a Bachelor of Computer Applications course at Vivekananda Institute of Professional Studies, focusing on the Internet of Things (IoT) and Arduino platform. It covers the introduction to Arduino, various sensors and actuators, their applications, and programming basics, along with project details. Additionally, it discusses different types of Arduino boards and sensors, including analog and digital types, and their functionalities in electronic applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views42 pages

iot_file

The document is a practical file for a Bachelor of Computer Applications course at Vivekananda Institute of Professional Studies, focusing on the Internet of Things (IoT) and Arduino platform. It covers the introduction to Arduino, various sensors and actuators, their applications, and programming basics, along with project details. Additionally, it discusses different types of Arduino boards and sensors, including analog and digital types, and their functionalities in electronic applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

VIVEKANANDA INSTITUTE OF PROFESSIONAL STUDIES

VIVEKANANDA SCHOOL OF INFORMATION TECHNOLOGY

BACHELOR OF COMPUTER APPLICATION


PRACTICAL FILE IOT - IOT LAB

BCA 372

Guru Gobind Singh Indraprastha University


Sector - 16C Dwarka, Delhi – 110078

SUBMITTED TO: SUBMITTED BY:

Dr. Cosmena Kanak Aggarwal (00337702022)


Sr. Assistant Professor Indu Mudgal (00287702022)
Rohit Tulsyani (02517702022)
VSIT BCA 6 (A)
INDEX

S No. Title Sign Date


1. Introduction to the Arduino platform, introduction to various sensors
and actuators & its application.

2. (A) Arduino IDE and Operators in IDE.


(B) Frequently used functions in Arduino IDE.

3. Study and Install the IDE of Arduino.

4. Project details of IOT project.


PRACTICAL 1: Introduction to the Arduino platform, introduction to various
sensors and actuators & its application.

Theory:
Arduino is an open-source prototyping platform in electronics based on easy-to-use hardware
and software. Arduino is a microcontroller based prototyping board which can be used in
developing digital devices that can read inputs like finger on a button, touch on a screen, light
on a sensor etc. and turning it in to output like switching on an LED, rotating a motor, playing
songs through a speaker etc.
The Arduino board can be programmed to do anything by simply programming the
microcontroller on board using a set of instructions for which, the Arduino board consists of a
USB plug to communicate with your computer and a bunch of connection sockets that can be
wired to external devices like motors, LEDs etc.

Power (USB / Barrel Jack)


Every Arduino board needs a way to be connected to a power source. The Arduino UNO can
be powered from a USB cable coming from your computer or a wall power supply that is
terminated in a barrel jack. Here, USB connection is labeled (1) and the barrel jack is labeled
(2). USB connection is helps to load code onto your Arduino board. NOTE: The
recommended voltage for most Arduino models is between 6 and 12 Volts.
Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)
Pins on Arduino are places where we connect wires to construct a circuit using black plastic
'headers' that allows to plug a wire right into the board. The Arduino has several different
kinds of pins, each of which is labeled on the board and used for different functions.
• GND (3): Short for 'Ground'. There are several GND pins on the Arduino, any of
which can be used to ground your circuit.
• 5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of power, and the
3.3V pin supplies 3.3 volts of power.
• Analog (6): The area of pins under the 'Analog In' label (A0 through A5 on the UNO)
are Analog In pins. These pins can read the signal from an analog sensor (like a
temperature sensor) and convert it into a digital value that we can read.
• Digital (7): Across from the analog pins are the digital pins (0 through 13 on the
UNO). These pins can be used for both digital input (like telling if a button is pushed)
and digital output (like powering an LED).
• PWM (8): Notice tilde (~) symbol, next to some digital pins (3, 5, 6, 9, 10, and 11 on
the UNO). These pins act as normal digital pins, but can also be used for something
called Pulse-Width Modulation (PWM).
• AREF (9): Stands for Analog Reference. Most of the time you can leave this pin
alone. It is sometimes used to set an external reference voltage (between 0 and 5
Volts) as the upper limit for the analog input pins.

Reset Button
The Arduino has a reset button (10). Pushing it will temporarily connect the reset pin to
ground and restart any code that is loaded on the Arduino.

Power LED Indicator


Tiny LED next to word 'ON' (11). This LED lights up whenever we plug Arduino into a
power source. If this light doesn't turn on, there's a good chance something is wrong. Time to
re-check your circuit!

Voltage Regulator
Voltage regulator (14) controls amount of voltage that is let into the Arduino board. It will turn
away an extra voltage that might harm the circuit.

Arduino Programming Language

The Arduino Programming Language is basically a framework built on top of C++. It’s not a
real programming language.
A program written in the Arduino Programming Language is called sketch. A sketch is
normally saved with the .ino extension (from Arduino).
The main difference from “normal” C or C++ is that you wrap all your code into 2 main
functions.
One is called setup(), the other is called loop(). The first is called once, when program starts,
the second is repeatedly called while your program is running.
We don’t have a main() function like you are used to in C/C++ as the entry point for a
program. Once you compile your sketch, the IDE will make sure the end result is a correct
C++ program and will basically add the missing glue by pre-processing it.

Types of Arduino Boards

There are many types of Arduino boards available in the market which can be programmed
using the Arduino IDE. The reasons for different types of boards are different power supply
requirements, connectivity options, their applications etc.
Arduino boards are available in different sizes, form factors, different no. of I/O pins etc.
Some of the commonly known and frequently used Arduino boards are Arduino UNO,
Arduino Mega, Arduino Nano, Arduino Micro and Arduino Lilypad.

There are add-on modules called Arduino Shields which can be used to extend the
functionalities of the Arduino boards. Some of the commonly used shields are Arduino Proto
shield, Arduino WiFi Shield and Arduino Yun Shield.

Arduino Uno (R3)


The Uno is a huge option for your initial Arduino. It consists of 14-digital I/O pins, where
6pins can be used as PWM (pulse width modulation outputs), 6-analog inputs, a reset button, a
power jack, a USB connection and more. It includes everything required to hold up the
microcontroller; simply attach it to a PC with the help of a USB cable and give the supply to
get started with a AC-to-DC adapter or battery.
LilyPad Arduino Board
The Lily Pad Arduino board is a wearable e-textile technology expanded by Leah
"Buechley"and considerately designed by "Leah and SparkFun". Each board was imaginatively
designed with huge connecting pads & a smooth back to let them to be sewn into clothing
using conductive thread. This Arduino also comprises of I/O, power, and also sensor boards
which are built especially for e-textiles. These are even washable!

RedBoard Arduino Board


The RedBoard aAduino board can be programmed using a Mini-B USB cable using the
Arduino IDE. It will work on Windows 8 without having to modify your security settings.It is
more constant due to the USB or FTDI chip we used and also it is entirely flat on the back.
Creating it is very simple to utilize in the project design. Just plug the board, select the menu
option to choose an Arduino UNO and you are ready to upload the program. You can control
the RedBoard over USB cable using the barrel jack.
Arduino Mega (R3) Board
The Arduino Mega is similar to the UNO's big brother. It includes lots of digital I/O pins
(from that, 14-pins can be used as PWM o/ps), 6-analog inputs, a reset button, a power jack, a
USB connection and a reset button. It includes everything required to hold up the
microcontroller; simply attach it to a PC with the help of a USB cable and give the supply to
get started with a AC-to-DC adapter or battery.The huge number of pins make this Arduino
board very helpful for designing the projects that need a bunch of digital i/ps or o/ps like lots
buttons.

Arduino Leonardo Board


The first development board of an Arduino is the Leonardo board. This board uses one
microcontroller along with the USB. That means, it can be very simple and cheap also.
Because this board handles USB directly, program libraries are obtainable which let the
Arduino board to follow a keyboard of the computer, mouse, etc.
Introduction to Sensors and Actuators:
Sensors and actuators are two critical components of every closed loop control system. Such
a system is also called a mechatronics system. Mechatronics system consists of a sensing unit,
a controller, and an actuating unit. Sensing unit consist of additional components such as
filters, amplifiers, modulators, and other signal conditioners. Controller accepts information
from sensing unit, makes decisions based on control algorithm, and outputs commands to
actuating unit. Actuating unit consists of an actuator and optionally a power supply and a
coupling mechanism.

What is a Sensors?
A Sensor is a converter that measures a physical quantity and converts it into a signal which
can be read by an observer or by an (today mostly electronic) instrument.

SENSORS
We frequently use different types of sensors in several electrical and electronic applications,
which are classified as chemical, pressure, temperature, position, force, proximity, thermal,
presence, flow, optical, automotive, sound, speed, magnetic, electric, heat, fiber-optic
sensors, analog and digital sensors. A sensor can be defined as an appliance that detects
changes in
physical or electrical or other quantities and by this means, generally, produces an electrical
or optical signal output as an acknowledgement of the change in that specific quantity.

What is an Actuator?
An Actuator is a type of motor for moving or controlling a mechanism or system. It is
operated by a source of energy, typically electric current, hydraulic fluid pressure, or
pneumaticpressure, and converts that energy into motion. An actuator is the mechanism by
which a control system acts upon an environment.
Actuators are devices which drive a machine (robot) including its grippers. Muscles of a
human arm and hand. While human arm provides motion, hand is used for object
manipulation. So, actuators in robots (machine) provides motion while grippers manipulates
objects. An actuator system comprises of several subsystems, namely,

(i) Power supply; (ii) Power amplifier; (iii) Servomotor; (iv) Transmission system.

Different Types of Sensors


The following is a list of different types of sensors that are commonly used in various
applications. All these sensors are used for measuring one of the physical properties like
Temperature, Resistance, Capacitance, Conduction, Heat Transfer etc.

1. Temperature Sensor
2. Proximity Sensor
3. Accelerometer
4. IR Sensor (Infrared Sensor)
5. Pressure Sensor
6. Light Sensor
7. Ultrasonic Sensor
8. Smoke, Gas and Alcohol Sensor
9. Touch Sensor
10. Color Sensor
ANALOG SENSORS

1. Accelerometers
Analog sensors that detect changes in position, velocity, orientation, shock, vibration, and
tilt by sensing motion are called as accelerometers. These analog accelerometers are again
classified into different types based on the variety of configurations and sensitivities.

These accelerometers are available as analog and digital sensors, based on the output signal.
Analog accelerometer produces a constant variable voltage based on the amount of
acceleration applied to the accelerometer

a. Small board size - Just 28mm X 23mm


b. Simple 5 pin interface (VCC, GND, Xout, Yout, Zout, Self Test)
c. Needs no external components
d. Easy to mount on General purpose PCB, Breadboards and special PCBs
e. Low Current Consumption: 500 μA
f. Low Voltage Operation: 5V

2. Light Sensors
Analog sensors that are used for detecting the amount of light striking the sensors are
called as light sensors. These analog light sensors are again classified into various types
such as photo-resistor, Cadmium Sulfide (CdS), and, photocell.
Light dependent resistor (LDR) can be used as analog light sensor which can be used to
switch on and off loads automatically based on the day light incident on the LDR. The
resistance of the LDR increases with decrease in light and decreases with increase in
light.

3. Sound Sensors
Analog sensors that are used to sense sound level are called as sound sensors. These analog
sound sensors translate the amplitude of the acoustic volume of the sound into an electrical
voltage for sensing sound level. This process requires somecircuitry, and utilizes
microcontroller along with a microphone for creating an analog output signal.

4. Pressure Sensor
The analog sensors that are used to measure the amount of pressure applied to a sensor are
called as analog pressure sensors. Pressure sensor will produce an analog output signal
that is proportional to the amount of applied pressure. These piezoelectric sensors are one
type of pressure sensors that can produce an analog output voltage signal proportional to
the pressure applied to the piezoelectric sensor.
5. Analog Temperature sensor
Temperature sensors are widely available as both digital and analog sensors. Typically
used analog temperature sensors are thermistors. There are different types of thermistors
thatare used for different applications. Thermistor is a thermally sensitive resistor that is
used for detecting changes in temperature. If the temperature increases, then the electrical
resistance of thermistor increases. Similarly, if temperature decreases, then the resistance
decreases. It is used in various temperature sensor applications.

6. Water Level Sensor


Water Sensor water level sensor is an easy-to-use, cost-effective high level/drop
recognition sensor, which is obtained by having a series of parallel wires exposed traces
measured droplets/water volume to determine the water level. Easy to complete water to
analog signal conversion and output analog values can be directly read Arduino
development board to achieve the level alarm effect.
DIGITAL SENSORS:

Electronic sensors or electrochemical sensors in which data conversion and data


transmission takes place digitally are called as digital sensors. These digital sensors are
replacing analog sensors as they can overcome the drawbacks of analog sensors. The
digital sensor consists of majorly three components: senor, cable, and transmitter. In
digital sensors, the signal measured is directly converted into digital signal output inside
the digital sensor itself. And this digital signal is transmitted through cable digitally. There
are different types of digital sensors that overcome disadvantages of analog sensors.

1. Digital Temperature and Humidity Sensor

DHT11 and DHT22 digital temperature sensor available for measurement of temperature
and humidity DHT11 sensor includes a resistive-type humidity measurement component,
an NTC temperature measurement component and a high- performance 8-bit
microcontroller inside, and provides calibrated digital signal output. It has high reliability
and excellent longterm stability

DHT22 includes a capacitive sensor wet component and a high-precision temperature


measurement device, and connected with a high-performance 8-bit microcontroller. The
sensor has excellent quality, fast response, strong anti- jamming capability, and high cost.
Standard single-bus interface, system integration quick and easy. Small size, low power
consumption, signal transmission distance up to 20 meters, making it the best choice of all
kinds of applications and even the most demanding applications. DHT22 has higher
precision and can replace the expensive imported SHT10 temperature and humidity
sensor.

2. Ultrasonic Sensor
Ultrasonic sensor distance measuring module is stable, measure the distance accurately. The
sensor with High precision, blind spots (3cm) super close. Its provides a full set of ranging
process

3. IR Sensor (Obstacle sensor)


IR Obstacle Sensor consists of a TSOP as a receiver and IR LED as a transmitter. TSOP as a
receiver provides flexibility of sensing light.The sensor is perfectly suited for Detecting obstacle
within line of sight. Interface with any device compatible with Digital Signal.
▪ Obstacle Avoider or Obstacle sensor for robots and electronics with range
between 3cms to 7cms
▪ 0.1th inch (2.54 mm) with Breadboard compatiblity
▪ Obstacle sensing LED and Power LED
▪ Arduino, AVR, PIC and other microcontroller Compatible
▪ A compact form on a tiny board
4. Flame sensor)
Flame Detection Sensor Module is sensitive to the flame, but also can ordinary light. Usually
used as a flame Detects a flame or a light source of a wavelength in the range of 760nm
Flame detection distance, lighter flame test can be triggered within 0.8m, if the intensity
of flame is high , the detection distance will be increased.

5. Gas Sensor

It is a hazardous gas detection apparatus for the family, the environment, suitable for
ammonia, aromatic compounds, Sulphur, benzene vapors, smoke and other gases harmful
gas detection, gas-sensitive element test. Air quality sensor is for detecting a wide range of
gases, including NH3, NOx, alcohol, benzene, smoke and CO2. Ideal for use in office
or factory with simple drive and monitoring circuit.

• Dual signal output (analog output, and TTL level output)


• TTL output valid signal is low
• Analog output with increasing concentration, the higher the concentration, the higher
the voltage
• Sulphide, benzene, smoke and other harmful gases with high sensitivity
• Has a long life and reliable stability
• Rapid response recovery characteristics

6. Line Tracker Sensor

Line Tracker sensor consists of 3 IR transmitter and IR receiver pairs. This tracker
sensor is typically used for robots in line following task. It can be used for either dark or
bright line following. The tracker sensor have 3 digital outputs to user indicating the
existence of the line. Every sensor is provided with its own LEDs as indication of line
detection

ACTUATORS

1. Relay
Relay provides an electrical connection between two or more points in response to the
application of a control signal. Relays are basically electrically operated switches that come
in many shapes, sizes and power ratings suitable for all types of applications. Relays can
also have single or multiple contacts within a single package
2. DC Motor
A DC motor (Direct Current motor) is the most common type of motor. DC motors
normally have just two leads, one positive and one negative. If you connect these two
leads directly to a battery, the motor will rotate. If you switch the leads, the motor will
rotate in the opposite direction.

3. Servo Motor
A Servo Motor is a small device that has an output shaft. This shaft can be positioned to
specific angular positions by sending the servo a coded signal. If the coded signal exists on
the input line, the servo will maintain the angular position of the shaft. If the coded signal
changes, the angular position of the shaft changes. In practice, servos are used in radio-
controlled airplanes to position control surfaces like the elevators and rudders. They are
also used in radio-controlled cars, puppets, and of course, robots.
4. Stepper Motor
A Stepper Motor or a step motor is a brushless, synchronous motor, which divides a full
rotation into several steps. Unlike a brushless DC motor, which rotates continuously when
a fixed DC voltage is applied to it, a step motor rotates in discrete step angles

5. Seven Segment Display


The seven segments display a very simple device. It is a combination of 8 LEDs (the
decimal point -DP- is the 8th), which can be arranged so that different combinations can be
used to make numerical digits.

6. LCD Display
An LCD is an electronic display module which uses liquid crystal to produce a visible image.

The 16×2 LCD display is a very basic module commonly used in DIYs and circuits. The
16×2 translates display 16 characters Per line in 2 such lines. In this LCD each character is
displayed in a 5×7 pixel matrix
PRACTICAL 2(A): Arduino IDE and Operators in IDE.

Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text


editor for writing code, a message area, a text console, a toolbar with buttons for common
functions and a series of menus. It connects to Arduino hardware to upload programs and
communicate with them.

Writing Sketches
Programs written using Arduino Software (IDE) are called sketches. These sketches are written
in text editor and are saved with file extension. ino. Editor has features for cutting/pasting and for
searching/replacing text. Message area gives feedback while saving and exporting and also
displays errors. Console displays text output by Arduino Software (IDE), including complete
error messages and other information. Bottom right-hand corner of the window displays the
configured board and serial port. Toolbar buttons allow you to verify and upload programs,
create, open, and save sketches, and open serial monitor.
NB: Versions of the Arduino Software (IDE) prior to 1.0 saved sketches with the extension

.pde. It is possible to open these files with version 1.0, you will be prompted to save the
Verify Checks your code for errors compiling it.
Upload Compiles your code and uploads it to the configured board. If you are using an
external programmer with your board, you can hold down the "shift" key on your computer when
using this icon. The text will change to "Upload using Programmer"

New Creates a new sketch.

Open Presents a menu of all the sketches in your sketchbook. Clicking one will open it
within the current window overwriting its content.
Note: due to a bug in Java, this menu doesn't scroll; if you need to open a sketch late in the
list, use the File | Sketchbook menu instead.

Save Saves your sketch.

Serial Monitor Opens the serial monitor.

Additional commands are found within the five menus: File, Edit, Sketch, Tools, Help. The
menus are context sensitive, which means only those items relevant to the work currently being
carried out are available.

File
• New Creates a new instance of the editor, with the bare minimum structure of a
sketch already in place.
• Open Allows to load a sketch file browsing through the computer drives and folders.
• Open Recent Provides a short list of the most recent sketches, ready to be opened.
• Sketchbook Shows the current sketches within the sketchbook folder structure; clicking
on any name opens the corresponding sketch in a new editor instance. Examples Any
example provided by the Arduino Software (IDE) or library shows up in this menu item.
All the examples are structured in a tree that allows easy access by topic or library.
• Close Closes the instance of the Arduino Software from which it is clicked.
• Save Saves the sketch with the current name. If the file hasn't been named before, a
name will be provided in a "Save as.." window.
• Save as... Allows to save the current sketch with a different name.
• Page Setup It shows the Page Setup window for printing.
• Print Sends the current sketch to the printer according to the settings defined in Page Setup.
• Preferences Opens the Preferences window where some settings of the IDE may be
customized, as the language of the IDE interface.
• Quit Closes all IDE windows. The same sketches open when Quit was chosen will be
automatically reopened the next time you start the IDE.

Edit
• Undo/Redo Goes back of one or more steps you did while editing; when you go back,
you may go forward with Redo.
• Cut Removes the selected text from the editor and places it into the clipboard.
• Copy Duplicates the selected text in the editor and places it into the clipboard.
• Copy for Forum Copies the code of your sketch to the clipboard in a form suitable for
posting to the forum, complete with syntax coloring.
• Copy as HTML Copies the code of your sketch to the clipboard as HTML, suitable for
embedding in web pages.
• Paste Puts the contents of the clipboard at the cursor position, in the editor.
• Select All Selects and highlights the whole content of the editor.
• Comment/Uncomment Puts or removes the // comment marker at the beginning of
each selected line.
• Increase/Decrease Indent Adds or subtracts a space at the beginning of each selected
line, moving the text one space on the right or eliminating a space at the beginning.

• Find Opens the Find and Replace window where you can specify text to search inside the
current sketch according to several options.
• Find Next Highlights the next occurrence - if any - of the string specified as the
search item in the Find window, relative to the cursor position.
• Find Previous Highlights the previous occurrence - if any - of the string specified as
the search item in the Find window relative to the cursor position.

Sketch
• Verify/Compile Checks your sketch for errors compiling it; it will report memory usage
for code and variables in the console area.
• Upload Compiles and loads the binary file onto the configured board through
the configured Port.
• Upload Using Programmer This will overwrite the bootloader on the board; you will
need to use Tools > Burn Bootloader to restore it and be able to Upload to USB serial
port again. However, it allows you to use the full capacity of the Flash memory for your
sketch. Please note that this command will NOT burn the fuses. To do so Tools -> Burn
Bootloader command must be executed.
• Export Compiled Binary Saves a .hex file that may be kept as archive or sent to the board
using other tools.
Show Sketch Folder Opens the current sketch folder.
• Include Library Adds a library to your sketch by inserting #include statements at the start
of your code. For more details, see libraries below. Additionally, from this menu item you
can access the Library Manager and import new libraries from .zip files.
• Add File Adds a supplemental file to the sketch (it will be copied from its current
location). The file is saved to the data subfolder of the sketch, which is intended for assets
such as documentation. The contents of the data folder are not compiled, so they do not
become part of the sketch program.
Tools
• Auto Format This formats your code nicely: i.e. indents it so that opening and closing
curly braces line up, and that the statements inside curly braces are indented more.
• Archive Sketch Archives a copy of the current sketch in .zip format. The archive is placed
in the same directory as the sketch.
• Fix Encoding & Reload Fixes possible discrepancies between the editor char map
encoding and other operating systems char maps.
• Serial Monitor Opens the serial monitor window and initiates the exchange of data with
any connected board on the currently selected Port. This usually resets the board, if the
board supports Reset over serial port opening.
• Board Select the board that you're using. See below for descriptions of the various boards.
• Port This menu contains all the serial devices (real or virtual) on your machine. It should
automatically refresh every time you open the top-level tools menu.
• Programmer For selecting a hardware programmer when programming a board or chip
and not using the onboard USB-serial connection. Normally you won't need this, but if
you're burning a bootloader to a new microcontroller, you will use this.
• Burn Bootloader The items in this menu allow you to burn a bootloader onto the
microcontroller on an Arduino board. This is not required for normal use of an Arduino
board but is useful if you purchase a new ATmega microcontroller (which normally come
without a bootloader). Ensure that you've selected the correct board from the Boards
menu before burning the bootloader on the target board. This command also set the right
fuses.

Help
Here you find easy access to a number of documents that come with the Arduino Software
(IDE). You have access to Getting Started, Reference, this guide to the IDE and other
documents locally, without an internet connection. The documents are a local copy of the online
ones and may link back to our online website.

Find in Reference This is the only interactive function of the Help menu: it directly selects the
relevant page in the local copy of the Reference for the function or command under the cursor.
Sketchbook
The Arduino Software (IDE) uses the concept of a sketchbook: a standard place to store your
programs (or sketches). The sketches in your sketchbook can be opened from the File >
Sketchbook menu or from the Open button on the toolbar. The first time you run the Arduino
software, it will automatically create a directory for your sketchbook.

You can view or change the location of the sketchbook location from with the Preferences
dialog. Beginning with version 1.0, files are saved with a .ino file extension. Previous versions
use the .pde extension. You may still open .pde named files in version 1.0 and later, the
software will automatically rename the extension to .ino.

Tabs, Multiple Files, and Compilation

Allows you to manage sketches with more than one file (each of which appears in its own tab).
These can be normal Arduino code files (no visible extension), C files (.c extension), C++ files
(.cpp), or header files (.h).
Libraries
Libraries provide extra functionality for use in sketches, e.g. working with hardware or
manipulating data. To use a library in a sketch, select it from the Sketch > Import Library
menu. This will insert one or more #include statements at the top of the sketch and compile
the library with your sketch.

Serial Monitor
This displays serial sent from the Arduino board over USB or serial connector. To send
data to the board, enter text and click on the "send" button or press enter. Choose the baud
rate from the drop-down menu that matches the rate passed to Serial.begin in your sketch.

The types of Operators classified in Arduino are:

1. Arithmetic Operators
2. Compound Operators
3. Boolean Operators
4. Comparison Operators
5. Bitwise Operators

Arithmetic Operators

There are six basic operators responsible for performing mathematical operations in Arduino,
which are listed below:
Assignment Operator ( = ): Used to set variable's value. It is quite different from equal
symbol (=) normally used in mathematics.
Addition ( + ): Used for addition of two numbers. For example, P + Q.
Subtraction ( - ): Used to subtract one value from the another. For example, P - Q.
Multiplication ( * ): Used to multiply two numbers. For example, P * Q.
Division ( / ): Used to determine result of one number divided with another. For
example, P/Q. Modulo ( % ): Used to calculate remainder after division of one number
by another number.
Code 1: Add two numbers and print their result on serial monitor
int b; void setup ( )
{
Serial.begin( 9600 );
}
void loop ( )
{ b = 5 + 2;
Serial.println(b
);
}

Result: 7

Code 2: Run the below code to check the working of


arithmetic operators
int d; void setup ( )
{
Serial.begin( 9600 );
}
void loop ( )
{ d = 5 - 2;
Serial.println(d
); d = d + 3;
Serial.println(d
);
}

Result: 3

If we want decimal values to be printed, we need to use the float instead of int.
Code 3: Use float datatype and divide operator to write
a code.
float b; void setup ( )
{
Serial.begin( 9600 );
}
void loop ( )
{ b = 20.0 / 3; // decimal value is used to force the
compiler to print decimal value.

Serial.println(b);

Code 4: Write a code to verify


BODMAS int c; void setup ( )
{
Serial.begin( 9600 );
}
void loop ( )
{
c = 2 * 3 / (2 + 1) + 4;
Serial.println(c);
}

Output: 6
Compound Operators
Compound operators perform two or more calculations at once. Result of right operand is
assigned to left operand. Same condition will apply to all the compound operators, which are
listed below:

Let's consider a variable b.


• b++
Here, b = b + 1. It is called increment operator.
• b+=

For example, b + = 4. It means, b = b+ 4.


• b--

Here, b = b - 1. It is called as the decrement operator.


• b-=

For example, b - = 3. It means, b = b - 3.


• b*=

For example, b * = 6. It means, b = b * 6.


• b/=

For example, b / = 5. It means, b = b / 5.


•b%=

For example, b % = 2. It means, b = b % 2.

Now, let's use the above operators with two variables, b and c.
o b + = c ( b = b+c)
o b - = c ( b = b - c)
o b * = c ( b = b *c)
o b / = c ( b = b / c)
o b % = c (b=b%c)
Boolean Operators

The Boolean Operators are NOT (!), Logical AND (& &), and Logical OR (| |).

Logical AND (& &): The result of the condition is true if both the operands in the condition are true.
if (a = = b & & b = = c)

Above statement is true if both conditions are true. If any of conditions is false, statement will be false.

Logical OR (| |): Result of condition is true, if either of variables in condition is true.


if (a > 0 | | b > 0)
The above statement is true, if either of above condition (a> 0 or b > 0) is true.

NOT (!): It is used to reverse the logical state of the operand.

For example, a! = 2.

The NOT operator returns value 1 or TRUE when specified operand is FALSE. It also reverses
the value of the specified expression.

Comparison Operators

The comparison operators are used to compare the value of one variable with the other. The
comparison operators are listed below:

• less than ( < ): The less than operator checks that the value of the left operand is less than
the right operand. The statement is true if the condition is satisfied.

Example: Consider the below code.


1. int b;
2. int c ;
3. void setup ( )
4. {
5. Serial.begin( 9600 );
6. }
7. void loop ( )
8. {
9. b = 3;
10. c = 5;
11. if ( b < 4 )
12. Serial.println(b);
13. if ( c < 4)
14. Serial.println( c);
15. }

Output: 3

In above code, if any of two statements is correct, corresponding value of variable will be
printed. Here, only first condition is correct. Hence, value of b will be printed.
• greater than (>): Less than operator checks that value of left side of a statement is greater
than right side. Statement is true if the condition is satisfied. For example, a > b. If a is
greater than b, the condition is true, else false.
• equal to (= =): It checks the value of two operands. If the values are equal, the condition is
satisfied. For example, a = = b. The above statement is used to check if the value of a is equal
to b or not.
• not equal to (! = ): It checks the value of two specified variables. If the values are not equal,
the condition will be correct and satisfied. For example, a! = b.
• less than or equal to (< =): The less or equal than operator checks that the value of left side
of a statement is less or equal to the value on right side. The statement is true if either of the
condition is satisfied. For example, a < = b. It checks the value of a is less or equal than b.
• greater than or equal to (> =): The greater or equal than operator checks that the value of
the left side of a statement is greater or equal to the value on the right side of that statement.
The statement is true if the condition is satisfied. For example, a > = b. It checks the value of
a is greater or equal than b. If either of the conditions satisfies, the statement is true.
Bitwise Operators

The Bitwise operators operate at the binary level. These operators are quite easy to use.
There are various bitwise operators. Some of the popular operators are listed below:
1. bitwise NOT (~): The bitwise NOT operator acts as a complement for reversing the
bits. For example, if b = 1, the NOT operator will make the value of b = 0.
• 0 0 1 1 // Input or operand 1 (decimal value 3)
• 1 1 0 0 // Output (reverses the input bits) decimal value is 12
2. bitwise XOR (^): The output is 0 if both the inputs are same, and it is 1 if the two input
bits are different. For example,
1. 1 0 0 1 // input 1 or operand 1
2. 0 1 0 1 // input 2
3. 1 1 0 0 // Output (resultant - XOR)
3. bitwise OR (|): Output is 0 if both of the inputs in the OR operation are 0. Otherwise,
the output is 1. The two input patterns are of 4 bits. For example,
1. 1 1 0 0 // input 1 or operand 1
2. 0 0 0 1 // input 2
3. 1 1 0 1 // Output ( resultant - OR)
4. bitwise AND (&): Output is 1 if both the inputs in the AND operation are 1.
Otherwise, the output is 0. The two input patterns are of 4 bits. For example,
1. 1 1 0 0 // input 1 or operand 1
2. 0 1 0 1 // input 2
3. 0 1 0 0 // Output ( resultant - AND)
5. bitwise left shift ( < < ): The left operator is shifted by the number of bits defined by
the right operator.
6. bitwise right shift ( > > ): The right operator is shifted by the number of bits defined by
the left operator.
PRACTICAL 2(B): Frequently used functions in Arduino IDE.

Functions allow structuring the programs in segments of code to perform individual tasks. The
typical case for creating a function is when one needs to perform the same action multiple times
in a program.
Standardizing code fragments into functions has several advantages −
• Functions help the programmer stay organized. Often this helps to conceptualize the program.
• Functions codify one action in one place so that the function only has to be thought about
and debugged once.
• This also reduces chances for errors in modification, if the code needs to be changed.
• Functions make the whole sketch smaller and more compact because sections of code are
reused many times.
• They make it easier to reuse code in other programs by making it modular, and using
functions often makes the code more readable.
There are two required functions in an Arduino sketch or a program i.e. setup () and loop().
Other functions must be created outside the brackets of these two functions.
The most common syntax to define a function is −

Function Declaration
A function is declared outside any other functions, above or below the loop function. We
can declare the function in two different ways −
The first way is just writing the part of the function called a function prototype above the loop
function, which consists of –

• Function return type


• Function name
• Function argument type, no need to write the argument
name Function prototype must be followed by a semicolon ( ; ).
The following example shows the demonstration of the function declaration using the first method.
Arduino IDE offers a wide range of functions and libraries to help you program your Arduino
microcontroller effectively. Here are some frequently used functions along with coding examples:

1. pinMode(): Configures a pin as INPUT or OUTPUT.


pinMode(ledPin, OUTPUT);

Example: // LED connected to pin 13


const int ledPin = 13;
void setup() {
pinMode(ledPin,
OUTPUT);
} void loop() { digitalWrite(ledPin,
HIGH); // Turn on the LED
delay(1000); // Wait
for 1 second digitalWrite(ledPin,
LOW); // Turn off the LED
delay(1000); // Wait
for 1 second }

2. digitalWrite(): Writes a HIGH or LOW value to a digital pin. digitalWrite(ledPin, HIGH);

Example: // LED connected to pin 13


const int ledPin = 13;
void setup() {
pinMode(ledPin,
OUTPUT);
} void loop() { digitalWrite(ledPin,
HIGH); // Turn on the LED
delay(1000); // Wait
for 1 second digitalWrite(ledPin,
LOW); // Turn off the LED
delay(1000); // Wait
for 1 second }

3. digitalRead(): Reads the value from a digital pin (HIGH or


LOW). int buttonState = digitalRead(buttonPin);
Example: // Button connected to pin 2
const int buttonPin = 2;
void setup() {
pinMode(buttonPin,
INPUT_PULLUP);
Serial.begin(9600);
} void loop()
{
int buttonState =
digitalRead(buttonPin);
Serial.println(buttonState);
delay(1000);
}

4. analogWrite(): Writes an analog value (PWM) to a pin.


analogWrite(ledPin, brightness);

5. analogRead(): Reads the analog value from an analog pin (0-


1023). int sensorValue = analogRead(A0);

Example: // Analog sensor connected to analog pin 0


const int sensorPin = A0;
void setup() {
Serial.begin(960
0);
} void loop()
{
int sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
delay(1000);
}

6. delay(): Pauses the program for a specified number of milliseconds. delay(1000);


// Pause for 1 second
Example:
void setup() {
pinMode(LED_BUILTIN,
OUTPUT);
} void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1 second
digitalWrite(LED_BUILTIN, LOW); delay(1000);
// Wait for 1 second
}

Serial.begin(): Initializes serial communication.


Serial.begin(9600); // Initialize serial communication at 9600 bps

8. Serial.println(): Prints data to the Serial Monitor.

Serial.println("Hello, Arduino!");
Example:
void setup() {
Serial.begin(960
0);
}
void loop() {
Serial.print("Hello,
World!"); delay(1000);
}

9. if() statement: Conditional execution based on a condition.

if (temperature > 25) { // Code to execute when temperature is above 25°C }


10.for() loop: Repeats a block of code a specified number
of times. for (int i = 0; i < 5; i++) { // Code to
repeat 5 times }
11. while() loop: Repeats a block of code as long as a condition is true.
while (buttonState == HIGH) { // Code to execute while the button is pressed }
12. Functions: Custom functions allow you to organize and reuse code.
void blinkLED(int pin, int duration)
{
digitalWrite(pin,
HIGH);
delay(duration);
digitalWrite(pin,
LOW);
delay(duration);
}
PRACTICAL 3: Study and Install IDE of Arduino.

Study and Install IDE of Arduino.


Arduino is an open-source electronics platform based on easy-to-use hardware and software.
Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter
message
- and turn it into an output - activating a motor, turning on an LED, publishing something online.
You can tell your board what to do by sending a set of instructions to the microcontroller on the
board. To do so you use the Arduino programming language (based on Wiring), and the Arduino
Software (IDE), based on Processing.

We will learn in easy steps, how to set up the Arduino IDE on our computer and prepare the
board to receive the program via USB cable.

Step 1 − First you must have your Arduino board (you can choose your favorite board) and a
USB cable. In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560, or
Diecimila, you will need a standard USB cable (A plug to B plug), the kind you would connect to
a USB printer as shown in the following image.

Step 2 − Download Arduino IDE Software.


You can get different versions of Arduino IDE from the Download page on the Arduino Official
website. You must select your software, which is compatible with your operating system
(Windows, IOS, or Linux). After your file download is complete, unzip the file.
Step 3 − Power up your board.
The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power from either,
the USB connection to the computer or an external power supply. If you are using an Arduino
Diecimila, you have to make sure that the board is configured to draw power from the USB
connection. The power source is selected with a jumper, a small piece of plastic that fits onto two
of the three pins between the USB and power jacks. Check that it is on the two pins closest to the
USB port.Connect the Arduino board to your computer using the USB cable. The green power
LED (labeled PWR) should glow.

Step 4 − Launch Arduino IDE.


After your Arduino IDE software is downloaded, you need to unzip the folder. Inside the folder,
you can find the application icon with an infinity label (application.exe). Double-click the icon to
start the IDE.
PRACTICAL 4: Project details of IOT project

PROJECT TITLE: Ultrasonic Radar System using Arduino


Project Description

The IoT-Based Ultrasonic Radar System is a basic real-time object detection system that simulates
radar functionality using simple electronic components and Arduino programming. The system
detects the presence and distance of nearby objects by rotating an ultrasonic sensor mounted on a
servo motor and scanning the surroundings.

This setup includes an ultrasonic sensor (HC-SR04) to measure distance by emitting and
receiving ultrasonic waves, and a servo motor to rotate the sensor for a 180° sweep. The core of
the system is the Arduino UNO, which processes the sensor data and controls the motor's
movement. When the sensor detects an object within a certain range, the system can display the
distance on a serial monitor or transmit it further through IoT integration.

For enhanced functionality, this setup can be expanded with an ESP8266 Wi-Fi module to send
real-time data to a mobile application or cloud server, making it suitable for remote monitoring and
data visualization in defense, automation, or smart surveillance systems.

Key Features:

 Rotating radar system using ultrasonic sensing and servo control


 Real-time object detection and distance measurement
 Wi-Fi-based IoT connectivity for remote data monitoring
 Simple, low-cost implementation using Arduino UNO

Major Components (as per hardware setup):

 Arduino UNO (Microcontroller)


 Ultrasonic Sensor (HC-SR04) (Distance measurement)
 Servo Motor (Rotating mechanism for scanning area)
 ESP8266 Wi-Fi Module (IoT data transmission to cloud/app)
 Breadboard and jumper wires (Prototyping and connections)
CODE:

#include <Servo.h>
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>

// Wi-Fi & ThingSpeak config


const char* ssid = "yourSSID";
const char* password = "yourPassword";
unsigned long channelID = YOUR_CHANNEL_ID;
const char* writeAPIKey = "YOUR_API_KEY";

WiFiClient client;
Servo radar;
const int trig = 9, echo = 10, servoPin = 11;

void setup() {
pinMode(trig, OUTPUT); pinMode(echo, INPUT);
radar.attach(servoPin);
Serial.begin(9600);

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);

ThingSpeak.begin(client); // Start cloud communication


}

void loop() {
for (int angle = 0; angle <= 180; angle += 10) {
radar.write(angle); delay(200);

digitalWrite(trig, LOW); delayMicroseconds(2);


digitalWrite(trig, HIGH); delayMicroseconds(10);
digitalWrite(trig, LOW);

long dur = pulseIn(echo, HIGH);


float dist = (dur * 0.0343) / 2;

Serial.print("Angle: "); Serial.print(angle);


Serial.print(" | Distance: "); Serial.println(dist);

ThingSpeak.setField(1, angle);
ThingSpeak.setField(2, dist);
ThingSpeak.writeFields(channelID, writeAPIKey);

delay(1500); // Required delay for ThingSpeak


}
}
OUTPUT:

You might also like