Varun Iot Full Practicle[1]
Varun Iot Full Practicle[1]
LUDHIANA
IOT LAB(LPCIT-109)
PRATICAL FILE
Arduino :-
• Arduino is microcontroller based .
• It is open sources electronic prototyping board .
• It is easy to used .
Major components:-
• Usb connector
• Power port
• Microcontroller
• Analog input pins
• Digital pins
• Reset switch
• Crystal oscillator
• USB interface chip
• TX RX LEDS
Diagram:-
1. USB connector :-
• It is a printer USB port .
• it is used to load a program.
• From Arduino IDE onto the Arduino board .
• It is also powered through this port .
2. Power port :-
• It can be powered through ac to dc.
• The power sources can be connected by plugging 2.1 mm center
positive plug .
4. Microcontroller :-
• It is most prominent black rectangular chip with 28 pins.
• It is brain of ardunio .
• It is microcontroller used on the UNO board is Atmega 328P by
Atmel .
Component :-
o Flash memory :-
• 32 KB
• The program loaded from Arduino IDE is stored .
o RAM :-
• 2 KB
• This is a runtime memory .
o CPU :-
• It control everything that goes on within the device.
• It fetch the program instruction from flash memory and run them with
the help of RAM.
o EEPROM :-
• This is a type of non volatile memory .
5. Analog input pins :-
• The Arduino UNO board has 6 analog input pins .
• This pins can read the signal from an analog sensor .
• It is the system understanding .
• It only measure the voltage not current .
• It has very high internal resistance .
6. Digital pins :-
• These pins can be used either input and output pins .
• These pins act as a power supply source.
• Some of digital pins are labelled with tilde (~) symbol.
7. Reset switch :-
• It sends a logical pulse to the reset pin.
• It can be very useful . if your code doesn`t repeat but you want to test
it multiple times .
8. Crystal oscillator :-
• This is a quartz crystal oscillator which tick 16 million time a second
.
• The microcontroller performs one operation for eg : addition
,substraction etc.
Raspberry PI:-
• The Raspberry Pi device looks like a motherboard. It is a cheap.
• Credit-card-sized device that uses a daily keyboard and mouse and joins to
a TV or computer monitor.
• It is a thin weighable computer.
• Its low cost, modularity, and open architecture, it is now commonly used in
many fields, such as for weather forecasting.
Major components :-
• ARM CPU/GPU
• GPIO
• RCA
• Audio out
• LEDs
• USB
• HDMI
• Power
• SD cardslot
• Ethernet
Diagram:-
1. ARM CPU/GPU:-
This is a Broadcom BCM2835 System on a Chip (SoC) that's made up
of an ARM central processing unit (CPU) and a Videocore 4 graphics
processing unit (GPU).CPU handles all the computations that make a
computer work and the GPU handles graphics output.
2. GPIO:-
These are exposed general-purpose input/output connection points that
will allow the real hardware hobbyists the opportunity to tinker.
3. RCA :-
An RCA jack allows connection of analog TVs and other similar
output devices.
4. Audio out :-
This is a standard 3.55-millimeter jack for connection of audio output
devices such as headphones or speakers. There is no audio in.
5. LEDs:-
Light-emitting diodes, for all of your indicator light needs.
6. USB :-
This is a common connection port for peripheral devices of all types
(including your mouse and keyboard).
7. HDMI :-
This connector allows you to hook up a high-definition television or
other compatible device using an HDMI cable.
8. Power :-
This is a 5v Micro USB power connector into which you can plug your
compatible power supply.
9. SD cardslot :-
This is a full-sized SD card slot. An SD card with an operating system
(OS) installed is required for booting the device.
10. Ethernet :-
This connector allows for wired network access and is only available
on the Model B.
Compare of Arduino and Raspberry pi
Arduino Raspberry pi
o The Arduino is defined as a o The Raspberry Pi is defined
simple microcontroller as the mini computer.
motherboard.
Installation of Arduino
Step 1: Visit the Arduino Website’s Downloads page
https://www.arduino.cc/en/software
Step 2: Choose the version suitable for your operating system and click download
Step 3: After Downloading open the installation setup and press install
Step 4: Press Finish and here’s your Arduino ready to launch.
Experiment no :2
To demonstrate the communication modules like BLE, WIFI,
XBEE
BLE:-
5.Configuration and API Modes: XBee modules offer two primary modes
of operation:
•AT Mode (Transparent Mode): In this mode, modules are configured using
AT commands, and they transmit data transparently. It's like a simple serial
cable replacement.
•API Mode (Application Programming Interface Mode): In API mode,
modules allow for more advanced control and data framing, enabling
developers to build custom communication protocols and manage complex
data.
6.Range and Data Rate: The range and data rate of XBee modules vary
depending on the specific model and configuration. Typically, XBee
modules can provide communication ranges from a few hundred feet to
several miles, with data rates ranging from a few kbps to over 1 Mbps.
7.Development Tools: Digi International provides development kits,
software tools, and libraries to facilitate the integration of XBee modules
into various projects. These tools make it easier for developers to configure
and manage XBee modules.
8.IoT and Industrial Applications: XBee modules are commonly used in IoT
(Internet of Things) applications, industrial automation, remote monitoring,
sensor networks, and robotics, among others.
9.Integration with Microcontrollers: XBee modules can be interfaced with
microcontrollers such as Arduino, Raspberry Pi, and others. This allows
developers to create wireless-enabled projects with ease.
10.Security Features: XBee modules offer security features such as
encryption and authentication to ensure the confidentiality and integrity of
data transmitted over the wireless network.
Experiment no :3
Experiment no :4
To interface LED/ Buzzer with Arduino/ Raspberry Pi and
write a program to turn ON/OFF LED for specific duration.
To perform this practical, we need these components –
• Arduino board Uno (preferably) but if you don’t have the Uno board,
you can easily adapt by finding the corresponding pins.
• Breadboard
• Push Button
• LED color – any
• 220 Ohm resistor for the LED. If you don't have this specific value, any
resistorfrom 330 to 1k Ohm will do.
• 10k Ohm resistor for the push button. If you don't have, you can go
until 20k-50k Ohm.
• A bunch of male to male wires (including if possible black, red, and
other colors).
Experiment no :5
To interface DHT11/ DHT22 sensor with Arduino/ Raspberry
Pi and write a program to print temperature and humidity
readings.
The DHT11 measures relative humidity. Relative humidity is the amount of water
vapor in air vs. the saturation point of water vapor in air. At the saturation point,
water vapor starts to condense and accumulate on surfaces forming dew.The
saturation point changes with air temperature. Cold air can hold less water vapor
before it becomes saturated, and hot air can hold more water vapor before it
becomes saturated. The formula to calculate relative humidity is:
But before all of this, you’ll need to install the DHTLib library. It’s easy to install,
just download DHTLib.zip file below and open up Arduino IDE. After this
installation, upload this example program to the Arduino and open the serial
monitor.
CODE:
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to //
Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE); void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds! // Sensor
readings may also be up to 2 seconds 'old' (its a very slow sensor) float h =
dht.readHumidity(); // Read temperature as Celsius float t =
dht.readTemperature(); // Read temperature as Fahrenheit float f =
dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!"); return;
}
// Compute heat index
// Must send in temp in Fahrenheit! float
hi = dht.computeHeatIndex(f, h);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
}
Output :
Experiment no :6
To interface PIR Sensor with Arduino/ Raspberry Pi and write
a program to check the motion of PIR sensor.
The PIR motion sensor is ideal to detect movement. PIR stand for “Passive
Infrared”. Basically, the PIR motion sensor measures infrared light from objects
in its field of view. So, it can detect motion based on changes in infrared light in
the environment. It is ideal to detect if a human has moved in or out of the sensor
range.
Wiring the PIR motion sensor to an Arduino is pretty straightforward – the sensor
has only 3 pins.
• GND – connect to ground
• OUT – connect to an Arduino digital pin
• 5V – connect to 5V
How does a PIR sensor work?
Every object with a temperature above absolute zero emits IR radiation,
which is invisible to the human eye but carries information about an object's
temperature and movement. The topmost part of the PIR sensor consists of
a lens with concentric grooves carved into the plastic. These are called
Fresnel lens.
The contours on this plastic helps in gathering parallel light rays at a focal
point, each one of them acting as individual refracting surfaces. These
surfaces increase the range and field of view of PIR sensor, the lens is
divided into several sections, each of them being a separate Fresnel lens.
The operation of the PIR Sensor unfolds in several stages. Upon powering
up, the sensor initiates an initialization phase during which it calibrates
itself to the ambient IR radiation conditions. This calibration helps the
sensor adapt to the background temperature and minimize false triggers.
Subsequently, the sensor continuously monitors its surroundings,
comparing the detected IR radiation pattern with the previously calibrated
background. When a warm object, such as a human or a pet, moves within
the sensor's field of view, it causes a dynamic alteration in the IR radiation
pattern received by the pyroelectric sensor. This change is promptly
detected by the sensor. The sensor's internal circuitry processes the signal
output from the pyroelectric sensor. It includes signal amplification and
filtering mechanisms to ensure accurate and reliable motion detection. The
final output from the HC-SR501 PIR Sensor is typically a digital signal.
This signal remains in a low state when no motion is detected. However,
when motion occurs within the sensor's sensing range, the signal transitions
to a high state. The duration for which the signal stays high is determined
by the time-delay adjustment potentiometer on the sensor.
After this preset time, the signal returns to its low state, indicating the
absence of motion.
Connect the PIR sensor's VCC (or +) pin to the Arduino's 5V output.
Connect the GND (-) pin of the PIR sensor to any GND pin on the
Arduino.Attach the OUT (or signal) pin of the PIR sensor module to a
digital input pin on the Arduino (e.g., pin 5).
The following code gives the representation of how PIR sensor will work
with Arduino Board.
CODE:
int led = 13; // the pin that the LED is atteched to int
sensor = 2; // the pin that the sensor is atteched to int
state = LOW; // by default, no motion detected int val =
0; // variable to store the sensor status (value) void
setup() {
pinMode(led, OUTPUT); // initalize LED as an output pinMode(sensor,
INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is
HIGH digitalWrite(led, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds
if (state == LOW) {
Serial.println("Motion detected!"); state =
HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
if (state == HIGH){
Serial.println("Motion stopped!"); state =
LOW; // update variable state to LOW
}}}
Output :
Experiment no :7
To interface PI Camera with Arduino/ Raspberry Pi and
write a program to start the camera and to place the
clicked pictures on the desktop
Interfacing a Pi Camera with an Arduino board is not a direct process since the Pi
Camera uses the Raspberry Pi's Camera Module and communicates through the
Raspberry Pi's GPIO pins. If you want to capture images using the Pi Camera and
transfer them to your computer, you'll need to use a Raspberry Pi board.
Here's how you can achieve this using a Raspberry Pi and Python programming
language:
Hardware Requirements:
• Raspberry Pi Board (e.g., Raspberry Pi 3/4)
• Pi Camera Module
• Arduino Board (for other purposes, if needed)
• Internet connection for Raspberry Pi
Software Requirements:
• Raspbian OS installed on Raspberry Pi
• Python 3 installed on Raspberry Pi
Setup and enable the Pi camera
First, make sure to shutdown and power off your Raspberry Pi. Localize the
camera port (don’t confuse it with the display port which has a similar connector).
The camera port is between the HDMIs ports and the jack port. You can see
“CAMERA” written next to it.
Once you’ve located the camera port, now make sure to plug the connector in the
right way. The blue part should face the jack and USB ports.
Now, power on your Raspberry Pi. To open the settings for the Pi camera, click on
the Raspberry Pi icon > “Preferences” > “Raspberry Pi Configuration”.
Then, click on OK and reboot your Pi so the change will be effective. Take a picture
with the Raspberry Pi cameraNow that the camera is plugged and enabled, you
can start to take pictures. Here we’ll use the raspistill command in the terminal –
already installed on the Raspberry Pi OS.
First, open a terminal. If you don’t have the terminal icon on the top bar, click on
the Raspberry
Pi icon > “Accessories” > “Terminal”.
First picture with Raspberry Pi and raspistill To take a picture, you’ll need to use
the raspistill command and also provide one argument: the name of the file for the
output, so raspistill can save the photo into that file.
1. Connect the Pi Camera:
• Make sure your Raspberry Pi is turned off.
• Connect the Pi Camera module to the Camera CSI port on the Raspberry Pi
board.
2. Enable the Camera Interface:
• Boot up your Raspberry Pi and open the terminal.
• Run sudo raspi-config command.
• Navigate to "Interfacing Options" and enable the Camera interface.
• Reboot the Raspberry Pi.
3. Write Python Code to Capture and Transfer Images:
• Write a Python script to capture images using the Pi Camera and transfer
them to your desktop computer.
• Here's an example Python code for capturing images and saving them on
the Pi: import os import time
from picamera import PiCamera
# Initialize the PiCamera
camera = PiCamera()
# Set the resolution of the camera (optional)
camera.resolution = (640, 480) # Path to
save captured images image_path =
"/home/pi/Desktop/" try:
# Capture an image
28
timestamp = time.strftime("%Y%m%d_%H%M%S")
image_filename = f"image_{timestamp}.jpg"
image_fullpath = os.path.join(image_path,
image_filename)
# Capture the image
camera.capture(image_fullpath)
print(f"Image captured: {image_filename}")
except Exception as e: print(f"Error:
{str(e)}") finally:
# Release the camera resources camera.close()
Experiment no :8
To transmit and access the sensed data to any cloud
Platform
One of the simplest , rather evolved in the 1970s and 1980s, before the
development of all the radio links. The Sensor includes a processor which
is tough enough to configure the data uploading to cloud. The Ethernet
connection would connect to wired Internet service. The problem: Some
places don’t have wired Internet. The processor could also have the ability
to update or modify the functions of the sensor. There is no involvement of
radio link.
Sensor To Mobile-Phone Network To Cloud
The mobile phone network began to develop in the early 1980s. These early
cellular networks were the first widely available radio link for connecting sensors
to the cloud. The disadvantages are that
• The sensor still needs a wired connection to a mobile phone or needs an
expensive custom radio in the mobile-phone band to connect to the phone
tower.
• The uplink (sensor to the phone tower) radio transmitter needs a fair amount
of power to reach the tower
• The user needs to pay the mobile network provider for usage.
Sensor To Long-Range Radio To The Cloud
Regulators established several license free radio bands as early as 1947. But
these did not attract much interest until mobile phones really caught on in
the late 1990s. IEE 802.15.4 standard has frequencies of two bands at 902-
928 MHz and 2400-2483 MHz.(There are other standards, such as Zigbee,
in one or both of these bands.)
One configuration that uses these bands is a mesh network. It consists of
many small, low-power radios connected to each other to relay data from
remote sensors at the outer edges of an area to radios at a collection point.
Each collection point has access to the cloud. This allows for wide-area
usage by deploying sensors connected to very lowpower radios.
The 2400-2483 MHz band and another license-free band at 5130-5835 MHz
were the original frequency bands of the 802.11 Wi-Fi Standard (created in
1997). They are used primarily for Wi Fi access points, which is widely
available in cities these days. The largest number of these routers are in
homes, businesses, and public gathering places (coffee shops, malls, and
airports).
Industry and infrastructure used a small number of more specialized
routers. This is the most widely-used way today to connect mobile devices
(laptops, tablets, smart phones) to the cloud. In fact, most applications in
smartphones connect to the cloud primarily through a Wi-Fi router.
Shortly after Wi-Fi-capable smartphones became available, remote sensors
that could connect directly to a Wi-Fi router also began to appear. Small
sensors with low power Wi-Fi radio are placed within the range of wifi
routor. Internet connection is provided later.