julianp13
Posts: 6
Joined: Mon Sep 24, 2012 8:49 am

Temperature alarm with buzzer

Fri Jan 15, 2016 12:04 pm

Hi Forum members,

I have a wood furnace and am attempting to make an alarm go off when a temperature threshold is reached. I have a MAX31855 thermocouple working but am not sure how to get the buzzer to activate. Also I would like a push button via the GPIO to turn the buzzer off once the fire has been attended to.

Here is the code so far:

Code: Select all

import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_MAX31855.MAX31855 as MAX31855
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)


# Define a function to convert celsius to fahrenheit.
def c_to_f(c):
    return c * 9.0 / 5.0 + 32.0


# Uncomment one of the blocks of code below to configure your Pi or BBB to use
# software or hardware SPI.

# Raspberry Pi software SPI configuration.
CLK = 25
CS = 24
DO = 18
sensor = MAX31855.MAX31855(CLK, CS, DO)


# Loop printing measurements every second.
print 'Press Ctrl-C to quit.'
while True:
    temp = sensor.readTempC()
    print 'Thermocouple Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(temp, c_to_f(temp))
    time.sleep(5.0)

while (True):
	GPIO.output(07, True) 				# true sets buzzer pin high
	time.sleep(0.5) 					#delay of 0.5 sec
	GPIO.output(07, False)   			#false sets buzzer pin low
	time.sleep(0.5) 					#delay of 0.5 sec

evilkitty
Posts: 380
Joined: Tue Apr 15, 2014 11:39 pm

Re: Temperature alarm with buzzer

Sun Jan 17, 2016 12:45 am

if you are using a beep speaker, like what a desktop computer has on the motherboard, you have to use PWM to make it buzz
most beep speakers are made for 5v and if they work at 3.3v they probably need >16ma

pin 12 is the only pin with a hardware level PWM feature, other pins offer PWM via software
using the

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
pwm=GPIO.PWM(12, 500) # set frequency to 500
pwm.start(0)# initialize PWM at 0% (aka off)
pwm.ChangeDutyCycle(50) # make annoying buzz
time.sleep(5)
pwm.ChangeDutyCycle(0) # make annoying buzz stop
Image

btw your second loop will never start cause the 1st never ends
lookup making a loop as a second thread

Code: Select all

import time
import thread
def doStuff():
  while True:
    print "hello"
    time.sleep(1)
thread.start_new_thread(doStuff,())
while True:
  print "meow"
  time.sleep(0.5)
My Pi Server: http://imgur.com/a/6xIUI | Thermostat: http://imgur.com/a/4LVnT

julianp13
Posts: 6
Joined: Mon Sep 24, 2012 8:49 am

Re: Temperature alarm with buzzer

Thu Jan 21, 2016 12:24 pm

Thanks for the reply. Actually i am using this buzzer:
http://www.amazon.com/gp/product/B008OT ... ge_o00_s00

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: Temperature alarm with buzzer

Thu Jan 21, 2016 1:31 pm

julianp13 wrote:Thanks for the reply. Actually i am using this buzzer:
http://www.amazon.com/gp/product/B008OT ... ge_o00_s00
30mA from a GPIO is a bad idea.
I'd go with 5V power and a transistor controlled by a GPIO in any case (as suggested)

Return to “Automation, sensing and robotics”