IoT LAB Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

SCHOOL OF ENGINEERING

IoT LAB

A.Hardware and Software for IoT


1) Concept of IoT and Arduino:-
Concept of IoT
The Internet of Things (IoT) is a network of physical devices, vehicles, home appliances,
and other items embedded with electronics, software, sensors, actuators, and
connectivity which enable these objects to connect and exchange data. Each thing is
uniquely identifiable through its embedded computing system but can inter-operate
within the existing Internet infrastructure. Simply, we can say that “IoT is essentially a
platform where embedded devices are connected to the internet, so they can collect and
exchange data with each other. It enables devices to interact, collaborate and, learn from
each other’s experiences just like humans do.”
Examples of IoT applications include smart homes or buildings that use sensors to monitor
energy consumption; connected cars that can be remotely monitored for diagnostics
purposes; wearable health monitors that track fitness levels; intelligent agriculture
systems that measure crop conditions; industrial automation systems used in factories or
warehouses to monitor equipment performance.

Concept of Arduino
Arduino is a project, open-source hardware, and software platform used to design and
build electronic devices. It designs and manufactures microcontroller kits and single-board
interfaces for building electronics projects. It is an open-source platform and has a variety
of controllers and microprocessors. There are various types of Arduino boards used for
various purposes.
Arduino is an open-source electronics platform based on simple microcontroller boards
and a development environment for writing software for the boards. The boards are
equipped with sets of digital and analog input/output (I/O) pins that may be interfaced
with various expansion boards or other circuits. The boards feature an Atmel AVR
microcontroller and are pre-programmed with a boot loader that simplifies the uploading
of programs to the on-chip flash memory.
The Arduino development environment (IDE) is a cross-platform application written in
Java. It is designed to introduce programming to artists and other newcomers unfamiliar
with software development. It includes a code editor with features such as syntax
highlighting, brace matching, automatic indentation, and a program verifier that checks
the code for some common errors.
Arduino boards are widely used for DIY projects, and in many cases, the projects are
designed to interact with the physical world via sensors and actuators. Some common
examples of projects include:
• Controlling lights and motors
• Reading sensor data (e.g., temperature, humidity, light level)
• Communicating with other devices (e.g., via Bluetooth or Wi-Fi)
• Creating interactive art installations
Overall, Arduino is a simple, versatile, and affordable tool for creating electronic projects
and interacting with the physical world.

Page | 1
SCHOOL OF ENGINEERING
IoT LAB

Microcontroller ATmega328
Operating Voltage 5V
Input 7-12V
Voltage(recommended)
Input Voltage(limits) 6-20V
Digital I/O pins 14(of which 6 provide PWM
output)
Analog input pins 6
DC current per I/O pin 40Ma
DC current for 3.3V pin 50Ma
Flash Memory 32 KB(ATmega328) of which
0.5 KB
used by bootloader
SRAM 2 KB(ATmega328)
EEPROM 1 KB(ATmega328)
Clock Speed 16 MHz

Page | 2
SCHOOL OF ENGINEERING
IoT LAB

2) Different Operating Systems for Arduino:-


Arduino boards are typically programmed using the Arduino Software (IDE), which runs on
a variety of operating systems including Windows, macOS, and Linux. Here are some
popular operating systems that can be used to set up an Arduino board:
➢ Windows
➢ macOS
➢ Linux
➢ Chrome OS
➢ Mobile OS
➢ Coop Threads
➢ FreeRTOS
➢ Helios
➢ Simba
➢ TaskManagerIO
In addition to the Arduino Software (IDE), other programming environments such as the
Arduino Web Editor, the Arduino command-line interface, and third-party integrated
development environments (IDEs) can also be used to program Arduino boards.

3) Operating System Installation on Arduino:-


Unlike typical real-time operating systems, FreeRTOS is specially designed for
microcontrollers. Because Microcontrollers come with limited resources, therefore, we
need an operating system as per the available resources of microcontrollers. It is an open-
source Kernel that means it can download free of cost and be used in RTOS-based
applications. By using FreeRTOS, we can make sure that each task of Arduino will have a
deterministic execution pattern and every task will meet its execution deadline. In other
words, it is a scheduler that assigns Arduino CPU resources to every task according to a
scheduling algorithm.

How to use FreeRTOS with Arduino?


The RTOS used in this project is FreeRTOS. FreeRTOS is developed by Real Time Engineers
Ltd. It is an open-source popular Real-Time Operating System kernel. Furthermore, it is
used for embedded devices which as microcontrollers, Arduino. It is mostly written in C
but some functions are written in assembly. There are also SafeRTOS and OpenRTOS
available online which are similar to FreeRTOS.
Download and Install FreeRTOS in Arduino IE
➢ First, we need to download and install FreeRTOS in Arduino IDE.
➢ After that go to this GitHub link and download the FreeRTOS library:
https://github.com/ExploreEmbedded/Arduino_FreeRTOS/archive/master.zip
➢ After downloading the FreeRTOS library, extract the folder and paste this extracted
folder in the Arduino IDE libraries folder as shown below.

Page | 3
SCHOOL OF ENGINEERING
IoT LAB

➢ FreeRTOS library can also be installed directly through the Arduino Library
Manager. For this, open Arduino IDE and go to Sketch>>”Include Library” and click
on Manage libraries.

➢ After that, type “FreeRTOS in the search window, this library will appear. After that
click on the install button.

Page | 4
SCHOOL OF ENGINEERING
IoT LAB

B. Hardware and Software for IoT


1) Interface LED with Arduino UNO:-
LED
A light-emitting diode (LED) is a
semiconductor device that emits
light when an electric current
flows through it. When current
passes through an LED, the
electrons recombine with holes
emitting light in the process. LEDs
allow the current to flow in the
forward direction and blocks the
current in the reverse direction. Light-emitting diodes are heavily doped p-n junctions.
Based on the semiconductor material used and the amount of doping, an LED will emit
coloured light at a particular spectral wavelength when forward biased.
Binary Counter
A counter that pursues the binary number sequence is known as a binary counter. An n-
bit binary counter is a register of n flip-flops and related gates that follows a sequence of
states as per the binary count of n bits, from 0 to 2" – 1. Normally binary counters are used
for counting the number of pulses coming at the input line in a specified time period. The
binary counters must possess memory since it must remember its past states. As the name
suggests, it is a circuit which counts. The main purpose of the counter is to record the
number of occurrences of some input. Depending on the way in which the counting
progresses, the synchronous or asynchronous counters are classified as follows.
• Up counters
• Down counters
• Up/Down counters
Code:
const int LED=12;
void setup()
{
pinMode(LED, OUTPUT);
}

void loop()
{
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);
}

Page | 5
SCHOOL OF ENGINEERING
IoT LAB

2) Implement two-bit binary counter UP and DOWN:-


Code:
const int LED1=12;
const int LED2=10;
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop()
{
upcounter();
downcounter();
}
void upcounter()
{

digitalWrite(LED1,LOW); digitalWrite(LED2,LOW);
delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH);
delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW);
delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH);
delay(1000);
}
void downcounter()
{
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH);
delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW);
delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH);
delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW);
delay(1000);
}

Page | 6
SCHOOL OF ENGINEERING
IoT LAB

3) Implement four-bit binary counter UP and DOWN:-


Code:
const int LED1=12;
const int LED2=10;
const int LED3=8;
const int LED4=6;
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
}
void loop()
{
upcounter();
downcounter();
}
void upcounter()
{
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);

Page | 7
SCHOOL OF ENGINEERING
IoT LAB

digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
}
void downcounter()
{
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,HIGH); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,HIGH); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,HIGH);

Page | 8
SCHOOL OF ENGINEERING
IoT LAB

digitalWrite(LED4,LOW); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); delay(1000);
digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW); delay(1000);
}

4) Control Single LED using Push Button with Arduino UNO:-


A push button switch is a simple mechanism that initiates power to a machine, device, or
appliance. The body is typically metal or plastic, featuring a durable and ergonomic design.
With switches available that provide latching or momentary action, there are push-button
switches for virtually any relevant application. The initial state of the push button circuit
can be open or closed, depending on the application. The type of switch will also depend
on the application. push button with Arduino helps you to learn to control the project with
one push-button or switch and it will also help you to learn the Coding part.
In Arduino, The Push-button has to be connected to the input pins so It can read the push
button. When you press the push button then the edge of the attitude will change. For
example, the voltage change from 5v to 0 in binary 1 to 0, in assembly HIGH to LOW you
can use the last two in the Arduino language.

Code:
const int LED = 12;
const int button = 2;
int buttonstate=0;
void setup()
{
pinMode(LED,OUTPUT);
pinMode(button,INPUT);
Serial.begin(9600);
}

Page | 9
SCHOOL OF ENGINEERING
IoT LAB

void loop()
{
digitalWrite(LED,LOW);
buttonstate=digitalRead(button);
if(buttonstate==LOW)
{
digitalWrite(LED,HIGH);
Serial.println(buttonstate);
}
else
{
Serial.println(buttonstate);
}
}

5) Interface an SSD with Arduino UNO:-


A 7-segment display is commonly used in electronic display devices for decimal numbers
from 0 to 9 and in some cases, basic characters. The use of light-emitting diodes (LEDs) in
seven-segment displays made it more popular, whereas of late liquid crystal displays (LCD)
have also come into use. Electronic devices like microwave ovens, calculators, washing
machines, radios, digital clocks, etc. to display numeric information are the most common
applications. A seven-segment display is made of seven different illuminating segments.
These are arranged in a way to form numbers and characters by displaying different
combinations of segments. The binary information is displayed using these seven
segments. LED is a P-N junction diode that emits energy in the form of light, different from
a standard P-N junction diode which emits in the form of heat. Whereas LCD uses liquid
crystal properties for displaying and does not emit light directly. These LEDs or LCDs are
used to display the required numeral or alphabet.
Display Types:

Page | 10
SCHOOL OF ENGINEERING
IoT LAB

6) Implement a single digit decimal UP counter:-


Code:
void setup()
{
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
void loop()
{
unsigned char SSDCode []={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF};
int k;
while(1)
{
for(k=0;k<=9;k++)
{
PORTD=SSDCode[k];
delay(1000);
}
}
}

Page | 11
SCHOOL OF ENGINEERING
IoT LAB

7) Implement a single digit decimal DOWN counter:-


Code:
void setup()
{
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
void loop()
{
unsigned char SSDCode []={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF};
int k;
while(1)
{
for(k=9;k>=0;k--)
{
PORTD=SSDCode[k];
delay(1000);
}
}
}

Page | 12
SCHOOL OF ENGINEERING
IoT LAB

8) Interface an LCD with Arduino UNO:-


The Liquid Crystal library allows you to control LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you can usually tell them
by the 16-pin interface. The LCDs have a parallel interface, meaning that the
microcontroller has to manipulate several interface pins at once to control the display. The
interface consists of the following pins:
• A register select (RS) pin that controls where in the LCD's memory you're writing
data to. You can select either the data register, which holds what goes on the
screen, or an instruction register, which is where the LCD's controller looks for
instructions on what to do next.
• A Read/Write (R/W) pin that selects reading mode or writing mode
• An Enable pin that enables writing to the registers
• 8 data pins (D0 -D7).
The states of these pins (high or low) are the bits that you're writing to a register when
you write, or the values you're reading when you read. There's also a display contrast pin
(Vo), power supply pins (+5V and GND) and LED Backlight (Bklt+ and Bklt-) pins that you can
use to power the LCD, control the display contrast, and turn on and off the LED backlight,
respectively.
The process of controlling the display involves putting the data that form the image of
what you want to display into the data registers, then putting instructions in the
instruction register. The Liquid Crystal Library simplifies this for you so you don't need to
know the low-level instructions.
The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit. The 4-bit
mode requires seven I/O pins from the Arduino, while the 8-bit mode requires 11 pins. For
displaying text on the screen, you can do most everything in 4-bit mode, so example shows
how to control a 16x2 LCD in 4-bit mode.

Page | 13
SCHOOL OF ENGINEERING
IoT LAB

Code:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
lcd.begin(16, 2);
lcd.print("IOT-LAB RECORD!");
}
void loop()
{
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}

9) Interfacing IR Sensor with Arduino UNO:-


An IR sensor is a device that measures the Infrared radiation in its surroundings and gives
an electric signal as an output. An IR sensor can
measure the heat of an object as well as can
detect the motion of the object. IR technology
is used in our day-to-day life and also in
industries for different purposes. For example,
TVs use an IR sensor to understand the signals
that are transmitted from a remote control.
The main benefits of IR sensors are low power
usage, their simple design & their convenient
features. IR signals are not noticeable to the
human eye. As Infrared Radiation is invisible to
our eyes, it can be detected by the Infrared

Page | 14
SCHOOL OF ENGINEERING
IoT LAB

Sensor. An IR sensor is a photodiode that is sensitive to IR light. When IR light falls on the
photodiode, the resistances and the output voltages will change in proportion to the
magnitude of the IR light received.
As we know till now active IR Sensors emit Infrared waves and as well as detect Infrared
ways. The IR sensor module exactly works on the same phenomenon. The IR Sensor
module contains an Infrared LED and an infrared photodiode.
• Infrared LED: The Infrared LED looks the same as a normal LED. But the Infrared
LED emits light that is invisible to the naked eyes. Whenever the electricity is given
to the Infrared LED. it emits infrared light.
• Infrared Photodiode: The IR photodiode will be black in color as shown in the
picture above. Whenever Infrared waves are applied to the Infrared photodiode, in
result the Infrared photodiode changes its resistance, which causes a change in the
output voltages.
Code:
const int IR_sensor=7;
const int buzzer=8;
void setup()
{
pinMode(IR_sensor, INPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int sensorValue=digitalRead(IR_sensor);
if(sensorValue==LOW)
{
Serial.println(sensorValue);
digitalWrite(buzzer,HIGH);
delay(50);
digitalWrite(buzzer,LOW);
delay(100);
}
else
{
digitalWrite(buzzer,LOW);
}
delay(200);
}

Page | 15

You might also like