IOT Lab
IOT Lab
Procedure:
Step 1: Connect the DHT11/DHT22 temperature and humidity sensor to the Raspberry Pi:
Step 5: Write a Python program to read from the DHT sensor and send the data to ThingSpeak.
python dht_thingspeak.py
CODE:
import time
import board
import adafruit_dht
import requests
while True:
try:
temperature = dhtDevice.temperature
humidity = dhtDevice.humidity
print(f"Temp: {temperature}°C Humidity: {humidity}%")
except Exception as e:
print("Error:", e)
Procedure:
● 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 5: Write code to turn ON/OFF the LED based on received Zigbee data.
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() {
void loop() {
if (Serial.available() > 0) {
if (command == '1') {
}
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:
● VCC → 5V
● GND → GND
● TX → RX (Pin 0)
● RX → TX (Pin 1)
● VCC → 5V
● GND → GND
● OUT → A0 (Analog pin)
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:
float temperature;
void setup() {
void loop() {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Procedure:
Step 5: Write a program to check the sensor input and send an SMS when the condition is met.
Step 7: Monitor the GSM module status using serial monitor if needed.
CODE:
#include <SoftwareSerial.h>
void setup() {
pinMode(sensorPin, INPUT);
gsm.begin(9600);
Serial.begin(9600);
delay(1000);
void loop() {
alertSent = true;
if (sensorState == LOW) {
alertSent = false;
delay(1000);
gsm.println("AT+CMGF=1");
delay(1000);
gsm.print("AT+CMGS=\"");
gsm.print(phoneNumber);
gsm.println("\"");
delay(1000);
gsm.println(message);
delay(100);
delay(5000);
Procedure:
Step 4: Write a Python program to read temperature and humidity values from the DHT sensor.
python3 dht_read.py
CODE:
import time
import board
import adafruit_dht
dhtDevice = adafruit_dht.DHT11(board.D4)
while True:
try:
temperature = dhtDevice.temperature
humidity = dhtDevice.humidity
except Exception as e:
time.sleep(2)