Log Sensor Data from Sense HAT to Google Sheets using Raspberry Pi

The easy way to log your data to Google Sheets!

Introduction

I have shared before about IoT data logger using Blynk app. This time, we will try to log the data to Google Sheets – a spreadsheet program included as part of a free, web-based software office suite offered by Google. The sensor data will be collected from Sense HAT which include temperature, humidity, pressure, accelerometer, gyroscope and magnetometer. I like the easy way, so we will use the Integromat services to link between them and reduce the lines of code.

Video

This video shows how to log sensor data from Sense HAT to Google Sheets using Raspberry Pi.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is python3 sample program. You can use it with Thonny Python IDE.

from sense_hat import SenseHat
from time import time
import datetime
import requests
sense = SenseHat()
sense.clear()
send = False
interval = 60 # 1 minute
prevSec = 0
print("Send sensor data from Sense HAT to Google Sheets using Raspberry Pi")
print()
while True:
for event in sense.stick.get_events():
if event.direction == "left":
send = False
sense.show_letter("0", text_colour=(100,0,0))
print("Stop!")
print()
if event.direction == "right":
send = True
sense.show_letter("1", text_colour=(0,100,0))
print("Sending data…")
print()
if send == True:
if time() prevSec > interval:
prevSec = time()
data_to_send = {}
data_to_send["date"] = str(datetime.datetime.now())
data_to_send["temperature"] = sense.get_temperature()
data_to_send["humidity"] = sense.get_humidity()
data_to_send["pressure"] = sense.get_pressure()
data_to_send["accelerometer"] = sense.get_accelerometer_raw()
data_to_send["gyroscope"] = sense.get_gyroscope_raw()
data_to_send["magnetometer"] = sense.get_compass()
print("JSON data:")
print(data_to_send)
# Replace your webhook URL here
r = requests.post("https://your.webhook.url", json = data_to_send)
print(r.status_code)
print()

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

1 thought on “Log Sensor Data from Sense HAT to Google Sheets using Raspberry Pi”

  1. Hi, i want to ask about this project.. this project always need to connect with usb mouse, keyboard (laptop) or what? Can it operate wireless?? I mean, can i put it on my robot car (moving around freely) and collate the data wireless without need to connect it with usb to laptop???

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
DIY Automated Vacuum Cleaner Using REKA:BIT With Micro:bit
Rainbow Spark in Mini House using Maker Uno.
Tutorials of Cytron Technologies Scroll to Top