Exp 9 Log Data Using Raspberry Pi and Upload It To Cloud Platform

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

EXP NO: LOG DATA USING RASPBERRY PI AND

DATE: UPLOAD TO THE 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:

1. *Processor:* It is powered by a 1.4 GHz 64-bit quad-core ARM Cortex-


A53 CPU.

2. *Memory:* It comes with 1GB LPDDR2 SDRAM.


3. *Connectivity:* The Raspberry Pi 3B+ has built-in dual-band 2.4 GHz
and 5 GHz IEEE 802.11.b/g/n/ac wireless LAN and Bluetooth 4.2/BLE,
making it easier to connect to Wi-Fi networks and Bluetooth devices.

4. *Ethernet:* It includes a Gigabit Ethernet port for wired network


connectivity.

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.

7. *Video Output:* It supports HDMI output for connecting to displays, as


well as composite video via a 3.5mm TRRS jack.

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.

9. *Operating System:* It can run various operating systems, including


Raspbian (a Debian-based Linux distribution optimized for the Raspberry
Pi), Ubuntu, and others.

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:

*Principle of Operation:* Ultrasonic sensors operate based on the principle


of echo detection. They emit ultrasonic waves and then measure the time it
takes for the waves to bounce off an object and return to the sensor. This
information is used to calculate the distance to the object.
THINGSPEAK CLOUD PLATFORM:

ThingSpeak is an Internet of Things (IoT) analytics platform developed by


MathWorks, the company behind MATLAB and Simulink.
1.Data Collection
2.Channels
3.Visualization
4.Data Analysis
5.Integration
6.Open Platform
7.Education and Research

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()

#copy each and every required syntax mentioned below


SYNTAX FOR PROGRAM:

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).

5.Make sure to use a resistor (typically around 330 ohms) to create a


voltage divider between the Echo pin of the ultrasonic sensor and the GPIO
pin of the Raspberry Pi.

2.Procedure for compling a Thonny IDE Script


3.Procedure for Creating a Channel in
ThingSpeak;
RESULT:
Thus, above experiment of Log Data using Rapberry Pi and
Upload to the Cloud Platform was designed executed and
uploaded successfully.

You might also like