Help for the connection

I had a raspberry pi 3b+ me and I done some code in it for performing some on-off function with the help of an ultrasonic sensor. When distance reading from the ultrasonic sensor comes to a particular point it will perform the on operation and when the distance reading from the ultrasonic sensor comes to a particular point it should come to off state and it works well. Now I want to connect the pi to the Blynk app for controlling the device. The code done in the raspberry pi is python and it works well without Blynk and right now I want to connect to Blynk and I donโ€™t know how to connect the device to Blynk. Can you please help me to solve this problem. Can you please provide the details like how to add the auth token in the pi code and connection code for monitoring through the Blynk app.

Have you read this:


1 Like

Sir this is the code which I used :

import subprocess
import time
GPIO.setup(20,GPIO.OUT)     # Trigger pulse
GPIO.setup(21,[GPIO.IN](      # Echo signal
GPIO.output(20, False)
print "idle"
    GPIO.output(20, True)
    GPIO.output(20, False)
    while GPIO.input(21)==0:                         
        pstart = time.time()
    while GPIO.input(21)==1:
        pend = time.time()
    pduration = pend - pstart
    distance = pduration*17150
    distance = round(distance, 1)
    if distance >= 8:
    if distance <= 4:
    print "Distance:",distance,"cm"
GPIO.cleanup() ```

How should I modify this code to get connected with blynk app, So that I can monitor the 
 reading on blynk app and an ON OFF button on the blynk app for manual on and off.

@123tibinjose please edit your code, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:



Sir, Can you please help me with this code.

Iโ€™m afraid not, it isnโ€™t C++


No, Its Python