How to trigger buzzer inside the Telegram Alert Code

I would like to know how to trigger the buzzer if the temperature crosses the threshold in the telegram alert program

Thats simple connect the LM35( to (5v-A0=GND) pins as explained in the temp monitor project in the course. Now for adding the buzzer use the same circuit for LED(just replace the LED with buzzer). Also use the GPIO pin 0/1/2/3/4 . Here i am taking PIN 1. Don’t forget to connect the resistor(330ohm-orange orange brown) across the buzzer. Since there 2 connection in the ground use the bread board and wires.

Now comming to the code: contains

“”“Configurations for”""
bolt_api_key = “XXXX” # This is your Bolt Cloud API Key
device_id = “XXXX” # This is the device ID and will be similar to BOLTXXXX where XXXX is some numbers
telegram_chat_id = “@XXXX” # This is the channel ID of the created Telegram channel. Paste after @
telegram_bot_id = “botXXXX” # This is the bot ID of the created Telegram Bot. Paste after bot
threshold = 250 # Threshold beyond which the alert should be sent

The main code is this:
Here when the sensor value crosses the threshold value 250 along with sending telegram message. We give voltage to pin1 where the buzzer is connected.
And if sensor value doesn’t cross the threshold else part sets the voltage of pin1 to low

import requests
import json
import time

from boltiot import Bolt
import conf
mybolt = Bolt(conf.bolt_api_key, conf.device_id)

def get_sensor_value_from_pin(pin):
“”“Returns the sensor value. Returns -999 if request fails”""
response = mybolt.analogRead(pin)
data = json.loads(response)
if data[“success”] != 1:
print(“Request not successfull”)
print(“This is the response->”, data)
return -999
sensor_value = int(data[“value”])
return sensor_value
except Exception as e:
print(“Something went wrong when returning the sensor value”)
return -999

def send_telegram_message(message):
“”“Sends message via Telegram”""
url = “” + conf.telegram_bot_id + “/sendMessage”
data = {“chat_id”: conf.telegram_chat_id,“text”: message}
response = requests.request(“POST”,url,params=data)
print(“This is the Telegram URL”)
print(“This is the Telegram response”)
telegram_data = json.loads(response.text)
return telegram_data[“ok”]
except Exception as e:
print(“An error occurred in sending the alert message via Telegram”)
return False

while True:

sensor_value = get_sensor_value_from_pin("A0")
print("The current sensor value is:", sensor_value)

if sensor_value == -999:
	print("Request was unsuccessfull. Skipping.")

if sensor_value >= conf.threshold:
	print("Sensor value has exceeded threshold")
	message = "Alert! Sensor value has exceeded " + str(conf.threshold) +  ". The current value is " + str(sensor_value)
	telegram_status = send_telegram_message(message)
	print("This is the Telegram status:", telegram_status)


Hope it helps you