Currently I'm doing a project for a ATV belt temp sensor and warning system.
Everything except the buzzer works great, I have a LCD 16x2 display with a infrared temp sensor.
What I'm trying to do is when the belt temp reaches a certain point the heat level bar on the display flashes and the buzzer will sound off so I can give the belt a break.
Currently the buzzer just stays on in a low buzzing state, when the temp is reached for the warning, it buzzes a little louder and then continues the low buzz. its plugged into digital 9 and 5V, I've tried different pins. on top of that ive tried digital write and many other things
It seems like something in the code is keeping the 9 pin on?
Here is the code:
#include <Adafruit_MLX90614.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
//LCD port and init
LiquidCrystal_I2C lcd(0x27, 16, 2);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
//initi belttemp
int beltTemp;
int buzzer = 9;
//initi custom char
byte customChar[8] = {
0b10100,
0b11100,
0b10101,
0b00000,
0b10000,
0b10001,
0b10000,
0b11100
};
void setup()
{
//temp sens init
mlx.begin();
//lcd init
lcd.init();
lcd.backlight();
lcd.createChar(0, customChar);
lcd.begin(16, 2);
//buzzer init
pinMode(buzzer,OUTPUT);
}
//**** MAIN ****
void loop()
{
//init belttemp var
beltTemp = mlx.readObjectTempF();
//printing current belt temp
lcd.setCursor(0,0);
lcd.print("Belt temp:"); lcd.print(beltTemp); lcd.print("F"); lcd.print(" ");
//printing belt heat level
lcd.setCursor(0,1);
lcd.write((uint8_t)0); //HL custom char
HeatLevel(beltTemp);
}
//**** FUNCTIONS ****
//Function for the Heat Level Bar
int HeatLevel(int beltTemp)
{
//Heat Level
int HL = 0;
//Loop Control (Copy of HL)
int LC = 0;
//wont show if less than 100F
HL = ((beltTemp-90)/10); //min 100, max 250
LC = HL;
//when HL is greater than 0(100F) it shows heat level
if(HL > 0)
{
while(LC > 0)
{
lcd.write(255);
LC--;
}
}
lcd.print(" ");
//when HL is 10 (200F) or greater it flashes
if(HL > 2)
{
//Clearing bar and buzzing alert (Flashing effect)
delay(250);
tone(buzzer, 1000);
lcd.setCursor(1,1);
lcd.print(" ");
delay(250);
noTone(buzzer);
}
}
Please let me know if you see anything that's causing the buzzer to stay on at all times.
