Skip to main content

7.7. Smart Weather Station

Under construction
Short example demonstration video

Smart weather station project displays measured data from STHC3 sensor on 16x2 LCD display. Additionaly, it sends the data via POST request on Webhhook.site so you can monitor the data remotely.

At the end of this example you will learn:

  • How to connect SHTC3 sensor and LCD display at once
  • How to display measured data
  • How to upload measured data to internet using POST request
ℹ️

Parts required:

  • Soldered NULA Mini Board
  • Breadboard
  • 16x2 LCD Display
  • SHTC3 temperature and humidity sensor
  • 2 x Qwiic cable

Putting the components together

  • Take a Qwiic cable and connect the LCD to the NULA Mini board, using other Qwiic cable connect the SHTC3 sensor and LCD display
  • Both the sensor and the display have two Qwiic connectors on them, so you can connect them with each other
  • If you are not using the Qwiic connector, manually connect your board using the table below:
NULA MiniSHTC3
VCCVCC
GNDGND
SDAIO3
SCLIO4
Under construction
Components connected together

Code Example

Import necessary libraries.

from machine import Pin, I2C
from LCD import LCD_I2C
from SHTC3 import SHTC3
import network
import urequests
import time

Setup and initialize I2C connection with LCD and SHTC3 sensor. I2C allows the SCL and SDA pins to be shared between devices.

i2c = I2C(0, scl=Pin(7), sda=Pin(6))

lcd = LCD_I2C(i2c)
shtc3 = SHTC3(i2c)

lcd.backlight()
lcd.begin()

This part of code handles WiFi connection with the given ssid and password.

ssid = ""
password = ""

wlan = network.WLAN(network.STA_IF)

wlan.active(True)
wlan.connect(ssid, password)

while wlan.isconnected() == False:
pass

lcd.print("WiFi Connected")

time.sleep(2)
lcd.clear()

Place your Webhook URL here and declare the variable which saves the last time POST request was sent.

WEBHOOK_URL = "https://webhook.site/YOUR-UNIQUE-ID"

last_send_time = 0

Main loop to measure and display values on LCD. Every 10 seconds values are sent via POST request on Webhook URL where they can be examined.

while True:
# Sample values from the sensor
shtc3.sample()

# Read measured values
temperature = shtc3.readTemperature()
humidity = shtc3.readHumidity()

# Print measured data on LCD
lcd.setCursor(0, 0)
lcd.print("Temp: {:.1f} C".format(temperature))
lcd.setCursor(0, 1)
lcd.print("Humidity: {:.2f}%".format(humidity))

# Wait 2 seconds before sampling the values again
time.sleep(2)
lcd.clear()

if time.ticks_diff(time.ticks_ms(), last_send_time) >= 10000:
# Store data in dictionary
data = {
"temperature": temperature,
"humidity": humidity
}
try:
# Make a POST request
response = urequests.post(WEBHOOK_URL, json=data)
response.close()
lcd.print("Data sent!")
time.sleep(1)
lcd.clear()
except Exception as e:
print("Failed to send data:", e)

# Update the last time data was sent
last_send_time = time.ticks_ms()

Full Example

7.7_Smart_Weather_Station.py