Introduction: Raspberry Pi Pico 2W + Mobile App: Build Your Own Smart Wi-Fi Thermometer!

Have you ever wanted to easily monitor the temperature in every room of your house? The good news is that you can do it effortlessly for under ten dollars!



Supplies

Step 1: Connect Temperature Sensor to PICO

Connect DS18B20 to the Raspberry PI Pico according to schema using a resistor between Red and Yellow wire.

Step 2: Set Up Visual Studio Code

  1. Install Visual Studio Code
  2. Open Settings -> Extensions
  3. Install Python, Raspberry PI Pico, MicroPico

Step 3: Connect to the Raspberry PI

  1. Open View -> Command Pallete
  2. Search for MicroPico: Connect
  3. Create a file main.py
  4. Add a line print("Hello") to the main.py
  5. When Pico connects, run All Commands -> Upload Project
  6. Press "Run"

Step 4: Clone a Raspberry PI Pico Framework

Run:

git init
git submodule add https://github.com/Nerdy-Things/itk_pico.git

Step 5: Broadcast Temperature to the Wi-Fi Network

Replace code in the main.py with:

from itk_pico.temperature import TemperatureSensor
from itk_pico.wifi import WiFi
from itk_pico.udp import Udp
from itk_pico.ip_utils import get_broadcast_address
from time import sleep
import json

UDP_PORT = 5468

temperature_sensor = TemperatureSensor(15)

wifi = WiFi()
udp = Udp(UDP_PORT)

wifi.connect("itkacher", "itkacher")

while True:
wifi.try_reconnect_if_lost()
temperature = temperature_sensor.get_temperature()
broadcast_ip_address = get_broadcast_address(wifi.get_ip_address(), wifi.get_subnet_mask())
message_dict = {"name": "Kitchen", "temperature": temperature}
message = json.dumps(message_dict)
udp.send(message, broadcast_ip_address, UDP_PORT)
sleep(10)

Upload the project to the Raspberry PI Pico 2W and press Run

Step 6: Clone a Cross-platform Application

git clone https://github.com/Nerdy-Things/raspberry-pi-pico-thermo-sensor-cross-platform.git

Step 7: Run the Application

To run a desktop application:

cd raspberry-pi-pico-thermo-sensor-cross-platform
cd kotlin-multiplatform
./gradlew run

To run an Android application:

Open the raspberry-pi-pico-thermo-sensor-cross-platform/kotlin-multiplatform folder in Android Studio. Press Run.

To run an iPhone application:

Open the iosApp/iosApp.xcodeprojfile in xCode. Press Run.