Displaying Sensor’s Data on Blynk App Using Raspberry Pi

Now, let's try displaying sensor's data on Blynk app


We go a bit further in Blynk app and Raspberry Pi. Now I will share with you on how to display sensor’s data (in this case I’m using temperature and humidity sensor) on Blynk app.


This video shows how to display sensor’s data on Blynk app using Raspberry Pi and Maker pHAT. For substitle, please click on CC button.


Connection between DHT22 sensor and Raspberry Pi

DHT22 SensorRaspberry Pi

Sample Code

This sample code will read DHT22 sensor and update the readings to Blynk app every ~3 seconds.

from gpiozero import LED, Button, Buzzer
import BlynkLib
import Adafruit_DHT
led1 = LED(17)
led2 = LED(18)
led3 = LED(27)
led4 = LED(22)
led5 = LED(25)
led6 = LED(12)
led7 = LED(13)
led8 = LED(19)
sw1 = Button(21)
buzzer = Buzzer(26)
sensor_type = Adafruit_DHT.DHT22
sensor_pin = 17
BLYNK_AUTH = 'YourAuthToken'
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
# Register Virtual Pins
def my_write_handler(value):
print('Current V1 value: {}'.format(value[0]))
if int(format(value[0])) == 1:
def sw1Pressed():
buzzer.beep(0.1, 0.1, 2)
print('SW1 is pressed')
blynk.notify('SW1 is pressed')
def my_user_task():
humidity, temperature = Adafruit_DHT.read_retry(sensor_type, sensor_pin)
print('Humidity = {:.2f}%\tTemperature = {:.2f}C'.format(humidity, temperature))
blynk.virtual_write(2, '{:.2f}'.format(temperature))
blynk.virtual_write(3, '{:.2f}'.format(humidity))
blynk.set_user_task(my_user_task, 3000)
sw1.when_pressed = sw1Pressed
while True:
except KeyboardInterrupt:
view raw BlynkDHT22.py hosted with ❤ by GitHub

Thank You


  1. blynk-library-python from vshymanskyy
  2. Adafruit_Python_DHT from Adafruit

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

5 thoughts on “Displaying Sensor’s Data on Blynk App Using Raspberry Pi”

  1. Hi affat, you can try edit Adafruit_DHT.DHT22 to Adafruit_DHT.DHT11 in coding. Thanks.

  2. may I know how about dht11? is it the same coding for sample code dht22 but change the type of sensor to dht11?

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 Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
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
Tutorials of Cytron Technologies Scroll to Top