Python code for light intensity system

Please help me out why the buzzer is not working in the if else when implemented
here the connections are good as the buzzer is working if I write the code outside the if else
hlp

You are declaring test = bolt.digitalWrite('0','HIGH') but not calling it.

Add the print statement alongwith.

test = bolt.digitalWrite('0','HIGH')
print (test)

Can you try and revert if your buzzer runs now?

I may have spotted a mistake

The sensor value ie sens can’t be both less than 100 and greater than 120

1 Like

@mohatapriya yes you found it. @shubham11gupta10 your condition will not ever evaluate to True. Correct the condition and also there is no point of storing the GPIO commands in a variable because you have to execute the same whenever the condition is reached.

So do the following changes:

  1. Correct the condition. I think you want to run the of block when the temp value is in between 100 and 120. So you should write like this: if sens<100 or sens>120
  2. Use this syntax:

bolt.digitalWrite(‘0’,‘HIGH’)