Induja Lab IOT t3
Induja Lab IOT t3
21BEC0316
INTERNET OF THINGS ANALYST LAB
TASK 3
1. Hello World Program in RPI (BLINK a LED at any of the GPIO pin)
Aim:
To blink LED using raspberry pi
Materials Required:
• Raspberry Pi board
• Bread Board
• Male to Female wires
• Mouse
• Keyboard
• HDMI Cable
• Monitor
• LED
Circuit Connections:
Procedure:
• Insert the Memory card in the board
• Make the circuit connections using the wires, bread board and the raspberry
pi board.
• And connect the mouse and the Keyboard using the USB ports
• And also connect to the monitor using the HDMI cable.
• Type the code in Thonny ide
• And simulate the code
Code:
Output:
Inference:
Based on the procedure provided, it can be inferred that when the pin connected
to the LED is set to a low state (not put to sleep) in the code, the LED remains
off. Conversely, when the pin connected is set to high in the code, the LED is
turned on. This indicates that the state of the pin directly controls the behavior of
the LED, where a low state corresponds to the LED being off, and a high state
corresponds to the LED being on.
Result:
Hence we’ve made the LED to blink continuously for infinite time until the code is
forcefully stopped.
Code:
Output:
Inference:
Based on the provided information, it can be inferred that when the sensor detects
an object near it, it prints "Detected" as the output. Conversely, when nothing is
detected, it prints "Not Detected". The status is updated every 5 seconds, suggesting
that the system continuously monitors its surroundings for the presence of objects or
organisms nearby. This functionality enables the system to serve as a detection
mechanism, alerting users to the presence or absence of objects in its vicinity.
Result:
Exactly, by implementing the described procedure and inference, a practical
detection system has been created. This system effectively detects the presence or
absence of objects nearby and provides real-time feedback through the shell,
informing users promptly whenever an object is detected or not. Such a system can
have various applications, including security, automation, and environmental
monitoring.
3. Interface IR sensor and send data to thingspeak if detected and 0 if not
detected
Aim:
To interface IR sensor and send data to thingspeak if detected and 0 if not detected
Materials Required:
• Raspberry Pi board
• Bread Board
• Male to Female wires
• Mouse
• Keyboard
• HDMI Cable
• Monitor
• IR sensor
• Thingspeak account
Circuit Connections:
Procedure:
• Insert the Memory card in the board
• Make the circuit connections using the wires, bread board and the raspberry
pi board as per the circuit connections.
• And connect the mouse and the Keyboard using the USB ports
• And also connect to the monitor using the HDMI cable.
• Type the code in Thonny ide
• And simulate the code
Code:
Output:
Inference:
Moving a step further from the previous process, we have enhanced the functionality
by uploading the data to the cloud platform ThingSpeak. By utilizing the API key, we
have established a connection between the Raspberry Pi and ThingSpeak. Now, the
data from the sensor is not only displayed in the shell but also sent to the cloud,
where it is stored and visualized in the form of a graph. This integration allows for
convenient access to the data at any time and enables further analysis and
monitoring of the detected objects or organisms over time.
Results:
With this enhancement, we have developed a robust detection system capable of
communicating information through the shell interface while also storing the data in
the cloud using platforms like ThingSpeak. This integration not only provides real-
time feedback but also ensures that the data is securely stored and accessible for
future analysis or reference. Overall, this system offers a comprehensive solution for
object detection and data management, with potential applications in various fields
such as environmental monitoring, security, and automation.
4. Interface dht11 sensor and display temperature and humidity.
Aim:
To interface dht11 sensor and display temperature and humidity.
Materials Required:
• Raspberry Pi board
• Bread Board
• Male to Female wires
• Mouse
• Keyboard
• HDMI Cable
• Monitor
• IR sensor
• Thingspeak account
Circuit Connections:
Procedure:
• Insert the Memory card in the board
• Make the circuit connections using the wires, bread board and the raspberry
pi board as per the circuit connections.
• And connect the mouse and the Keyboard using the USB ports
• And also connect to the monitor using the HDMI cable.
• Install the dht11 module
• Type the code
• And simulate the code
Hardware Setup:
VCC TO RPI 5V (PIN No: 2) 5V PWR
GND TO RPI (PIN No: 6)
OUT TO RPI (PIN No: 7) –GPIO 4
Software Setup:
sudo apt update
sudo apt upgrade –y
sudo apt install python3 python3-pip python3-venv
mkdir ~/dht11
-After creating the directory,
cd ~/dht11
-rerun this command whenever you want to use this Python script to interact with
your DHT11 sensor.
source env/bin/activate
nano dht11.py
Code:
Python3 dht11.py ------ to run the code
5. Interface dht11 sensor and display temperature and humidity and push both
to thingspeak cloud
Aim:
To interface dht11 sensor and display temperature and humidity and push both to
thingspeak cloud.
Materials Required:
• Raspberry Pi board
• Bread Board
• Male to Female wires
• Mouse
• Keyboard
• HDMI Cable
• Monitor
• IR sensor
• Thingspeak account
Circuit Connections:
Procedure:
• Insert the Memory card in the board
• Make the circuit connections using the wires, bread board and the raspberry
pi board as per the circuit connections.
• And connect the mouse and the Keyboard using the USB ports
• And also connect to the monitor using the HDMI cable.
• Install the dht11 module
• Type the code
• And simulate the code
Hardware setup:
VCC TO RPI 5V (PIN No: 2) 5V PWR
GND TO RPI (PIN No: 6)
OUT TO RPI (PIN No: 7) –GPIO 4
Software setup:
- Create a Python script to read data from the sensor and push it to ThingSpeak.
import time
import Adafruit_DHT
import urllib.request
import urllib.parse
url = 'https://api.thingspeak.com/update'
api_key = 'YOUR_API_KEY_HERE'
sensor = Adafruit_DHT.DHT11
pin = 4
def read_sensor_data():
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
return humidity, temperature
def send_to_thingspeak(humidity, temperature):
data = {'api_key': api_key, 'field1': temperature, 'field2': humidity}
encoded_data = urllib.parse.urlencode(data).encode('utf-8')
urllib.request.urlopen(url, data=encoded_data)
while True:
humidity, temperature = read_sensor_data()
if humidity is not None and temperature is not None:
send_to_thingspeak(humidity, temperature)
print(f'Temperature: {temperature}°C, Humidity: {humidity}%')
else:
print('Failed to retrieve data from sensor')
time.sleep(15)
-This script reads data from the DHT11 sensor every 15 seconds and sends it to
ThingSpeak.