0% found this document useful (0 votes)
55 views62 pages

IoT Lab Manual

The document is a lab manual for the Internet of Things Lab at Gokaraju Lailavathi Engineering College for the academic year 2024-2025. It includes a list of experiments focused on Arduino and Raspberry Pi platforms, covering topics such as interfacing with Zigbee and GSM modules, and cloud data logging. The manual provides detailed instructions on programming and setting up various components, along with example codes for practical applications.

Uploaded by

anisha01531
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views62 pages

IoT Lab Manual

The document is a lab manual for the Internet of Things Lab at Gokaraju Lailavathi Engineering College for the academic year 2024-2025. It includes a list of experiments focused on Arduino and Raspberry Pi platforms, covering topics such as interfacing with Zigbee and GSM modules, and cloud data logging. The manual provides detailed instructions on programming and setting up various components, along with example codes for practical applications.

Uploaded by

anisha01531
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

GOKARAJU LAILAVATHI ENGINEERING COLLEGE,

BACHUPALLY ROAD, HYDERABAD

LAB MANUAL

Academic Year : 2024-2025

Semester : VII

Name of the Program: B.E (IT) Year: IV

Course/Subject: Internet of Things Lab

Course Code: PC751IT

Name of the Faculty: Dr. Ravi Kumar Poluru

Designation: Asst. Professor


LIST OF EXPERIMENTS

1. Introduction to Arduino platform and programming.


2. Interfacing Arduino to Zigbee module.
3. Interfacing Arduino to GSM module.
4. Interfacing Arduino to Bluetooth Module.
5. Introduction to Raspberry PI platform and Python programming.
6. Interfacing sensors to Raspberry PI.
7. Communicate between Arduino and Raspberry PI using any wireless
medium.
8. Setup a cloud platform to log the data.
9. Log Data using Raspberry PI and upload to the cloud platform.
10. Design an IOT based system.
EXPERIMENT 1

AIM: INTRODUCTION TO ARDUINO PLATFORM AND PROGRAMMING.

Introduction: Arduino is an open-source electronics platform based on easy-to-use hardware


and software. It is designed to make the process of using electronics in multidisciplinary
projects more accessible. Arduino boards can read inputs – light on a sensor, a finger on a
button, or a Twitter message – and turn them 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.

The Arduino Uno is an open-source microcontroller board based on the Microchip


ATmega328P microcontroller and developed by Arduino.cc. The board is equipped with sets
of digital and analog input/output (I/O) pins that may be interfaced to various expansion boards
(shields) and other circuits. The board has 14 digital I/O pins (six capable of PWM output), 6
analog I/O pins, and is programmable with the Arduino IDE (Integrated Development
Environment), via a type B USB cable. It can be powered by the USB cable or by an external
9-volt battery, though it accepts voltages between 7 and 20 volts. The word "uno" means "one"
in Italian and was chosen to mark the initial release of Arduino Software.

Features of the Arduino

1. Arduino boards are able to read analog or digital input signals from different sensors
and turn it into an output such as activating a motor, turning LED on/off, connect to the
cloud and many other actions.
2. The board functions can be controlled by sending a set of instructions to the
microcontroller on the board via Arduino IDE.
3. Arduino IDE uses a simplified version of C++, making it easier to learn to program.
4. Arduino provides a standard form factor that breaks the functions of the micro-
controller into a more accessible package.

Arduino IDE (Integrated Development Environment): The Arduino Software (IDE) is


easy-to-use and is based on the Processing programming environment. The Arduino Integrated
Development Environment (IDE) is a cross-platform application (for Windows, macOS,
Linux) that is written in functions from C and C++. The open-source Arduino Software (IDE)
makes it easy to write code and upload it to the board. This software can be used with any
Arduino board.

The Arduino Software (IDE) – contains:

• A text editor for writing code

• A message area

• A text consoles

• A toolbar with buttons for common functions and a series of menus. It connects to the Arduino
hardware to upload programs and communicate with them.

Components of the Arduino Platform:

1. Arduino Board: The hardware includes an Atmel microcontroller, digital and analog
input/output pins, and communication interfaces.

2. Arduino IDE (Integrated Development Environment): The software environment


where you write code (sketches) and upload it to the board.

3. Power Supply: The Arduino board can be powered through USB or an external power
source.

4. Pinout: Arduino boards have multiple digital and analog pins for interfacing with
peripherals like LEDs, sensors, and motors.
Installation of Arduino Software (IDE)

Step1: Downloading

➢ To install the Arduino software, download this page: http://arduino.cc/en/Main/Software


and proceed with the installation by allowing the driver installation process.

Step 2: Directory Installation

➢ Choose the installation directory

Step 3: Extraction of Files

➢ The process will extract and install all the required files to execute properly the Arduino
Software (IDE)
Step 4: Connecting the board

➢ The USB connection with the PC is necessary to program the board and not just to power it
up. The Uno and Mega automatically draw power from either the USB or an external power
supply. Connect the board to the computer using the USB cable. The green power LED
(labelled PWR) should go on.

Step 5: Working on the new project

➢ Open the Arduino IDE software on your computer. Coding in the Arduino language will
control your circuit.

➢ Open a new sketch File by clicking on New.

Step 6: Working on an existing project

➢ To open an existing project example, select File → Example → Basics → Blink.


Step 7: Select your Arduino board.

➢ To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer.

➢ Go to Tools → Board and select your board.

Step 8: Select your serial port

➢ Select the serial device of the Arduino board.


➢ Go to Tools → Serial Port menu. This is likely to be COM3 or higher (COM1 and COM2
are usually reserved for hardware serial ports).

➢ To find out, you can disconnect your Arduino board and re-open the menu, the entry that
disappears should be of the Arduino board. Reconnect the board and select that serial port.

Step 9: Upload the program to your board.

➢ Click the "Upload" button in the environment.

➢ Wait a few seconds; you will see the RX and TX LEDs on the board, flashing.

➢ If the upload is successful, the message "Done uploading" will appear in the status bar.

A Verify

B Upload

C New

D Open

E Save

F Serial
Motor
Programming Arduino:

Arduino programs, also known as sketches, are written in the Arduino programming language,
which is based on C/C++.

• Basic Structure of an Arduino Sketch:

o setup() function: Runs once when the board is powered on or reset. It's used to
initialize variables, pin modes, and libraries.

o loop() function: Runs continuously after the setup. It contains the code that
performs the primary tasks of the project.

Example Code:

// Turn on an LED connected to pin 13

void setup() {

pinMode(13, OUTPUT); // Set pin 13 as an output pin

void loop() {

digitalWrite(13, HIGH); // Turn on the LED

delay(1000); // Wait for 1 second

digitalWrite(13, LOW); // Turn off the LED

delay(1000); // Wait for 1 second

}
EXPERIMENT 2

AIM: INTERFACING ARDUINO TO ZIGBEE MODULE.

To establish serial communication between two XBee modules connected to two separate
Arduino boards using UART (Serial) communication, we can use the following example code
for both the transmitter and receiver. In this example, we’ll assume that one Arduino is the
transmitter, and the other is the receiver.

Connection Diagram:

Steps of Working:

1. Connect your Zigbee module to the computer’s serial port using a serial adapter.

2. Download a virtual terminal program like PuTTY for Windows.

3. Configure your computer’s serial port settings to a baud rate of 9,600, 8 data bits, no
parity, and 1 stop bit.

4. Enable the “Local Echo” option.

5. Click “OK” to save the session settings.

6. Click the “Connect” button in the virtual terminal program.

7. Once connected to the Zigbee module, give your session a name.

8. Utilize AT commands to configure your module as needed.

After that, type +++ on the virtual terminal. After a few seconds, it will respond with “OK”.
Then, type these commands:

• ATMY1234
• ATDL5678

• ATDH0

• ATID0

• ANSWER

Your Zigbee module is ready to use.

Code: Xbee Arduino Transmitter Code

void setup() {

Serial.begin(9600); // Set the baud rate to match your XBee configuration

void loop() {

String message = "Hello, XBee!"; // Message to send

Serial.println(message); // Send the message over serial

delay(1000); // Wait for a moment before sending the next message

Xbee Arduino Receiver Code

void setup() {

Serial.begin(9600); // Set the baud rate to match your XBee configuration

void loop() {

if (Serial.available() > 0) {

String receivedMessage = Serial.readStringUntil('\n'); // Read the incoming message

Serial.print("Received: ");

Serial.println(receivedMessage); // Print the received message

}
EXPERIMENT 3
AIM: INTERFACING ARDUINO TO GSM MODULE.

The Global System for Mobile Communication, or GSM Modules for short, provides us with
cellular capabilities. GSM modules play a crucial role in enabling communication and
connectivity in various devices and systems, making them an essential component in modern-
day IoT devices where Wi-Fi and Ethernet are not available.

SIM900A GSM Module

SIM900A is an ultra-compact and reliable wireless module. It provides a complete Dual-band


GSM/GPRS solution in a Surface Mount Technology (SMT) module, which can be easily
integrated into customer applications. This module offers an industry-standard interface and
delivers excellent performance for voice, SMS, Data, and Fax over GSM/GPRS 900/1800 MHz
frequencies.

SIM900A Module Status Indicators

This GSM module has 2 LEDs to indicate its status, these are mentioned below

Status
Function of LED
LED

D5 This LED remains on, but whenever a call arrives, it starts flashing.

This LED indicates the connection status of the GSM module. In case the GSM
is not connected to any cellular network; this LED blinks every second. Once the
D6
GSM module connects to the cellular network, this LED starts blinking every 3
seconds, indicating a successful connection.

Table 1: Status Indicator LEDs of SIM900A GSM Module


SIM900A Important AT Commands

Here are some important AT commands for the SIM900A GSM module:

AT Command Description

AT Checks if the module is responding.

AT+CPIN? Checks the status of the SIM card (PIN ready or not).

AT+CSQ Checks the signal quality (measured in dBm).

AT+CREG? Checks the registration status with the network.

AT+CGATT? Checks if the device is attached to GPRS service.

AT+CIPSTATUS Gets the connection status with the server.

AT+CIPSTART Starts a TCP/UDP connection with the server.

AT+CIPSEND Sends data to the server in TCP/UDP connection.

AT+CIPCLOSE Closes the TCP/UDP connection with the server.

Sets SMS text mode, allowing sending/receiving SMS in text


AT+CMGF=1
format.

AT+CMGS=”number” Initiates sending an SMS to the specified “number”.

Reads an SMS from the SMS memory with the specified


AT+CMGR=index
“index”.

Hardware Components:

Here we have listed the hardware components we will be using in this tutorial:

• Arduino UNO board


• SIM900A GSM Module

• Jumper Wires

• Cellular Network Card or SIM card

How to Test SIM900A GSM Module with SIM

1. Insert the SIM card into the GSM module and lock it.

2. Connect the adapter to the GSM module and turn it ON!

3. Now wait for some time (say 1 minute) and see the blinking rate of the status
LED’ or ‘network LED’ (the GSM module will take some time to establish a
connection with the mobile network).

4. Once the connection is established successfully, the status/network LED will blink
continuously every 3 seconds. You may try making a call to the mobile number of the
SIM card inside the GSM module. If you hear a ring back, the GSM module has
successfully established a network connection.

Okay! Now let’s see how to connect a GSM module to an Arduino board!

GSM Module with Arduino – Schematic Diagram

This schematic diagram helps us properly connect our Arduino Board to the SIM900A GSM
module.
There are two ways of connecting SIM900A GSM Module to the Arduino board. These
are explained below:

Arduino Communicating with GSM over Serial Connection

The first method includes serial communication between the SIM900A GSM module and the
Arduino board. We can use the serial pins to connect the Arduino to the GSM Module. In this
configuration, we will connect the Tx pin of the GSM Module to the Rx pin of the Arduino
board. Similarly, we will connect the Rx pin of the GSM Module to the Tx pin of the Arduino
Board. Now, we will connect the ground pin of the GSM module to the Ground pin of the
Arduino board. With this, our schematic is complete using serial communication. We have also
provided these connections in the table below:

Pin of SIM900A GSM Module Pin of Arduino Board

Tx Rx

Rx Tx

GND GND

Table 2: Serial Communication Pins

Note: There is a problem with this method. Our Arduino board uses serial ports during
programming to load the sketch from the Arduino IDE. In the event that these pins are
connected to another module, the Arduino is unable to upload the code successfully. So we
have to disconnect the module from the Tx and Rx pins of the Arduino board for successful
uploading of our program to the board. Once the sketch is uploaded, we can again connect
these pins, and they will not cause any problems.

Connecting with GSM using digital pins

For some users, this can be difficult while prototyping, where frequent changes in the program
are required during calibration. We can use an alternate method to avoid this issue. This method
requires an external library for serial communication with the SIM900A GSM Module using
PWM-based digital pins. We will use two digital pins with PWM capability as serial pins for
communication. The SoftwareSerial library replicates the hardware functions and handles the
task of serial communication. We will be using Arduino pins 9 and 10 for serial
communication. The connection table is provided below:
Pin of SIM900A GSM Module Pin of Arduino Board

Tx 10 as Rx

Rx 9 as Tx

GND GND

Table 3: SoftwareSerial Communication pins

Arduino Sketch – SIM900A GSM Module

This code sets up communication between an Arduino and a GSM module (SIM900A) using
SoftwareSerial. It allows the user to send an SMS or make a call by sending specific characters
(‘s’ for SMS, ‘d’ for dialing) through the Arduino’s Serial Monitor. The GSM module is
configured to send an SMS to a specified phone number with the message “I am SMS from
GSM Module” when ‘s’ is received and to dial a specified phone number when ‘d’ is received.

Open the Arduino IDE and go to File > New to create a new file. Now copy this sketch given
below and paste it in the Arduino File. Select the COM port of the connected Arduino board
and click Upload. This will upload the sketch to the Arduino board.

Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}

void loop()
{
if (Serial.available() > 0)
{
switch (Serial.read())
{
case 's':
SendMessage();
break;
case 'd':
DialCall();
break;
}
}
if (mySerial.available() > 0)
{
Serial.write(mySerial.read());
}
}

void SendMessage()
{
mySerial.println("AT+CMGF=1"); // Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milliseconds or 1 second

mySerial.println("AT+CMGS=\"+xxxxxxxxxxx\"\r"); // Replace x with mobile number


delay(1000);

mySerial.println("I am SMS from GSM Module"); // The SMS text you want to send
delay(100);

mySerial.println((char)26); // ASCII code of CTRL+Z


delay(1000);
}

void DialCall()
{
mySerial.println("ATD+xxxxxxxxxxxx;"); // ATDxxxxxxxxxx; -- watch out here for
semicolon at the end!!
delay(100);
}
EXPERIMENT 4
AIM: INTERFACING ARDUINO TO BLUETOOTH MODULE.
HC-05 Bluetooth to serial port module and how to interface it with Arduino. This Bluetooth
device operates on UART communication. In other words, it uses serial communication to
transmit and receive data serially over standard Bluetooth radio frequency. Therefore, we will
use TX, RX pins of Arduino to connect with the module.
We will use an android application to communicate with the Arduino through the HC-05
Bluetooth module. We will see an example to control an LED from the Android application
using Bluetooth wireless communication. The LED will be connected with a GPIO pin of the
Arduino and in effect, we will be controlling that pin.

Bluetooth Terminal Application


We will use an android smartphone that will connect to our ESP8266 development board. So,
make sure you have an android phone at hand. We will also use a Bluetooth terminal
application to pair the two devices together. Go to the Play Store and download the application
by the name: Serial Bluetooth terminal.

HC-05 Introduction
HC-05 is one of the commonly used Bluetooth device that uses a UART communication
protocol. The HC-05 Bluetooth is much different in features from all other Bluetooth devices
because of its multiple pins and their functions. It has multiple pins for the different method
which makes it unique as compared to others. The module normally operates at UART serial
communication with TX and RX pins at 9600 baud rates.
Pinout
The HC-05 comes with multiple pins and indicators, which helps to control different operations
and view their states through indicators. This pinout diagram provides indications of all pins.

The table below also briefly describes the functionality of each pin.
Pin Description

The operating voltage range is 3.3 volts. But I/O pins can withstand voltage of up to
VCC 5 volts. Therefore, we can connect 5 volts power source to this pin, and also other
pins can also operate on 5 volts signals such as Tx and Rx signals.

Ground reference of both ESP8266 and HC-05 should be at the same level.
GND Therefore, we should connect a power supply, HC05, and ESP8266 ground pins to
each other.

As discussed earlier, the HC-05 Bluetooth module uses UART communication to


Tx transmit data. This is a transmitter pin. The TX pin will be the data transfer pin of the
module in UART.

This pin is a data receiving the pin in UART communication. It is used to receive
Rx
data from the microcontroller and transmits it through Bluetooth.

The state shows the current state of the Bluetooth. It gives feedback to the controller
State about the connectivity of Bluetooth with another device. This pin has an internal
connection with the onboard LED which shows the working of HC05.

Using an external signal, Enable/Key pin is used to change the HC-05 mode between
data mode and command mode. The HIGH logic input will transfer the device in
Enable/Key
command mode and the LOW logic input will change the mode to data mode. By
default, it works in data mode.

The command and data mode states are changeable through a button present on the
Button
module.

LED This pin shows the working status of module along with the State pin
Connection Diagram:

Connect the circuit as follows:


• Bluetooth Tx with Arduino UNO Rx (D0)
• Bluetooth Rx with Arduino UNO Tx (D1)
• Bluetooth VCC with Arduino UNO +5V
• Bluetooth GND with Arduino UNO GND
• No need to connect any other pin as given in figure.
NOTE: Make sure you plug out the Tx and Rx pins out of Arduino before uploading the
program. After uploading the program connect them back. Otherwise, you can get an error.

Code for HC-05 Bluetooth module interfacing with arduino


int LED = 13; //led pin

int info = 0; //variable for the information comming from the bluetooth module

int state = 0; //simple variable for displaying the state

int checking = 8;

void setup() {

Serial.begin(9600); //making serial connection

pinMode(LED, OUTPUT); //defining LED pin

digitalWrite(LED, LOW); //once the programm starts, it's going to turn of the led, as it can
be missleading.
pinMode(checking, OUTPUT);
}
void loop() {

int sta = digitalRead(checking);

//Serial.println(sta);

if (Serial.available() > 0) { //if there is any information comming from the serial lines...

info = Serial.read();

state = 0; //...than store it into the "info" variable

if (info == '1') { //if it gets the number 1(stored in the info variable...

digitalWrite(LED, HIGH); //it's gonna turn the led on(the on board one)

if (state == 0) { //if the flag is 0, than display that the LED is on and than set that value to 1

Serial.println("LED ON"); //^^that will prevent the arduino sending words LED ON all
the time, only when you change the state

state = 1;

} else if (info == '0') {

digitalWrite(LED, LOW); //else, it's going to turn it off

if (state == 0) {

Serial.println("LED OFF"); //display that the LED is off

state = 1;

}
In your smartphone settings, enable Bluetooth and scan for available Bluetooth devices. You
will see the HC-05 device in your scanned list. The default name for this Bluetooth device is
“HC-05” and the default pin code is either “0000” or “1234”.

Setting up Android App


We will use an android smartphone to connect with our ESP8266 module. To do that you will
have to perform a series of steps.
After you have installed the ‘Serial Bluetooth Terminal app, open it. On the top left corner of
the screen, you will find three horizontal bars. Tap it.

Now, tap on the Devices tab.


In the ‘available devices’ section, select ‘HC-05’
After you have selected the HC-05 module then tap the ‘link’ icon at the top of the screen. At
first, you will get the message: ‘Connecting to HC-05.’ After a successful connection, you
will get the message: ‘Connected.’

Follow these steps to control LED:


• Download the “Bluetooth Terminal” App from Android playstore on your android
phone.
• Open the app and connect with HC-05 Bluetooth.
• Send 1 to turn on the LED.
• Send 0 to turn off the LED.
EXPERIMENT 5
AIM: INTRODUCTION TO RASPBERRY PI PLATFORM AND PYTHON
PROGRAMMING.
Raspberry Pi Platform Overview
Raspberry Pi is a small, affordable, single-board computer designed to promote programming
and computer science education. Despite its compact size, the Raspberry Pi is highly versatile,
supporting various applications in education, IoT (Internet of Things), robotics, home
automation, and even personal computing.
Key Features of Raspberry Pi:
• Processor: Typically an ARM-based CPU, such as the Quad-core Cortex-A72 found
in the Raspberry Pi 4.
• Operating System: Runs a Linux-based OS, with the most common being Raspberry
Pi OS (formerly Raspbian), though it supports others like Ubuntu and Windows IoT
Core.
• Connectivity: Offers various connectivity options, including Ethernet, Wi-Fi,
Bluetooth, USB, HDMI, and GPIO (General Purpose Input/Output) pins for connecting
sensors, motors, and other peripherals.
• Cost-Effective: Raspberry Pi boards start at around $35, making it accessible for
educational projects and prototyping.
Python Programming on Raspberry Pi
Python is the preferred programming language for Raspberry Pi due to its ease of use and vast
ecosystem of libraries. Whether you're building simple automation scripts, interfacing sensors
via GPIO, or developing complex machine learning models, Python is a suitable choice.
Why Use Python with Raspberry Pi?
1. Ease of Learning: Python's simple syntax makes it an excellent language for beginners,
allowing them to focus on learning concepts rather than dealing with complex language
structures.
2. Rich Libraries: Python has a large ecosystem of libraries that can be easily installed on
Raspberry Pi, including:
➢ RPi.GPIO for controlling the GPIO pins.
➢ picamera for interacting with the Raspberry Pi camera.
➢ OpenCV for computer vision applications.
➢ Pandas, NumPy, and SciPy for data analysis and machine learning.
1. Community Support: Python's popularity means there is extensive community
support, tutorials, and resources for Raspberry Pi projects.
2. Versatility: Python can handle a wide range of applications, from simple automation
to complex IoT and machine learning tasks on Raspberry Pi.
Basic Python Programming on Raspberry Pi
To get started with Python on Raspberry Pi, you can write and run Python scripts
directly on the Pi using the built-in Python interpreter or via an Integrated Development
Environment (IDE) like Thonny, which comes pre-installed on Raspberry Pi OS.
Example: Blinking an LED Using Python and GPIO
One of the first projects many users try is controlling an LED using the GPIO pins on
Raspberry Pi.
Steps:
1. Wiring: Connect an LED to one of the GPIO pins (e.g., GPIO pin 17) with a resistor.
2. Python Code:
python
Copy code
import RPi.GPIO as GPIO
import time

# Set up GPIO mode


GPIO.setmode(GPIO.BCM)
# Set up pin 17 as an output pin
GPIO.setup(17, GPIO.OUT)
# Blink the LED
try:
while True:
GPIO.output(17, GPIO.HIGH) # Turn LED on
time.sleep(1) # Wait for 1 second
GPIO.output(17, GPIO.LOW) # Turn LED off
time.sleep(1) # Wait for 1 second
except KeyboardInterrupt:
GPIO.cleanup() # Clean up GPIO pins on interrupt
This simple program turns an LED on and off, demonstrating how to control GPIO pins
using Python on the Raspberry Pi.
Applications of Raspberry Pi with Python
• IoT Projects: Connect sensors and devices to collect data and automate systems, such
as a smart home or environmental monitoring system.
• Robotics: Build and control robots, drones, or autonomous vehicles.
• Computer Vision: Use Python libraries like OpenCV to add vision to projects like
facial recognition or object detection.
• Data Logging: Create data acquisition systems by connecting sensors to the Raspberry
Pi and logging data in a CSV or database for further analysis.
EXPERIMENT 6
AIM: INTERFACING SENSORS TO RASPBERRY PI

IR Sensor (IR Proximity Sensor)


IR Sensors emit and receive Infrared radiation. They are often used as Proximity Sensors i.e.
detect and alarm if an object is close to the sensor. An IR Sensor Module basically consists of
three parts: an IR Transmitter, an IR Detector and a control circuit. Usually, an IR LED is used
as an IR Transmitter and a Photo Diode or a Photo Transistor (less often) is used as an IR
Detector. The control circuit consists of a Comparator IC with necessary components.
Raspberry Pi IR Sensor Interface
Now that we have seen a little bit about the IR Sensor Module and its connections, we will
proceed with interfacing IR Sensor with Raspberry Pi. The Raspberry Pi IR Sensor Interface
can be converted into a Proximity Detector, where the application will detect if the object is
too close to the sensor.
C Diagram

Components Required
• Raspberry Pi 3 Model B
• IR Sensor
• 5V Buzzer
• Mini Breadboard
• Connecting Wires
• Power Supply
• Computer

Circuit Design
The IR Sensor Module has only three Pins: VCC, GND and Data. Connect the VCC and GND
pins of the IR Sensor to +5V and GND pins of the Raspberry Pi. Then connect the Data pin of
the IR Sensor to GPIO23 i.e. Physical Pin 16 of the Raspberry Pi. In order to indicate the alarm,
I have used a simple 5V Buzzer. Connect one terminal of the buzzer to GND of Raspberry Pi
and the other terminal (usually marked +) to GPIO24 i.e. Physical Pin 18 of Raspberry Pi.
Code
The following is the code for interfacing IR Sensor with Raspberry Pi. It is written in Python.
import RPi.GPIO as GPIO
import time
sensor = 16
buzzer = 18
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(buzzer,GPIO.OUT)

GPIO.output(buzzer,False)
print "IR Sensor Ready....."
print " "

try:
while True:
if GPIO.input(sensor):
GPIO.output(buzzer,True)
print "Object Detected"
while GPIO.input(sensor):
time.sleep(0.2)
else:
GPIO.output(buzzer,False)

except KeyboardInterrupt:
GPIO.cleanup()
LED blink program
The schematic or connection diagram for blinking a LED using Raspberry Pi is as shown
below.

Connection Diagram:

Code:
import RPi.GPIO as GPIO
import time
led_pin = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
while True:
GPIO.output(led_pin, GPIO.HIGH)
time.sleep(1)
GPIO.output(led_pin, GPIO.LOW)
time.sleep(1)
GPIO.cleanup( )

DHT11 Sensor
We need to install two libraries/software for making DHT11 sensor work with Raspberry Pi
4. Open a terminal and type the following commands.

pip3 install adafruit-circuitpython-dht


sudo apt-get install libgpiod2

The first command installs Adafruit’s DHT library that works with CircuitPython. The
second command is a library for accessing the GPIO pins of Raspberry Pi.
Connections diagram:

The code for sensing temperature and humidity using DHT 11 sensor using Raspberry Pi 4 is
given below.
import time
import board
import adafruit_dht
dhtDevice = adafruit_dht.DHT11(board.D17)
while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
print(“Temp: {:.1f} F / {:.1f} C Humidity: {}% “.format(temperature_f,
temperature_c, humidity))
except RuntimeError as error:
# Errors happen fairly often, DHT’s are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
time.sleep(2.0)
EXPERIMENT 7
AIM: COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI USING ANY
WIRELESS MEDIUM.

Required Components:
• Ultrasonic Sensor
• 2 Arduino Uno
• Raspberry Pi 3
• 2 nRF24l01 transmitter and receiver
• Jump wires
• Arduino cable
• MINI USB 2.0 for Pi
• Breadboard
Required Software:
• Raspbian for pi
• Arduino IDE or Visual Studio
• Putty on a remote computer for SSH
• VNC viewer on a remote computer

Steps of Working:
1) Download Raspbian:
• Your Pi needs an OS. Download Raspbian from Raspberrypi.org ‘s download section:
• https://www.raspberrypi.org/downloads/raspbian/

2) Download SD Memory Card Formatter:


• It is used to format the SD card as it is needed that the SD card should be empty
before the flashing image you downloaded. You can download it
from https://www.sdcard.org/downloads/formatter/eula_windows/

3) Flash it onto an SD card:


• You need to flash this downloaded image to the micro SD card. Assuming your laptop
has an SD card slot or a micro Sd card reader, you need a flashing software like etcher.
Go ahead and download from https://etcher.io/
4) Configure Wi-Fi:
• It’s easier to make two devices talk to each other if they are in the same network. An
ethernet cable can easily make your laptop’s network available to the Pi. But we don’t
have one. So, we are going to add a file to the SD card so that the Pi boots with a wifi
pre-configured.
• The SD card mounts as two volumes boot and rootfs . Open the boot volume and create
a file named wpa_supplicant.conf on booting the RPi, this file will be copied to
/etc/wpa_supplicant directory in /rootfs partition. The copied file tells the Pi the WIFI
setup information. This would overwrite any existing WIFI configuration, so if you had
already configured WIFI on the pi, then that will be overwritten.
• A typical wpa_supplicant.conf file is as follows:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1country=US
network={ ssid="«your_SSID»" psk="«your_PSK»" key_mgmt=WPA-PSK}
NOTE: Your SSID is your WIFI’s name. And psk is the password of the WI-FI.
5) Enable SSH
• We will later access the Pi using a secured shell (SSH), SSH is disabled by default in
Raspbian. To enable SSH, create a file named ssh in the boot partition. If you are on
Linux, use the touch command to do that.
6) Find Pi’s Ip address:
• Before switching on your raspberry pi, we need to find out the existing devices
connected to the network. Make sure your laptop is connected to the same WIFI
network as the one you configured on pi above.
• Download the Advanced IP Scanner to scan the IP of our raspberry pi. You can
download it from here https://www.advanced-ip-scanner.com/

7) SSH into your Pi:


• To create a secured shell connection in Linux we can use the ssh command. If you are
on windows, try downloading Putty from https://www.putty.org/
Default credentials are:
username: pipassword: raspberry

8) Access Pi remotely:
• Sometimes it doesn’t feel right if we can’t use the mouse. For that, we need to look
into the Raspbian desktop.
• We need to setup VNC (Virtual Network Connection) to see and control Pi
graphically. Let’s do that.
• To access the remote desktop, you need VNC-viewer (client) for your laptop.
Fortunately, RealVNC is available for a lot of OSes, pick one for your OS
from https://www.realvnc.com/en/connect/download/viewer/
9) Commands for vncserver:
10) Now open VNC Viewer on your remote computer:

5. Implementation and Working:


5.1. Wireless communication of Arduino to Arduino with nRF24L01:
• In this, we will learn how to make wireless communication between two Arduino
boards using the NRF24L01. And measure distance with ultrasonic sensor and
transmit it to another Arduino with transceiver module.
Wiring Instructions:
To wire your NRF24L01+ wireless Sender to your Arduino, connect the following pins:
• Connect the VCC pin to 3.3 Volts
• Connect the GND pin to ground (GND)
• Connect the CE pin to Arduino 9
• Connect the CSN pin to Arduino 10
• Connect the SCK pin to Arduino 13
• Connect the MOSI pin to Arduino 11
• Connect the MISO pin to Arduino 12
To wire your ultrasonic sensor to your Arduino, connect the following pins:
• Connect the VCC pin to Arduino 5Volts
• Connect the GND pin to ground (GND)
• Connect the Trig pin to Arduino 4
• Connect the Echo pin to Arduino 3

Schematic Diagram for wiring of Arduino Uno with ultrasonic sensor and NRF24L01
To wire your NRF24L01+ wireless sender to your Arduino, connect the following pins:
• Connect the VCC pin to 3.3 Volts
• Connect the GND pin to ground (GND)
• Connect the CE pin to Arduino 9
• Connect the CSN pin to Arduino 10
• Connect the SCK pin to Arduino 13
• Connect the MOSI pin to Arduino 11
• Connect the MISO pin to Arduino 12

Schematic Diagram for wiring of Arduino Uno NRF24L01


NOTE: RF24 module is mandatory for the code to run so you can add the library accordingly
• Start Arduino IDE then add the Downloaded Library from Here :
5.2. Code:
Sender Side code:
Receiver Side code:
Sending the Data

Receiving the data:


6. Wireless communication of Arduino to Raspberry Pi with nRF24L01:
6.1: Installation of RF24 Module on Raspberry Pi:
• It is the most important and foremost step for any Communication to work between
Arduino and Raspberry Pi as we have used RF24 library in Arduino for
communication so the same Library is needed on Pi.
• Further are the steps to which involve the installation of the Library. It took me almost
one week to install it as no clear idea about it is present.
=> Way to go:
1. Login to Raspberry Pi using Putty.
2. Go to the VNC server for GUI.
3. In the terminal type:
sudo raspi-config
Turn on SPI from Interfacing options in config

4. Reboot the Pi. In the terminal, type:


sudo reboot
5. In the terminal type:
sudo apt-get update
6. Download the install.sh file from http://tmrh20.github.io/RF24Installer/RPi/install.sh or
Run this on terminal:
wget http://tmrh20.github.io/RF24Installer/RPi/install.sh
7. Make it executable:
chmod +x install.sh
8. Run it and choose your options:

9. Run an example from one of the libraries:


cd rf24libs/RF24/examples_linux
make
sudo ./gettingstarted
Run Following Commands to run the program.
10. Further, if we want to run Python Programs for the same purpose, we can do this:
Running the Example Edit the pingpair_dyn.py example to configure the appropriate pins per
the above documentation:
nano pingpair_dyn.py
• Configure another device, Arduino or RPi with the pingpair_dyn example
• Run the example
sudo python pingpair_dyn.py
6.2. Wireless communication of Arduino to Arduino with nRF24L01:
• In this, we will learn how to make wireless communication between Arduino and
Raspberry Pi using the NRF24L01. And measure distance with an ultrasonic sensor
with the help of Arduino Uno and transmit it to Raspberry Pi and Data is received.
Wiring Instructions:
To wire your NRF24L01+ wireless Sender to your Arduino, connect the following pins:
• Connect the VCC pin to 3.3 Volts
• Connect the GND pin to ground (GND)
• Connect the CSN pin to Arduino 10
• Connect the CE pin to Arduino 9
• Connect the SCK pin to Arduino 13
• Connect the MISO pin to Arduino 12
• Connect the MOSI pin to Arduino 11
To wire your ultrasonic sensor to your Arduino, connect the following pins:
• Connect the VCC pin to Arduino 5Volts
• Connect the GND pin to ground (GND)
• Connect the Trig pin to Arduino 4
• Connect the Echo pin to Arduino 3
Schematic Diagram:
Schematic Diagram for wiring of Arduino Uno with ultrasonic sensor and NRF24L01
To wire your NRF24L01+ Wireless Receiver to your Raspberry Pi, connect the following
pins:
• Connect the VCC pin to 3.3 Volts (Pin 1)
• Connect the GND pin to ground (GND) (Pin 6)
• Connect the CE pin to Raspberry GPIO 22
• Connect the CSN pin to Raspberry GPIO 8
• Connect the SCK pin to Raspberry GPIO 11
• Connect the MOSI pin to Raspberry GPIO 10
• Connect the MISO pin to Raspberry GPIO 09
Schematic Diagram:

Schematic Diagram for wiring of Raspberry Pi and NRF24L01


6.3. Code:
Sender Side Code:
Receiver Side Code:
• It's not mandatory to use this code as it is tweaked by me as per my requirement.
To check the proper functioning of your connection and code you can run the examples
present in the library like pingpair_dyn.ino on your Arduino and pingpair_dyn.py on
Raspberry Pi
• The snippet of my running communication:
EXPERIMENT 8
AIM: SETUP A CLOUD PLATFORM TO LOG THE DATA.

Steps of Working:
You can write logs to Cloud Logging from Python applications by using the standard Python
logging handler, or by using the Cloud Logging API client library for Python directly. When
you use the standard Python logging handler, you must attach a Cloud Logging handler to the
Python root handler. Start by creating a Google Cloud account. With this account, you get $300
in free credits, plus free usage of over 20 products, up to monthly limits.
Create an account
1. In the Google Cloud console, on the project selector page, select or create a Google
Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a
project instead of selecting an existing project. After you finish these steps, you can
delete the project, removing all resources associated with the project.
2. Make sure that billing is enabled for your Google Cloud project.
3. Enable the Cloud Logging API.
4. Prepare your environment for Python development.
Install the library
To install the Cloud Logging library for Python, see Install the client library for Python. This
library lets you attach a Cloud Logging handler to the standard Python root handler. You can
also use this library to send API requests to Cloud Logging.
Write logs with the standard Python logging handler
To send all log entries that are written with the standard Python root handler to Cloud
Logging, do the following:
1. Attach the Cloud Logging handler to the Python root logger by calling
the setup_logging method:
# Imports the Cloud Logging client library
import google.cloud.logging
# Instantiates a client
client = google.cloud.logging.Client()
# Retrieves a Cloud Logging handler based on the environment
# you're running in and integrates the handler with the
# Python logging module. By default this captures all logs
# at INFO level and higher
client.setup_logging()
2. Write log data by using the Python root logger:
# Imports Python standard library logging
import logging
# The data to log
text = "Hello, world!"
# Emits the data using the standard logging module
logging.warning(text)
By default, any log whose severity level is at least INFO that is written by your application is
sent to Cloud Logging.
If messages are logged to Logging from App Engine or Google Kubernetes Engine, then the
handler sends them to those environments' respective resource types; otherwise, logs are listed
under the python log in the Global resource type.

Write logs with the Cloud Logging client library


For information on using the Cloud Logging client library for Python directly,
see Cloud Logging Client Libraries.
Run on Google Cloud
For an application to write logs by using the Cloud Logging library for Python, the
service account for the underlying resource must have the Logs Writer
(roles/logging.logWriter) IAM role. Most Google Cloud environments automatically
configure the default service account to have this role.
App Engine
Cloud Logging is automatically enabled for App Engine, and your app's default service
account has the IAM permissions by default to write log entries.
For more information, see Writing and viewing logs.
Google Kubernetes Engine (GKE)
GKE automatically grants the default service account the Logs Writer
(roles/logging.logWriter) IAM role. If you use Workload Identity Federation for
GKE with this default service account to let workloads access specific Google Cloud
APIs, then no additional configuration is required. However, if you use Workload
Identity Federation for GKE with a custom IAM service account, then ensure that the
custom service account has the role of Logs Writer (roles/logging.logWriter).
If needed, you can also use the following command to add the logging.write access
scope when creating the cluster:
gcloud container clusters create example-cluster-name \
--scopes https://www.googleapis.com/auth/logging.write

Compute Engine
Note: To use the Cloud Logging library for Python on a Compute Engine VM instance,
you do not need to install the Cloud Logging agent.
When using Compute Engine VM instances, add the cloud-platform access scope to
each instance. When creating a new instance through the Google Cloud console, you
can do this in the Identity and API access section of the Create Instance panel. Use the
Compute Engine default service account or another service account of your choice, and
select Allow full access to all Cloud APIs in the Identity and API access section.
Whichever service account you select, ensure that it has been granted the Logs Writer
role in the IAM & Admin section of the Google Cloud console.
Run locally and elsewhere
To use the Cloud Logging library for Python outside of Google Cloud, including
running the library on your own workstation, on your data center's computers, or on the
VM instances of another cloud provider, you must supply your Google Cloud project
ID and appropriate service account credentials directly to the Cloud Logging library for
Python.
For existing service accounts, do the following:
1. Grant the service account the IAM the Logs Writer (roles/logging.logWriter) IAM role.
For more information on IAM roles, see Access control.
2. Set up Application Default Credentials.
If you don't have a service account, then create one. For information about this process,
see Create service accounts.
For general information about the methods that you can use to authenticate,
see Terminology: service accounts.
View the logs
In the Google Cloud console, go to the Logs Explorer page:
Go to Logs Explorer
If you use the search bar to find this page, then select the result whose subheading
is Logging.
In the Logs Explorer, you must specify one or more resources, but the resource selection
might not be obvious. Here are some tips to help you get started:
• If you are deploying your application to App Engine or using the App Engine-specific
libraries, set your resource to GAE Application.
• If you are deploying your application on Compute Engine, set the resource to GCE VM
Instance.
• If you are deploying your application on Google Kubernetes Engine, your cluster's
logging configuration determines the resource type of the log entries. For a detailed
discussion on the Legacy Google Cloud Observability and the Google Cloud
Observability Kubernetes Monitoring solutions, and how those options affect the
resource type, see Migrating to Google Cloud Observability Kubernetes Monitoring.
• If your application is using the Cloud Logging API directly, the resource is dependent
on the API and your configuration. For example, in your application, you can specify a
resource or use a default resource.
• If you don't see any logs in the Logs Explorer, to see all log entries, switch to the
advanced query mode and use an empty query.
1. To switch to the advanced query mode, click menu (▾) at the top of the Logs
Explorer and then select Convert to advanced filter.
2. Clear the content that appears in the filter box.
3. Click Submit Filter.
You can examine the individual entries to identify your resources.
(or)
Logging in Google Cloud Platform
Logging provides us information like what is the execution flow, what event is
happening at what time and all the information of errors warnings if something goes,
logs help us to debug the problem step by step, usually in common practice we will try
to write logs related to that program flow or execution into a file or some other database
so which would help us in trouble shooting , in the same way Google Cloud Platform
provides Logging as a managed service and it is part of Google Cloud Operations
Suite.
Cloud Logging in GCP
It provides the log information related to any service available in the google cloud
platform it’s not constrained to a particular group of services, so you can keep an eye
on everything that’s happening in your organization GCP account and GCP also
provides you with APIs to manage logs programmatically, so basically it just lets us
to View, Query and Download the logs.
Below is an example log provided for your understanding.
{
httpRequest: {1}
insertId: "6375e32e0002d2cd0d2df081"
labels: {1}
logName: "projects/rock-partition-
363003/logs/appengine.googleapis.com%2Frequest_log"
operation: {4}
protoPayload: {28}
receiveTimestamp: "2022-11-17T07:30:54.185767503Z"
resource: {2}
severity: "INFO"
spanId: "8272484813176817280"
timestamp: "2022-11-17T07:30:53.051635Z"
trace: "projects/rock-partition-363003/traces/a8909f84c4f1f49a014d3a804cf4b117"
traceSampled: true
}
The basic information inside this a log entry are Time Stamp gives details of event
occurrence time and date like when the event is happened related to any particular
service and Resource from where that particular log information is generated for
example let’s say if you are trying to access big query so that related information
should have big query as a resource and detail information will be provided
in Payload , payload is been removed from the above given log as a payload will have
many line
In Cloud Logging logs are available in Json format, for a single log entry in order to
analyze this Json file you need to manually go through the whole Json syntax, Noo,
that’s a terrific task right, to help you with this GCP also allows you to export these
logs to some other google cloud services like Big Query, Google Cloud Storage for
further processing or analysis.
Types of audit logs in Cloud Computing
Now let’s see what the different type of audit logs are we have
Admin activity: Operations like creating, modifying or deleting a resource comes
under this admin related activity, so all these related activities are captured under admin
activity logs. You can also look into AWS cloudtails to find out action related every
API.
Data access: Logs generated from the activities made for accessing data are captured
under Data access logs, logs are generated even when data is not accessed and captured.
System event: system event means for example let’s say, you have scheduled
something to happen in a specified time like a life cycle for objects stored in Cloud
Storage, whenever the life cycle rules applied on the objects, logs will be generated,
and these logs will be captured as System event logs. Such as Linux operating system
logs would be available at /var/log/messages about every system activity.

Now let’s explore how this logging interface looks like, on your GCP web console go
to logging under operations,

You will be landing on Logs explorer page, here you can View and Query logs, and
also apply various filters and severities, just expand a log to analyze it, you can also
simply share the log link to your team member to discuss on it (he/she can only see the
log if the GCP account they are using has the required IAM privileges)
IAM role required for viewing a log is log.viewer .
Now let’s apply some filters from the console itself and understand the auto generated
queries, select a resource and the severity of the event to filter the logs. I am just
selecting info logs of service Google App Engine as I do not have any errors or
warnings from it.
below is the auto generated query from the applied filters.
severity=INFO
resource.type="gae_app"
as mentioned, you can also save this query for future use by just clicking on the save
button on the top right corner and you can also set the specific time frame to get the
logs as shown below.

Setting the time frame, you can set the time frame from the histogram tab or by ,
EXPERIMENT 9
AIM: LOG DATA USING RASPBERRY PI AND UPLOAD TO THE CLOUD
PLATFORM.

Steps of Working:
To log data using a Raspberry Pi and upload it to a cloud platform, you can use Fluentd or
Google Cloud Logging:
• Fluentd
This tool can be used to log data and upload it to the cloud. Here are some steps to use
Fluentd:
1. Install Raspbian, a free operating system
2. Install Fluentd
3. Configure and launch Fluentd
4. Prepare the fluentd.conf file
5. Launch Fluentd via your terminal
6. Test the configuration by posting a JSON message to Fluentd via HTTP
7. Access the databases page to confirm that your data has been uploaded
• Google Cloud Logging
This tool can be used to write logs from Raspberry Pi. Here are some steps to use Google
Cloud Logging:
1. Create a service account from the GCP console
2. Create a new key and download it as a JSON file
3. Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to
provide the JSON file to the logging driver

Method 2:
ThingSpeak is an open IoT platform for monitoring your data online. In ThingSpeak channel
you can set the data as private or public according to your choice. ThingSpeak takes minimum
of 15 seconds to update your readings. Its a great and very easy to use platform for building
IOT projects.
There are also some other platforms available for monitoring your data online which we will
cover in later articles but there are some advantages of ThingSpeak over other platforms like it
is very easy to set up and it also has many options to plot graph.

Components Required
1. Raspberry Pi
2. Power Cable
3. WiFi or Internet
Steps for building Raspberry Pi Data Logger on Cloud
Step 1: Signup for ThingSpeak
For creating your channel on ThingSpeak you first need to sign up on ThingSpeak. In case if
you already have account on ThingSpeak just sign in using your id and password.
For creating your account go to www.thinspeak.com

Click on signup if you don’t have account and if you already have account click on sign in.
After clicking on signup fill your details.

After this verify your E-mail id and click on continue.

Step 2: Create a Channel for Your Data


Once you Sign in after your account verification, Create a new channel by clicking “New
Channel” button
After clicking on “New Channel”, enter the Name and Description of the data you want to
upload on this channel. For example I am sending my CPU data (temperature), so I named it
as CPU data.
Now enter the name of your data (like Temperature or pressure) in Field1. If you want to use
more than one Field you can check the box next to Field option and enter the name and
description of your data.
After this click on save channel button to save your details.

Step 3: Getting API Key in ThingSpeak


To send data to ThingSpeak, we need an unique API key, which we will use later in our python
code to upload our CPU data to ThingSpeak Website.
Click on “API Keys” button to get your unique API key for uploading your CPU data.
Now copy your “Write API Key”. We will use this API key in our code.

Step 4: Python Code for Raspberry Pi


Complete code is given at the end of this tutorial, just make a file with any name and .py
extension and copy-paste the code and save the file. Don’t forget to replace the API key with
yours. You can run the python file any time using below command:
python /path/filename.py

Assuming you already installed python in Raspberry pi using this command


sudo apt-get install python

Case 1: If you are using monitor screen then just use the given code.
Now install all libraries:
sudo apt-get install httplib
sudo apt-get install urllib

After installing libraries run your python code (python /path/filename.py)


If the code runs properly you will see some CPU temperature values as shown in below
image.
If there are any errors uploading the data, you will receive “connection failed” message.
Case 2: If you are using “Putty” then you should follow these commands:
First update your pi using:
sudo apt-get update

After this make a file cpu.py using:


nano cpu.py

After creating this file copy your code to this file and save it using CTRL + X and then ‘y’
and Enter.
After this install all libraries using:
sudo apt-get install httplib
sudo apt-get install urllib

After installing libraries run your python code using:


python cpu.py

If the code runs properly you will see some CPU temperature values as shown in above
image.

Step 6: Check ThingSpeak site for Data Logging


After completing these steps open your channel and you will see the CPU temperature data is
updating into ThingSpeak website.
EXPERIMENT 10
AIM: DESIGN AN IOT BASED SYSTEM.

Designing an IoT-based system involves several steps that include defining the problem,
selecting the appropriate hardware, software, and communication protocols, and integrating
everything for seamless operation. Here's a basic step-by-step guide on how to design an IoT-
based system:
1. Define the Problem/Objective
• Identify the specific problem the IoT system will solve or the application it will support.
For example, is it for home automation, industrial monitoring, healthcare, etc.?
• Clearly define the objectives, such as monitoring temperature, controlling devices, or
collecting sensor data.
2. Identify System Requirements
• Sensors/Actuators: Determine what needs to be sensed (e.g., temperature, humidity,
motion) and controlled (e.g., motors, lights).
• Connectivity: What communication method will be used to transmit data? Options
include Wi-Fi, Bluetooth, Zigbee, LoRa, or cellular networks.
• Data Processing: Will data processing happen locally (edge computing) or on the
cloud? Define how much computational power is required.
• Power: Consider whether the system will be battery-powered or plugged in, and
calculate the power requirements accordingly.
3. Select Hardware Components
• Microcontroller/Microprocessor: Choose between a microcontroller (e.g., Arduino)
or a microprocessor (e.g., Raspberry Pi) depending on the complexity of the system.
• Sensors/Actuators: Select appropriate sensors based on the requirements (e.g.,
temperature sensor, motion sensor).
• Communication Modules: Choose the right communication module such as Wi-Fi
modules (ESP8266, ESP32), Bluetooth modules, or Zigbee modules.
• Power Supply: Design the power supply based on the consumption of sensors and
controllers.
4. Select a Communication Protocol
• Based on the use case, choose the appropriate communication protocol (Wi-Fi,
Bluetooth, Zigbee, LoRa).
• Protocols like MQTT, HTTP, or CoAP can be used for communication between
devices and servers/cloud.
5. Develop Software/Code
• Write the code for data acquisition from sensors, controlling actuators, and
communication with the cloud or a central system.
• For microcontroller-based systems (Arduino), use IDEs like Arduino IDE.
• For microprocessor-based systems (Raspberry Pi), you can use Python or C++ for more
complex tasks.
• Implement communication libraries (e.g., for MQTT, HTTP, or WebSockets).
6. Cloud/Server Integration
• If data needs to be processed or stored, choose a cloud platform like AWS IoT, Google
Cloud IoT, or ThingSpeak.
• For server-based systems, you can use a local server with a database like MySQL or
MongoDB.
• Create APIs or use existing cloud platforms for data visualization, control, and
analytics.
7. Data Processing and Analytics
• Implement algorithms to process sensor data in real-time.
• Use machine learning if the system involves pattern recognition or anomaly detection.
• For IoT systems with low processing power, offload the data to the cloud for advanced
analytics.
8. User Interface
• Design a dashboard or mobile application for monitoring the system, controlling
devices, or visualizing data.
• You can use platforms like Blynk, Node-RED, or custom web/mobile applications.
9. Test the System
• Run tests to check data accuracy, communication reliability, and response time.
• Check for any latency in the system and ensure the components work seamlessly
together.
10. Security Considerations
• Implement strong authentication mechanisms for device access.
• Encrypt data during transmission to protect it from being intercepted.
• Update firmware regularly to patch any security vulnerabilities.
Smart Home Lighting System
• Objective: Control lights remotely via smartphone and monitor energy usage.
• Requirements: Wi-Fi-enabled microcontroller, relay module for switching lights,
current sensor for energy monitoring.
• Hardware: ESP8266 microcontroller, relay module, current sensor (ACS712).
• Communication: Wi-Fi, MQTT protocol.
• Software: Arduino IDE for microcontroller code, Blynk for smartphone app.
• Cloud: Blynk or similar platform for control and data monitoring.

You might also like