Some links in this post may be affiliate links. We may get paid if you buy something or take an action after clicking one of these, but without addictional costs for you compared to direct buying.

Personal IoT with Blynk and Raspberry PI

3.7
(6)

IoT application are spreading the world to give people control of their home, garden, work and many other applications. IoT apps are ofter linked to products to buy and are strictly connected to products functions. Blynk, together with Raspberry PI, can make their access super simple and efficient

Today I want to show you how to create a flexible IoT solution, fully customizable, with open source Blynk platform and a Raspberry PI Zero W. The same procedure apply also to newer Raspberry PI computer boards.

What Is Blynk

Blynk_widgets

Blynk is an open source IoT platform, hardware agnostic, which enables user to create their own app layout and connect it to its own IoT hardware. It has a really awesome App interface (available both from Google Play and Apple AppStore) with widget based building system. You can create your own layout by simply dragging and dropping available widgets.

It works with and accounting system based on Energy Point. The free version offers an account with 2000 Energy Point which you can spend by adding widgets in your project. Every time you remove a widget, its Energy Point will go back to your Enery Balance.

Blynk is based on a client-server-IoT HW architecture, with Blynk server managing connection and authentication between App and your Hardware.

What We Need

Raspberry PI Zero WH board
Raspberry PI Zero WH board

As usual, I suggest adding from now to your favourite e-commerce shopping cart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from the shopping cart. So, hardware will be only:

Check hardware prices with following links:

Amazon raspberry pi boards box
Amazon raspberry pi Zero W box
Amazon Micro SD box
Amazon Raspberry PI Power Supply box

Step-by-Step Procedure

Blynk supports many hardware languages. In this guide I’ll use Python. This procedure will proceed with following order:

  • Install Blynk app on Smartphone
  • Install Raspberry PI OS Lite on Raspberry PI
  • Install Blynk Python Library on Raspberry PI
  • Configure and run first test

Install Blynk App On Smartphone

This part of procedure follows the official guide available on Blynk docs website.

Install Blynk App in your Smartphone

This step depends on your smartphone Operating System. Use you app store (Google Play for Android or AppStore for iOS) to locate and install Blynk app.

Create a Blynk Account

After Blynk app is installed, you will need to create a new Blynk app account. This account will require a mail to register. This mail will be used later in next steps also to receive authentication token to connect your hardware to your App.

Create a New Project

Blynk app create project button

Once successfully logged in, create a new project.

Choose Generic Device Hardware

Use Generic Hardware in next screen. Raspberry Pi is supported by Blynk, but only models A/B are listed. If you are using one of these, of course, use the proper model. You will be warned that your authentication token connected to this project has been sent to registration mail. This code will be used later in our Python code. After confirmaton, screen will switch to a new empty project:

Insert Your First Widget

Tap the button with cross on top-left. Your widget box will show a list of available widgets with their Energy costs. Your Energy Balance will be showed too. Tap on “Value Display” widget to have it inserted in you layout.

PS: You can remove at any time this widget and Energy Points will be given back to your Energy Balance.

Configure Your Widget

Tap on your widget, so that you will go on widget setting configuration. For our test, we’ll use as INPUT a Virtual PIN number 2, with Reading rate 1 second. So, tap on “PIN” and select “Virtual” -> “V2” -> “Ok”. Then, inder “Reading Rate” substitute default “Push” with “1 sec”.

New Project Configuration Completed

Blynk app 9 new project ready

Value Display widget can also be enlarged by keeping it pressed and releasing. This way will enable users to see larger info inside the widget, like we’ll see in following example.

Our New Project configuration on Blynk app ended. Now we’ll move on Raspberry PI

Install Operating System on Raspberry PI

Please refer to Install Raspberry PI OS Lite in your Raspberry PI – Guide for OS installation. We’ll configure Raspberry PI from remote with SSH terminal shell.

Be sure your OS is up to date. From terminal:

sudo apt update && sudo apt upgrade

Install Blynk Python Library on Raspberry PI

Python is pre-installed in Raspberry PI OS Lite, as you can verify by typing:

pi@raspberrypi:~ $ python --version
Python 2.7.16

We’ll need pip package to install blynk. Use the following command:

sudo apt install python-pip

Install blynk library for Python:

pip install blynk-library-python

Write your first Blink test code. Create a new file:

nano myBlynkTest.py

Insert the following code, taking care on using the token you received by mail from Blynk when:

import BlynkLib
from datetime import datetime
# Initialize Blynk
blynk = BlynkLib.Blynk('YOUR-TOKEN')

# Register Virtual Pin
@blynk.VIRTUAL_READ(2)
def my_read_handler():
     currentTime = datetime.now()
     blynk.virtual_write(2, currentTime.strftime("%d/%m/%Y %H:%M:%S"))

print("started!")
while True:
    blynk.run()

Finally execute this script:

python myBlynkTest.py

Swith back to Blynk app in your SmartPhone and press the Play button:

Blynk app 9 1 run new project

You should now see in your widget current date and time.

Enjoy!

How useful was this post?

Click on a star to rate it anonymously!

Average rating 3.7 / 5. Vote count: 6

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

14 comments

  1. Hello, I’ve been tasked to replicate and improve your Project regarding “WEATHER STATION WITH ARDUINO, BLYNK AND RASPBERRY PI OS LITE ON RASPBERRY PI ZERO W” but i’ve encoutnered mutiple errors, afew of them being
    1. Traceback (most recent call last): import Blynklib
    2. module = self._original_import(*args, **kw)
    ModuleNotFoundError: No module named ‘BlynkLib’
    I have been struggling with this issue and i hope you will be able to hhelp

  2. I have afew errors and im still fairly new to raspberry but for a project i had to replicate and improve your weather station raspberry project
    1. Traceback (most recent call last): import BlynkLib
    2.module = self._orginal_import(*args, **kw)
    ModuleNotFoundError: No module name ‘BlynkLib’

  3. My project is due in afew days, im hoping that if you are free you could help. But do no fret afterall this is my issue, Do enjoy your vacation have a wonderful time

        1. Ok, this is a good news as Blynk seems correctly installed.
          Now, do you use “python myBlynkTest.py” command or “python3 myBlynkTest.py”? The first one is the correct

          1. i used the command python myBlynkTest.py as per your guide and it shows the “BLYNK for python V0.2.0 (Linux) Started!’
            but it says Invalid auth token rigth after

          2. I know you are on vacation and i really hope i am not troubling you to much, but is there any way to better contact you besides using this comment area. Im still a student and completly new to raspberry pi and blynk. So thank you for your help

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy