Hi! Good day! Can you please help me with my code? Here is my code:
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Buzzer.h>
int buzzPin= A0;
Adafruit_MLX90614 mlx= Adafruit_MLX90614();
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
mlx.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
float t = mlx.readObjectTempC();
if (t<34);
{
analogWrite(buzzPin,LOW); // turn off Buzzer
}
if (t>34);
{
analogWrite (buzzPin, HIGH);
}
}
I didn't have any errors. These codes uploaded successfully.
This is my schematic diagram for the sensor:
And for my buzzer, the black wire is connected to the GND of the Arduino and the red wire is connected to A0 analog pin. (I am sorry if I can't provide a picture) This is what a 5V buzzer looks like:
The buzzer code and MLX sensor code works properly respectively. Yet, if they were joined, it doesn't work. Nothing happens. I am having trouble with my codes.
Here is my code for the sensor:
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup() {
Serial.begin(9600);
Serial.println("Adafruit MLX90614 test");
mlx.begin();
}
void loop() {
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF());
Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
Serial.println();
delay(500);
}
This is my code for the buzzer:
const int buzzer = A0;
void setup(){
pinMode(buzzer, OUTPUT); //
}
void loop(){
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
The buzzer shall activate if the sensor detected a temperature higher than 34 degrees. It will not activate if the temperature is below 34 degrees. Please help me. I am new to using the Arduino UNO and this is a school project. Advance thank you to those who will reply! Have a nice day and stay safe always.