IR Sensor not giving Output

Hey,
So I’ve been trying to use the IR sensor for my project. I’ve read the previous topics and tried the solutions but still no luck.


This is my IR connection and the code that I’ve tried for it on Putty. I’ve connected the signal pin of the IR to the digital pin 2 on the bolt module and tried it out. The IR detects an obstacle but i guess the bolt doesn’t read it.
No matter what i try the program always reads the else loop and gives me just that output. If i remove the else loop there’s no output at all. Even if there’s nothing in front of the sensor and the obstacle light doesn’t glow it gives me output saying that “something passed”
I’d really appreciate any help on this matter.

hey, have you tried to adjust the potentiometer above the IR sensor. May be that is not calibrated which results in inacurate result.
and also debug the program what is the detection value provided by the bolt check if it is numeric or string may be the value issue.put print statement after fetching data variable.

if that doesn’t work, once try with A0 pin.

@solankiuday1
Hey, I’ve tried calibrating the potentiometer and changing the program but no luck. Still getting the same issue.
How can i try with A0, the value from the IR is digital right?? Just a high and low??

Hi @joshua.rebello2424,

Your code is incorrect.

  1. import the json library in your code
  2. Read the response and parse it into json and get the value.
response = mybolt.digitalRead(2)
parsed_response = json.lodas(response) 
# {"success": "1", "value": "1"} 
detection = int(parsed_response["value"])
  1. detection value will be either 0 or 1 so change in your while loop.
while True:
    if detection == 1:
        print ("Somthing detected")
    else:
        print ("Nothing detected")
    time.sleep(10)
1 Like

@rahul.singh1
Hey, thanks for the code but still no luck. It still continuously gives only “Something Detected” as the output. I honestly think it’s not reading my bolt, cause even if my bolt is not connected or there is no power supplied to the bolt, the program still runs and gives output as “something Detected”.
But my bolt is connected and I’ve checked the API and BoltID, they’re correct.

Hi @joshua.rebello2424,

Because you are reading the value only for a single time and your while loop keep showing the same message. Do the digitalRead inside the while loop.

while True:
    response = mybolt.digitalRead(2)
    parsed_response = json.loads(response) 
    print ("Parsed response is")
    print (parsed_response)
    # {"success": "1", "value": "1"} 
    detection = int(parsed_response["value"])
    if detection == 1:
        print ("Somthing detected")
    else:
        print ("Nothing detected")
    time.sleep(10)
1 Like

@rahul.singh1
Hey Thanks, it works now.

@rahul.singh1
Hey, before I forget could you tell me why the program didn’t work without json?? I know JSON is used for communication between data and the processor but could you explain in simpler terms like why was it important here??
And another thing, I’m using the linux command line for my python programming. To use telegram from the linux command line do i need to import the bolt library or will it work without the bolt library also?? Is the Bolt library necessary here to use the telegram API??
And for Telegram if i want to send pictures through my bot to the channel. what do i have to do??