Easily Create an IoT App with Blynk and Raspberry Pi Pico W: Step-by-Step Guide

Blynk is an Internet of Things (IoT) platform that allows you to easily build and control connected projects. It provides a simple way to connect hardware devices, such as Arduino, Raspberry Pi, ESP8266, and others, to the internet and control them remotely using a mobile app.

In today’s tutorial, we will be showing how to create a Desktop App using Blynk with the Raspberry Pi Pico W and the BME280 temperature, humidity, and pressure sensor. It is incredibly simple to set up and free to get started, really the only thing you need is an active internet connection, and the same steps can be utilized to set up an IOS or Android app.

Another thing to note is that you do not have to use the BME280 sensor, you can stream any data you like. If you are interested in buying a BME280, you can purchase one from Amazon.

Either way, let’s get into it, but be sure to like, comment, and subscribe to continue to support ShillehTek content!

Step 1-) Setup Blynk Dashboard

  • Create a Blynk account at blynk.io
  • Create a new device on your dashboard as follows:
    • You can select Template > Quickstart Template
    • Save the information they give you, you will need the Auth Key in your MicroPython Code
    • Edit the dashboard from the dropdown
      • Delete the dashboard components and drag and drop three gauges from the Widget Box.
      • Edit the three Widget Boxes respectively with titles Temperature, Humidity, and Pressure. You can create a new Datastream for each one and select a unit and Virtual Pin. I selected virtual pins 7, 8, and 9 respectively for my Gauges. You can alter the max and min values and other properties.
      • That is all you need to get set up for Blynk Dashboard.

        Step 2-) Code Setup

        Now that you have your dashboard set up, you can use the following code on your Pico W to send the information you would like.

        from machine import Pin, I2C
        import network
        import time
        
        from blynklib import Blynk
        import bme280
        
        import constants
        
        
        i2c=I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
        BLYNK = Blynk(constants.BLYNK_AUTH_TOKEN)
        
        
        def connect_to_internet(ssid, password):
            # Pass in string arguments for ssid and password
        
            # Just making our internet connection
            wlan = network.WLAN(network.STA_IF)
            wlan.active(True)
            wlan.connect(ssid, password)
        
            # Wait for connect or fail
            max_wait = 10
            while max_wait > 0:
                if wlan.status() < 0 or wlan.status() >= 3:
                    break
                max_wait -= 1
                print('waiting for connection...')
                time.sleep(1)
            # Handle connection error
            if wlan.status() != 3:
                print(wlan.status())
                raise RuntimeError('network connection failed')
            else:
                print('connected')
                print(wlan.status())
                status = wlan.ifconfig()
        
        
        connect_to_internet(constants.INTERNET_NAME, constants.INTERNET_PASSWORD)
        
        
        while True:
            bme = bme280.BME280(i2c=i2c)
            temperature, pressure, humidity = bme.read_compensated_data()
            # Print sensor data to console
            print('Temperature: {:.1f} C'.format(temperature/100))
            print('Humidity: {:.1f} %'.format(humidity/1024))
            print('Pressure: {:.1f} hPa'.format(pressure/25600))
            BLYNK.virtual_write(7, temperature/100)
            BLYNK.virtual_write(8, humidity/1024)
            BLYNK.virtual_write(9, pressure/25600)
            BLYNK.run()
            time.sleep(1)

        Some notes about the code.

        • You need the Blynk library file in your libs folder on your Pico W. You can find it here -> https://github.com/shillehbean/youtube-channel/blob/main/blynklib.py
        • You can download the micropython bme280 library from the package manager in Thonny if you are using the BME280
        • You will need to replace the virtual pin numbers with the numbers you assigned on Blynk
        • You will also have to replace the values of the constants for the internet name, password, and Blynk auth token
        • We utilize the virtual_write method to send information to the gauges we defined. You can customize these as you like.

           That is the code at a high level, if you have everything set up correctly you should be able to run it with no issues!

          Conclusion

          This is a fantastic way to create simple IoT apps that actually have powerful use cases. The biggest benefit of using this method is that it is so quick to launch an app that many users can begin to use it.

          The drawback is that you will hit a paywall if you actually want to use this for production since there are many useful features that you will want/have to use down the line if you want to scale. However, their pricing is pretty solid. Wish I had a discount to give you!

          Other than that please do not forget to subscribe to ShillehTek on Youtube. Let me know if there are any questions will try my best to help.

          Create a free account to access full content.

          All access to code and resources on ShillehTek.

          Signup Now

          Already a member? Sign In

          Explore More on Our Blog

          How to Use ADS1115 with the Raspberry Pi (Part 1)

          How to Use ADS1115 with the Raspberry Pi (Part 1)

          Discover how to expand your Raspberry Pi projects by integrating the ADS1115 ADC for precise analog signal reading....

          How to Install Pip Packages in AWS Lambda Using Docker and ECR

          How to Install Pip Packages in AWS Lambda Using Docker and ECR

          Learn how to streamline AWS Lambda deployments by using Docker and Amazon Elastic Container Registry (ECR) to package...

          Create Tabular Product Descriptions on Your Shopify Store

          Create Tabular Product Descriptions on Your Shopify Store

          Enhance your Shopify store's product pages with our comprehensive guide on implementing tabular descriptions. Learn how to add a...

          SSH Into Raspberry Pi with Tailscale VPN

          SSH Into Raspberry Pi with Tailscale VPN

          Effortlessly access and manage your Raspberry Pi from anywhere using Tailscale's secure mesh VPN.

          Send Email with Lua and the ESP32

          Send Email with Lua and the ESP32

          In this tutorial, we delve into sending emails with the ESP32-S3 using Lua, focusing on the Xedge IDE's built-in SMTP...

          How to Code with Lua on ESP32 with XEdge32

          How to Code with Lua on ESP32 with XEdge32

          Learn how to set up Xedge32 and start coding on the ESP32-S3 with Lua programming!

          Stream Audio From Raspberry Pi to Local Computer

          Stream Audio From Raspberry Pi to Local Computer

          Discover the simplicity of streaming live audio directly from a USB microphone connected to your Raspberry Pi to...

          SSH Raspberry Pi via Cell Phone

          SSH Raspberry Pi via Cell Phone

          This beginner-friendly guide will walk you through remotely controlling your Raspberry Pi using SSH through your cell phone.

          Remotely Control Raspberry Pi via SSH from External Network

          Remotely Control Raspberry Pi via SSH from External Network

          Learn how to SSH into your Raspberry Pi from any network. This is critical in IoT since you can control...

          Stream Video from Raspberry Pi Camera to YouTube Live

          Stream Video from Raspberry Pi Camera to YouTube Live

          Learn how to stream to YouTube from a Raspberry Pi Camera.

          Back to blog

          Leave a comment

          Please note, comments need to be approved before they are published.