Problem with Melexis contactless infrared sensor-MLX90614 and 5V buzzer code

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.

if (t<34);Oops

Good day! I am sorry I didn't understand you reply. Will you please explain it? Thank you very much

Compare your conditionals with all the other conditionals in all the example code in the IDE.

Will you please give me an example? I am sorry if I ask too many questions I am really new to using the Arduino. Thank you very much!

The IDE is jam-packed with example code.

The snippet I quoted has ten characters in it.

That's too many.

It's a conditional, so you need an "if". That stays.

Then a space. That's optional; it can stay.

You need parentheses to contain the condition. They stay.

You need a condition inside the parentheses. That stays.

Which just leaves . . ? That goes.

I am very sorry sir/ma'am. I have very little knowledge about the Arduino. Will you please explain it in a simpler way? I am hoping for your very kind consideration. Thank you very much!

Without actually deleting (hint) the offending character for you, I don't know what more I can do.

Noted! Thank you very much for your advice. I really appreciate it! Stay safe always!

Arduino reference for 'if': if - Arduino Reference

thank you so much! Have a nice day

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.