About a project

I want the buzzer to beep whenever the threshold value crosses in terms of light or temp , so how could I do this?

Connect your buzzer on pin 0. And use the below python script to trigger that pin when conditions met.

from boltiot import Bolt
import json, time

minimum_limit = 300
maximum_limit = 600  

API_KEY="XXXXXXXXXXXXXXXXXXXXXXXXX"
DEVICE_ID = "BOLTXXXXXX"

mybolt = Bolt(API_KEY, DEVICE_ID)  

while True: 
        print ("Reading sensor value")
        response = mybolt.analogRead('A0') 
        data = json.loads(response) 
        print("Sensor value is: " + str(data['value']))
        try: 
            sensor_value = int(data['value']) 
            if sensor_value > maximum_limit or sensor_value < minimum_limit:
                mybolt.digitalWrite('0','HIGH')
        except Exception as e: 
            print ("Error occured: Below are the details")
            print (e)
        time.sleep(10)

But I also have to connect the ldr or temp resister with the wifi module so how the connection should be ?

Module has only one analog pin, i.e. A0. I have mentioned that pin in the code.

If you are asking about the connection,
For LDR - https://trainings.boltiot.com/courses/429176/lectures/6647171

For LM35 - https://trainings.boltiot.com/courses/429176/lectures/6656669

I want to say that there is one A0 pin and that one will be occupied by ldr or lm35 then how would I connect the buzzer with it?

@rishidutta795 you need the A0 pin (that is the analog pin) when you want to get the input from a sensor. That is why one must connect AO pin with LM35 sensor so that you can get the temperature value of your surroundings. In short we can conclude that AO pin is for input devices

Whereas buzzer is an output device so there is no point of connecting it to A0 pin. On the other end you have to connect the long leg of Buzzer, to any one of the 05 GPIO pins ( GPIO 0 to 4), and the short leg to the GND pin. And you can set the value of the buzzer either digitally or via analog way. Say you have connected the buzzer to GPIO 0 pin then:
Digital way: mybolt.digitalWrite(‘0’,‘High’)
Analog way: mybolt.analogWrite(‘0’,250)
Note : In the analog way you can give a numerical value of 0 to 255. O corresponds to Low/off while 255 corresponds to High/On

I hope you get the crux :slight_smile:

GND is also occupied by ldr or lm35 so how do I insert the leg of the buzzer?

@rishidutta795 you can use the breadboard for doing the same. Insert the GND pin from the Bolt molule to one of the pins of the breadboard using the male to female wires and then you can use those 05 ports of the breadboard as the GND port and then connect accordingly.

image
Say the pin which you see in the image is of the GND pin from the Bolt Module and then the rest 04 pins of the same line will be having GND in them. SO you can connect those with any of the sensor you want. I hope you understand :slight_smile:

1 Like

yes thats exactly what I want to know.

1 Like

Refer below connection

1 Like

So do close the query of its resolved by clicking on the solution button on the post :slight_smile: