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:

Pete.

1 Like

Sir this is the code which I used :

import subprocess
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(20,GPIO.OUT)     # Trigger pulse
GPIO.setup(21,[GPIO.IN](http://gpio.in/))      # Echo signal
GPIO.setup(23,GPIO.OUT)     
GPIO.output(20, False)
print "idle"
time.sleep(2)
while(True):
    GPIO.output(20, True)
    time.sleep(0.00001)
    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:
GPIO.output(23,GPIO.LOW) 
    if distance <= 4:
GPIO.output(23,GPIO.HIGH)
    print "Distance:",distance,"cm"
    time.sleep(1)
    pstart=0
    pend=0
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:
```

Pete.

Done.

Sir, Can you please help me with this code.

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

Pete.

No, Its Python