Pava
Pava
202045613
Experiment 1
1. Study of Arduino board with their pin diagram and Interfacing
of LED (s) with Arduino.
The most popular Arduino board is the Arduino UNO, based on the ATmega328P
microcontroller.
Arduino Mega ATmega2560 54 (15 PWM) 16 Used for projects needing more
I/O
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Applications of Arduino
• Home automation systems
• Robotic control systems
• Weather monitoring stations
• IoT-based devices
• Industrial automation
• Educational tools and simulation
The Arduino Uno is an excellent tool for learning embedded systems and electronics. Its open-
source nature, simple hardware, and extensive community support make it a preferred choice
for engineers and students. Understanding the Arduino board's pin configuration, architecture,
and programming methodology is fundamental for designing and implementing electronic
projects effectively.
Components Required
• Arduino Uno board
• Breadboard
• LED
• 220-ohm resistor
• Jumper wires
• USB cable for Arduino
Circuit Description
• The anode (longer leg) of the LED is connected to digital pin 13 of the Arduino
through a 220-ohm resistor.
• The cathode (shorter leg) of the LED is connected to GND.
• The resistor is used to limit the current to protect the LED.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Code:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 2
2. Study and implementation of Buzzer, Switches, LCD, keypad,
LDR, Ultrasonic sensors and PWM interfacing with Arduino.
1. Introduction
Using Arduino, we can easily interface a variety of sensors and modules to build
real-world interactive systems.
In this experiment, we have used the Arduino Uno board to interface the
following components:
• Ultrasonic Sensor (HC-SR04)
• LDR (Light Dependent Resistor)
• Heartbeat Sensor
• Joystick Module
Each component is implemented separately with its description, circuit
explanation, and sample code.
Ultrasonic Sensor (HC-SR04)
Working Principle:
The ultrasonic sensor measures distance by emitting an ultrasonic pulse and
calculating the time it takes for the echo to return.
Distance (cm)=(Time×0.0343)/2
Pin Configuration:
• VCC → 5V
• GND → GND
• TRIG → Digital Pin 9
• ECHO → Digital Pin 10
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Circuit Description:
• Connect the TRIG pin to pin 9 and ECHO to pin 10 on the Arduino.
• VCC to 5V and GND to Arduino’s GND.
Code:
const int trigPin = 9;
const int echoPin = 10;
void setup() {
[Link](9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
Output:
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Code:
void setup() {
[Link](9600);
}
void loop() {
int lightValue = analogRead(A0);
[Link]("Light Intensity: ");
[Link](lightValue);
delay(500);
}
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Output:
Heartbeat Sensor
Working Principle
The heartbeat sensor detects the pulse by sensing the change in blood flow
using an infrared LED and photodiode.
Pin Configuration
• VCC → 5V
• GND → GND
• OUT → Analog Pin A1
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Circuit Description
Connect the sensor’s OUT pin to A1, VCC to 5V, and GND to Arduino GND.
Code:
int k = 0;
float y,x;
void setup()
{
pinMode(A0, INPUT);
pinMode(8,OUTPUT);
[Link](9600);
}
void loop()
{
while (k < 5) {
//[Link]((double)analogRead(A0)/1024);
x = (-40 + 0.488155 * (analogRead(A0) - 20));
y = (x - 32) * (5.0/9.0);
[Link]("Fahrenheit : " );
[Link](x);
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
[Link]("Celcius : " );
[Link](y);
if (y > 30){
digitalWrite(8,HIGH);
}
else{
digitalWrite(8,LOW);
}
delay(1000); // Wait for 1000 millisecond(s)
k += 1;
}
}
Output:
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Joystick Module
Working Principle
A joystick module includes two potentiometers (X and Y axes) and a push-
button. It outputs analog values depending on the direction of movement.
Pin Configuration
• VCC → 5V
• GND → GND
• VRx → Analog Pin A2
• VRy → Analog Pin A3
• SW (Switch) → Digital Pin 7
Circuit Description
Connect VRx to A2, VRy to A3, SW to pin 7, VCC to 5V, and GND to GND.
Code:
void setup()
{
[Link](9600);
pinMode(9,INPUT); // SW pin
digitalWrite(9,HIGH);
}
int prev_state=0; // previous state of switch
void loop() {
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
int z=0,xpos=0,ypos=0;
int x=analogRead(A0);
int y=analogRead(A1);
int sensitivity=10; // you can adjust the sensitivity based on your comfort
if(x>=550) // when moved up
xpos=map(x,550,1023,0,sensitivity);
if(x<=450) // when moved down
xpos=map(x,450,0,0,-sensitivity);
if(y>=550) // when moved right
ypos=map(y,550,1023,0,sensitivity);
if(y<=450) // when moved left
ypos=map(y,450,0,0,-sensitivity);
int curr_state=digitalRead(9);
if(curr_state==1 && prev_state==0) // when SW is pressed
z=1;
else
z=0;
if(xpos!=0 or ypos!=0 or z==1) // prints only when the joystick is moved
{
[Link](xpos); // print the data and separating by ":"
[Link](":");
[Link](ypos);
[Link](":");
[Link](z);
}
prev_state=curr_state;
delay(10); // for normal operation
}
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Output:
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 3
3. To interface Bluetooth with Arduino/Raspberry Pi and
write a program to send sensor data to smartphone using
Bluetooth.
Requirements: HC-05 Bluetooth Module, Arduino UNO Board, Breadboard,
jumper wires, Bluetooth App.
Pin Description:
• EN: The module is enabled if the pin to EN is connected to 3.3V
supply, the module remains disabled if connected to GND.
• +5V: This is the supply pin for connecting +5V. As the module has
on-board 3.3V regulator, you can provide +5V supply.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
• STATE: This is a status indicator pin. This pin goes LOW when the
module is not connected to any device. When the module is
paired with any device, this pin goes HIGH.
Procedure:
1. Make the connections as shown in the above image. Don't connect the
RX & TX pins before uploading the code!
2. Copy the code given below.
3. Download the app called Blue Control from Google Play Store. You can
down-load it from the following link Bluetooth Controller. You can make
your own Android app by using MIT App inventor.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
4. Open the app blue control (It will automatically turn on the device's
Blue-tooth). Go to options. Click on "Connect to Robot". Choose the device
HC 05.
5. When you are connecting to the Bluetooth module for the first time, it
will ask you the password. Enter 0000 or 1234.
6. When the device gets successfully paired with the sensor, the LED lights
on sensor will start blinking at a slower rate than usual.
void connectToWiFi() {
[Link](WIFI_SSID);
[Link](WIFI_SSID, WIFI_PASS);
int retries = 0;
delay(500);
[Link](".");
retries++;
if ([Link]() == WL_CONNECTED) {
[Link]([Link]());
} else {
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
void setup() {
[Link](115200);
delay(100);
connectToWiFi();
void loop() {
if ([Link]() != WL_CONNECTED) {
connectToWiFi();
delay(5000);
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 4
4. Study NodeMCU with their pin diagram and Implementation
LED
(s) Interfacing with NodeMCU.
1. Introduction
The NodeMCU is an open-source development board built around the ESP8266 Wi-Fi
module, which is widely used in IoT (Internet of Things) projects due to its low cost,
built-in Wi-Fi capability, and ease of programming. It provides a simple and efficient
platform for developers to connect physical devices to the internet and control them
wirelessly.
One of the fundamental steps in learning to work with NodeMCU is understanding its pin
diagram, which includes GPIO (General Purpose Input/Output) pins, power pins, and
communication interfaces such as UART, SPI, and I2C. Familiarity with these pins is
crucial for interfacing the board with external components like sensors, actuators, and
LEDs.
2. Features
• Built-in Wi-Fi module (ESP8266) for IoT applications.
• Based on ESP8266 Wi-Fi SoC
• Supports standard Arduino IDE for programming
• Multiple GPIO pins available for interfacing
• Low Power Consumption: Ideal for battery-powered and portable devices.
• Analog Input: Single ADC (A0) pin for analog sensor readings.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Output:
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Applications:
• IoT based smart home projects
• Wireless sensor data transmission
• Remote monitoring and control
• Prototyping connected devices
Conclusion
NodeMCU is a versatile and affordable platform for IoT development. Its Wi-Fi
capabilities, multiple GPIO pins, and support for MicroPython make it ideal for
a wide range of smart device projects.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 5
5. Write a program on Arduino/Raspberry Pi to retrieve Temperature and humidity
data from things peak cloud.
Required Components
• ESP8266 Wi-Fi Module (NodeMCU)
• HC-SR04 Ultrasonic Sensor
• Breadboard
• Jumper Wires
Circuit Connections
The wiring for this project is straightforward. Connect the components as detailed below:
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 6
[Link] a program on Arduino/Raspberry Pi to publish
temperature data to MQTT broker.
Prerequisites
Before starting, ensure your development environment is correctly configured. You need to
have the ESP8266 board manager installed in your Arduino IDE. Additionally, the
PubSubClient library by Nick O'Leary is required for MQTT communication and must be
installed through the Arduino IDE's library manager. This experiment will utilize a free,
public MQTT broker, so a local setup is not needed. The broker details are:
• Broker Address: [Link]
• Port: 1883 (Standard unencrypted MQTT port)
Hardware Components
• NodeMCU ESP8266 Board
• LM35 Temperature Sensor
• Breadboard for prototyping
• Jumper Cables for connections
• Micro-USB Cable for power and programming
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
The program enables the NodeMCU to first connect to a specified Wi-Fi network. Once
online, it establishes a connection with the public HiveMQ MQTT broker. The device will
then periodically, every 10 seconds, read the analog value from the LM35 temperature
sensor. This value is converted into a temperature reading in degrees Celsius. Finally, this
temperature data is "published" (sent) to the MQTT topic iot/college/temperature. Any
other client or application subscribed to this specific topic will receive the temperature data in
real-time.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0; // To store the last time a message was published
void setup() {
[Link](115200);
[Link]();
connectToWiFi();
[Link](mqtt_broker, mqtt_port);
}
void connectToWiFi() {
[Link]("Connecting to ");
[Link](ssid);
[Link](ssid, password);
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
// Attempt to connect
if ([Link](clientId.c_str())) {
[Link]("connected!");
} else {
[Link]("failed, rc=");
[Link]([Link]());
[Link](" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
// Ensure the MQTT client is connected
if (![Link]()) {
reconnectMQTT();
}
[Link]();
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
[Link]("Failed to read from DHT sensor!");
return;
}
[Link](mqtt_topic, jsonPayload);
[Link]("Published to topic: ");
[Link](mqtt_topic);
[Link]("Payload: ");
[Link](jsonPayload);
}
}
Output:
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 7
1. Controlling Appliances using NodeMCU MQTT over the
Internet. (Adafruit Cloud).
• Requirements:
➢ Hardware:
NodeMCU (ESP8266)
Relay module (to control AC appliances safely)
Jumper wires, Breadboard
LED
➢ Software
Arduino IDE (with ESP8266 board installed)
Required libraries:
Adafruit_MQTT and Adafruit_MQTT_Client
ESP8266WiFi
Procedure
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
4. Create a new Feed and give it a name, for instance, appliance1. This
feed will hold the on/off state of your device.
5. Finally, create a new Dashboard. Add a control element like a Toggle
Button and link it to the appliance1 feed you just created. This button
will be your remote control.
Code:
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WIFI_SSID "Realme 7"
#define WIFI_PASS "12345678S"
#define AIO_SERVER "[Link]"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "Sneh5824"
#define AIO_KEY " aio_zacU53fhiF7iS8U1gc5a79VgOT6v"
// Create WiFi and MQTT clients
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME,
AIO_KEY);
// Feed (appliance control)
Adafruit_MQTT_Subscribe appliance1 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME
"/feeds/appliance1")
// Relay pin
#define RELAY_PIN D1
void setup() {
[Link](115200);
delay(10);
pinMode(RELAY_PIN, OUTPUT);
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
// Control relay
if (strcmp((char *)[Link], "ON") == 0) {
digitalWrite(RELAY_PIN, LOW); // Turn ON appliance
}
else if (strcmp((char *)[Link], "OFF") == 0) {
digitalWrite(RELAY_PIN, HIGH); // Turn OFF appliance
}
}
}
}
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Step 5 – Testing
1. Upload the code to NodeMCU.
2. Open Arduino Serial Monitor (115200 baud) → Check WiFi + MQTT connection.
3. Go to Adafruit IO Dashboard → Toggle the switch.
4. The relay will turn ON/OFF accordingly → controlling the appliance over the Internet.
Output:
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 8
[Link] and Setup Raspberry Pi board and Implementation of LED(s)
Interfacing with raspberry pi.
Raspberry Pi is a compact, single-board computer (SBC) about the size of a credit card,
designed for educational and hobbyist projects. It functions as a complete computer, typically
running a version of the Linux operating system like Raspberry Pi OS. Its most important
feature for electronics projects is the set of
General Purpose Input/Output (GPIO) pins, which allow it to connect to and control
external components like sensors, motors, and LEDs.
Key Components
• System on a Chip (SoC): The "brain" of the Pi, combining the CPU, GPU, and other
controllers into a single power-efficient chip.
• RAM: Volatile memory used to run programs, with capacities ranging from 1GB to 8GB.
• Storage: A microSD card holds the operating system and user files, allowing for easy
swapping and upgrades.
• GPIO Header: A 40-pin header that provides access to power, ground, and data pins for
interfacing with electronics.
• Connectivity: Includes HDMI for displays, connectors for cameras and touchscreens,
USB ports, Ethernet, and built-in Wi-Fi and Bluetooth on newer models.
• Power Input: Typically powered by a 5V supply through a micro-USB or USB-C port.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
2. Circuit Setup The provided code uses GPIO pin 18. You will connect
your LED to this pin.
1. Connect the LED's longer leg (anode) to GPIO 18 on the
Raspberry Pi.
2. Connect the LED's shorter leg (cathode) to a Ground (GND) pin on
the Raspberry Pi.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 9
9. Study of Node-red programming tool.
What is Node-RED?
It's a programming tool used for connecting hardware devices, APIs, and online services.
Key Features:
It offers a browser-based editor for creating "flows" by wiring together a variety of pre-built
nodes.
Flows can be deployed to its runtime with a single click.
It has a lightweight runtime built on [Link], leveraging its event-driven, non-blocking
model.
This makes it suitable for running on low-cost hardware like the Raspberry Pi, as well as in
the cloud.
Its functionality can be extended with over 225,000 modules available in Node's package
repository.
Deployment Options: Node-RED can be run locally, using Docker, on devices (like
Raspberry Pi or BeagleBone Black), or in the cloud (FlowFuse, Amazon Web Services,
Microsoft Azure). It also mentions interacting with Arduino and Android.
Node-RED Architecture
Flow Editor: The browser-based interface where users design flows.
Runtime: The part that executes the flows; it handles communication between nodes.
Nodes: Building blocks of Node-RED that represent various types of logic, hardware, or
services.
Dashboard: An optional feature for creating user interfaces and visualizations for the flows.
Setting up and Using Node-RED
4. Installation and Setup
• System Requirements: [Link], npm, and a supported operating system (Windows,
Linux, macOS).
• Installing Node-RED:
• For Windows: Use the [Link] package (includes npm) to install Node-RED.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Experiment 10
10. Study and implementation of processing data from different
sensors and visualize data on Node-red dashboard.
Required Components
Hardware:
• Raspberry Pi
• LED
• Breadboard
• Jumper Wires
Software:
• Node-RED installed on the Raspberry Pi.
• The node-red-node-pi-gpiod package for GPIO control.
• The node-red-dashboard package for the user interface.
Creating a Test Flow with Inject Nodes
Before building the dashboard, it's good practice to create a simple flow to test
the hardware connection. The image in the practical shows how to do this.
A. Add the "Turn On" Button
1. Drag an inject node onto your workspace.
2. Double-click it, set its Payload to the boolean value true, and give it a
Name like "Turn On".
B. Add the "Turn Off" Button
1. Drag another inject node onto the workspace.
2. Double-click it, set its Payload to boolean false, and give it a Name like
"Turn Off".
C. Add the GPIO Output Node
1. Find and drag an rpi-gpio out node onto the workspace.
2. Double-click it to configure it.
3. Set the Pin to GPIO4 - 7.
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |
ELEMENTS OF INTERNETOF THINGS
202045613
Pushpraj chavda
12302080501048 Page |