0% found this document useful (0 votes)
4 views9 pages

IOT Lab

The document outlines five experiments involving Raspberry Pi, Arduino, and various sensors/modules. Experiment 1 details how to measure temperature using a DHT sensor with Raspberry Pi and send data to ThingSpeak. Subsequent experiments cover controlling an LED with Zigbee, establishing Bluetooth communication for sensor data transmission, sending SMS alerts via a GSM module, and interfacing a DHT sensor with Raspberry Pi to read temperature and humidity values.

Uploaded by

roshauninfant
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)
4 views9 pages

IOT Lab

The document outlines five experiments involving Raspberry Pi, Arduino, and various sensors/modules. Experiment 1 details how to measure temperature using a DHT sensor with Raspberry Pi and send data to ThingSpeak. Subsequent experiments cover controlling an LED with Zigbee, establishing Bluetooth communication for sensor data transmission, sending SMS alerts via a GSM module, and interfacing a DHT sensor with Raspberry Pi to read temperature and humidity values.

Uploaded by

roshauninfant
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/ 9

Experiment 1: Design an experiment to measure temperature using a

temperature sensor with Raspberry Pi and send the data to ThingSpeak

Procedure:

Step 1: Connect the DHT11/DHT22 temperature and humidity sensor to the Raspberry Pi:

●​ VCC → 3.3V (Pin 1)


●​ GND → GND (Pin 6)
●​ DATA → GPIO4 (Pin 7)

Step 2: Power on your Raspberry Pi and ensure it has internet access.

Step 3: Create a ThingSpeak account at https://thingspeak.com, and create a new channel.​


Note the Write API Key from the API Keys tab.

Step 4: Create a Python file named dht_thingspeak.py.

Step 5: Write a Python program to read from the DHT sensor and send the data to ThingSpeak.

Step 6: Save and run the Python script:

python dht_thingspeak.py

CODE:
import time
import board
import adafruit_dht
import requests

# Set up DHT sensor on GPIO4


dhtDevice = adafruit_dht.DHT11(board.D4)

# Your ThingSpeak API key


THINGSPEAK_API_KEY = "YOUR_API_KEY_HERE"
# ThingSpeak URL
url = "https://api.thingspeak.com/update"

while True:
try:
temperature = dhtDevice.temperature
humidity = dhtDevice.humidity
print(f"Temp: {temperature}°C Humidity: {humidity}%")

# Send data to ThingSpeak


response = requests.get(url, params={
'api_key': THINGSPEAK_API_KEY,
'field1': temperature,
'field2': humidity
})
print(f"Data sent to ThingSpeak: {response.status_code}")

except Exception as e:
print("Error:", e)

time.sleep(20) # ThingSpeak allows updates every 15 sec (min)

Experiment 2: Design an experiment to control an LED connected to


Arduino remotely via Zigbee

Procedure:

Step 1: Connect an LED to Arduino:

●​ Positive (Anode) → Digital Pin 13 (through 220Ω resistor)


●​ Negative (Cathode) → GND

Step 2: Connect a Zigbee (XBee) module to the Arduino:

●​ VCC → 3.3V
●​ GND → GND
●​ TX of XBee → RX (Pin 0) of Arduino
●​ RX of XBee → TX (Pin 1) of Arduino​
(Note: Use a voltage divider for RX pin if using a 5V Arduino with 3.3V Zigbee)
Step 3: Insert another Zigbee module in a USB adapter and plug it into your PC for sending
commands.

Step 4: Open Arduino IDE and create a new sketch.

Step 5: Write code to turn ON/OFF the LED based on received Zigbee data.

Step 6: Upload the code to the Arduino board.

Step 7: Use a serial terminal on your PC to send '1' to turn ON and '0' to turn OFF the LED.

CODE:

void setup() {

Serial.begin(9600); // Initialize serial communication

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

void loop() {

if (Serial.available() > 0) {

char command = Serial.read(); // Read command from Zigbee

if (command == '1') {

digitalWrite(13, HIGH); // Turn ON LED

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

digitalWrite(13, LOW); // Turn OFF LED

}
Experiment 3: Establish a Bluetooth connection between Arduino and a
smartphone. Send sensor data from Arduino to the smartphone via
Bluetooth and display it on a mobile app.

Procedure:

Step 1: Connect an HC-05 Bluetooth module to the Arduino:

●​ VCC → 5V
●​ GND → GND
●​ TX → RX (Pin 0)
●​ RX → TX (Pin 1)

Step 2: Connect a sensor (e.g., DHT temperature sensor):

●​ VCC → 5V
●​ GND → GND
●​ OUT → A0 (Analog pin)

Step 3: Open Arduino IDE and create a new sketch.

Step 4: Write a program to read sensor data and send it via Serial (Bluetooth).

Step 5: Upload the code to Arduino (disconnect RX/TX wires before uploading and
reconnect after upload).

Step 6: Pair the HC-05 with your smartphone via Bluetooth settings. Default password is
usually 1234 or 0000.

Step 7: Install a serial Bluetooth app like “Serial Bluetooth Terminal” or “Bluetooth Terminal
HC-05” from Play Store.

Step 8: Open the app, connect to HC-05, and view the incoming sensor data.

CODE:

const int sensorPin = A0; // LM35 connected to A0

float temperature;
void setup() {

Serial.begin(9600); // Start serial communication (Bluetooth)

void loop() {

int sensorValue = analogRead(sensorPin); // Read analog value

temperature = (sensorValue * 5.0 * 100) / 1024; // Convert to °C

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.println(" °C");

delay(2000); // Wait 2 seconds before next reading

Experiment 4: Design a system using Arduino and a GSM module to send


an SMS alert when a sensor detects a predefined event

Procedure:

Step 1: Connect a GSM module (SIM800L/SIM900) to the Arduino:

●​ GSM RX → Arduino Pin 10


●​ GSM TX → Arduino Pin 9
●​ GND → GND
●​ VCC → 12V external power supply (not from Arduino)

Step 2: Connect a sensor (e.g., a push button or motion sensor):


●​ Sensor OUT → Arduino Pin 2
●​ VCC → 5V
●​ GND → GND

Step 3: Insert a SIM card into the GSM module.

Step 4: Open Arduino IDE and include the SoftwareSerial library.

Step 5: Write a program to check the sensor input and send an SMS when the condition is met.

Step 6: Upload the code to the Arduino.

Step 7: Monitor the GSM module status using serial monitor if needed.

CODE:

#include <SoftwareSerial.h>

SoftwareSerial gsm(9, 10); // RX, TX for GSM

const int sensorPin = 2; // Sensor connected to pin 2

bool alertSent = false;

void setup() {

pinMode(sensorPin, INPUT);

gsm.begin(9600);

Serial.begin(9600);

delay(1000);

void loop() {

int sensorState = digitalRead(sensorPin);


if (sensorState == HIGH && !alertSent) {

sendSMS("+910000000000", "Alert: Sensor triggered!");

alertSent = true;

if (sensorState == LOW) {

alertSent = false;

delay(1000);

void sendSMS(const char* phoneNumber, const char* message) {

gsm.println("AT+CMGF=1");

delay(1000);

gsm.print("AT+CMGS=\"");

gsm.print(phoneNumber);

gsm.println("\"");

delay(1000);

gsm.println(message);

delay(100);

gsm.write(26); // ASCII code of CTRL+Z to send message

delay(5000);

Great! Here's Experiment 5:


Experiment 5: Design an experiment to interface a temperature sensor
(DHT11/22) with Raspberry Pi

Procedure:

Step 1: Connect the DHT11 or DHT22 sensor to the Raspberry Pi:

●​ VCC → 3.3V (Pin 1)


●​ GND → GND (Pin 6)
●​ DATA → GPIO4 (Pin 7)
●​ Add a 10kΩ pull-up resistor between VCC and DATA

Step 2: Power on the Raspberry Pi and open the terminal.

Step 3: Create a new Python script named dht_read.py.

Step 4: Write a Python program to read temperature and humidity values from the DHT sensor.

Step 5: Save and run the script:

python3 dht_read.py

CODE:

import time

import board

import adafruit_dht

# Initialize the DHT device on GPIO4

dhtDevice = adafruit_dht.DHT11(board.D4)
while True:

try:

temperature = dhtDevice.temperature

humidity = dhtDevice.humidity

print(f"Temperature: {temperature}°C Humidity: {humidity}%")

except Exception as e:

print("Sensor read error:", e)

time.sleep(2)

You might also like