Go Down

Topic: Problem with Melexis contactless infrared sensor-MLX90614 and 5V buzzer code (Read 246 times) previous topic - next topic

abweynaa

Hi! Good day! Can you please help me with my code? Here is my code:
Code: [Select]
#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:
Code: [Select]
#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:
Code: [Select]
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.

TheMemberFormerlyKnownAsAWOL

Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

abweynaa

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

TheMemberFormerlyKnownAsAWOL

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

Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

abweynaa

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!

TheMemberFormerlyKnownAsAWOL

#5
Feb 21, 2021, 11:59 am Last Edit: Feb 21, 2021, 12:25 pm by TheMemberFormerlyKnownAsAWOL
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.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

abweynaa

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!

TheMemberFormerlyKnownAsAWOL

Without actually deleting (hint) the offending character for you, I don't know what more I can do.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

abweynaa

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


Go Up