Exp 9 Log Data Using Raspberry Pi and Upload It To Cloud Platform
Exp 9 Log Data Using Raspberry Pi and Upload It To Cloud Platform
AIM:
To Write, Develop and Execute the program for Logging the Data
using Raspberry PI3 model B+ and upload it to any of the Cloud
Platform (Thingspeak Cloud Platform).
APPARATUS REQUIRED:
Hardware and Software Tools:
S.NO COMPONENTS OF RANGE QUANTITY
HARDWARE and SOFTWARE
1. Raspberry PI3 Model B+ - 1
2. ULTRASONIC SENSOR HC-SR04 1
3. BREAD BOARD - 1
4. SD CARD AND 32 GB 1
MICRO USB CABLE - 1
5. HDMI TO VGA CABLE - 1
6. THONNY IDE AND THINGSPEAK - -
CLOUD
7. JUMBER WIRES - As Required
THEORY:
The Raspberry Pi 3 Model B+ is a single-board computer developed by the
Raspberry Pi Foundation. Here are some key features and specifications:
5. *USB Ports:* There are four USB 2.0 ports for connecting peripherals
such as keyboards, mice, and USB drives.
6. *GPIO Pins:* The 40-pin GPIO header allows for interfacing with
various sensors, displays, and other external devices.
8. *Power:* The Raspberry Pi 3B+ can be powered via a micro USB port
or GPIO header, with a recommended power supply of 5V and at least
2.5A.
10. *Form Factor:* The Raspberry Pi 3B+ is in the same form factor as its
predecessor, the Raspberry Pi 3 Model B, with dimensions of
approximately 85.6mm x 56.5mm x 17mm.
ULTRASONIC SENSOR:
An ultrasonic sensor is a device that emits high-frequency sound waves
(ultrasonic waves) and detects the echoes reflected off nearby objects. Here
are some key points about ultrasonic sensors:
PIN DIAGRAM:
CIRCUIT DIAGRAMS:
PROGRAM:
import RPi.GPIO as GPIO #import python from GPIO library
GPIO.setwarnings(False)
#import time library to make raspberry pi to wait between steps
import time
#import requests is used for making HTTP requests
import requests
api_key = 'DK26EZ3M1X5SWN97'
url = 'https://api.thingspeak.com/update'
TRIG=11
ECHO=13
def setup_ultrasonic_sensor():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
def measure_distance():
GPIO.output(TRIG, False)
time.sleep(0.2)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
pulse_start=time.time()
while GPIO.input(ECHO)==0:
pulse_start=time.time()
pulse_end=time.time()
while GPIO.input(ECHO)==1:
pulse_end=time.time()
pulse_duration=pulse_end-pulse_start
distance=pulse_duration*17150
distance=round(distance,2)
return distance
def send_to_thingspeak(distance):
payload = {'api_key': api_key, 'field1': distance}
response = requests.get(url, params=payload)
print(response.text)
try:
setup_ultrasonic_sensor()
while True:
distance=measure_distance()
print("Distance:",distance,"cm")
send_to_thingspeak(distance)
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
PROCEDURE:
1.Procedure for interfacing raspberry pi3
model B+ with ultrasonic sensor ;
Here's how to connect it:
1.- *VCC (5V)* pin of the ultrasonic sensor to any 5V pin on the Raspberry
Pi (like Pin 2 or 4).
2.- *GND* pin of the ultrasonic sensor to any ground (GND) pin on the
Raspberry Pi (like Pin 6, 9, 14, 20, 25, 30, 34, or 39).
3.- *TRIG* (Trigger) pin of the ultrasonic sensor to a GPIO pin on the
Raspberry Pi (like GPIO 23, GPIO 24, or any other GPIO pin).
4.- *ECHO* pin of the ultrasonic sensor to another GPIO pin on the
Raspberry Pi (different from the TRIG pin).