IoT Lab Manual
IoT Lab Manual
LAB MANUAL
Semester : VII
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.
• 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.
1. Arduino Board: The hardware includes an Atmel microcontroller, digital and analog
input/output pins, and communication interfaces.
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
➢ 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.
➢ Open the Arduino IDE software on your computer. Coding in the Arduino language will
control your circuit.
➢ 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.
➢ 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.
➢ 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++.
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:
void setup() {
void loop() {
}
EXPERIMENT 2
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.
3. Configure your computer’s serial port settings to a baud rate of 9,600, 8 data bits, no
parity, and 1 stop bit.
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
void setup() {
void loop() {
void setup() {
void loop() {
if (Serial.available() > 0) {
Serial.print("Received: ");
}
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.
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.
Here are some important AT commands for the SIM900A GSM module:
AT Command Description
AT+CPIN? Checks the status of the SIM card (PIN ready or not).
Hardware Components:
Here we have listed the hardware components we will be using in this tutorial:
• Jumper Wires
1. Insert the SIM card into the GSM module and lock it.
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!
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:
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:
Tx Rx
Rx Tx
GND GND
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.
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
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("I am SMS from GSM Module"); // The SMS text you want to send
delay(100);
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.
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.
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:
int info = 0; //variable for the information comming from the bluetooth module
int checking = 8;
void setup() {
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() {
//Serial.println(sta);
if (Serial.available() > 0) { //if there is any information comming from the serial lines...
info = Serial.read();
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;
if (state == 0) {
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”.
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.
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/
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:
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
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.
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.
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 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
If the code runs properly you will see some CPU temperature values as shown in above
image.
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.