IR showing random HEX values

I have a project that detects the water level + temperature + humidity, Whenever something goes too low, high, or very high, the buzzer will turn on, if I click a button on the IR the buzzer will turn off, but the problem is that when I click before the buzzer is turned on it shows the correct HEX value, but when the buzzer is turned on and I click the button it shows some random values each time.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#include <IRremote.h>

#define Type DHT11
// Sensors pins
int DHTPin = 7;
int waterP = A3;
int BuzzerPin = 2;
int IRPin = 3;

DHT HT(DHTPin, Type);

// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define variables for sensor values
int waterV = 0;
float humid;
float tempC;
float tempF;

// Warning messagges variables
String humidV;
String tempFV;
String tempCV;
String waterVW;

// Define variables for timing
unsigned long previousMillis = 0;
const long sensorreadtime = 100;      // Update every 1 second
const long displayTime = 3000;   // Common display time for all sensors in milliseconds
const long transitionTime = 2000; // Transition time between states in milliseconds

// Define states for the state machine
enum State
{
  Humidity,
  Water,
  TempC,
  TempF
};

State currentState = Humidity;    // Initial state
unsigned long displayStartTime = 0;  // Variable to store the start time for displaying each sensor

// IR sensor
IRrecv IR(IRPin);
decode_results results;

// Define a variable for IR signal filtering
unsigned long irFilterDelay = 500;  // Set the filter delay to 1 second
unsigned long lastIRMillis = 0;

void setup(){
  // Initialize LCD
  lcd.begin();
  lcd.backlight();

  // Initialize sensors
  pinMode(waterP, INPUT);
  HT.begin();
  pinMode(BuzzerPin, OUTPUT);
  digitalWrite(BuzzerPin,LOW);
  IR.enableIRIn();

  // Serial start
  Serial.begin(115200);
}

void loop(){
  //current time
  unsigned long currentMillis = millis();

  // IR Manager
  if (IR.decode(&results)) {
    // Check if enough time has passed since the last valid IR signal
    if (currentMillis - lastIRMillis >= irFilterDelay) {
      Serial.println(results.value, HEX);
      // Handle the remote input
      handleRemoteInput(results.value);
      // Update the last valid IR time
      lastIRMillis = currentMillis;
    }

    // Resume IR receiver
    IR.resume();
  }

  // Check if the sensorreadtime has passed
  if (currentMillis - previousMillis >= sensorreadtime){
    // Save the current time
    previousMillis = currentMillis;

    // Handle the state transitions and display sensor readings
    handleState(currentMillis);
  }
}

// Function to handle state transitions + display sensor readings
void handleState(unsigned long currentMillis)
{
  switch (currentState)
  {
    case Humidity:
      if (currentMillis - displayStartTime >= displayTime)
      {
        humid = HT.readHumidity();
        humid = round(humid); // Round the humidity value
        Serial.print("Humidity is being read. Humidity: ");
        Serial.println(humid);
        if (humid >= 60 && humid <= 80)
        {
          humidV = "Good - " + String(humid);
        }
        if (humid <= 60)
        {
          humidV = "Low - " + String(humid);
          startBuzzer(500);  // Beep for low humidity
        }
        if (humid >= 80)
        {
          humidV = "High - " + String(humid);
          startBuzzer(1000);  // Beep for high humidity
        }
        displaySensorReading("Humidity", humidV);
        currentState = Water;
        displayStartTime = currentMillis;
      }
      break;

    case Water:
      if (currentMillis - displayStartTime >= displayTime)
      {
        waterV = analogRead(waterP);
        Serial.print("Water is being read. Water Value: ");
        Serial.println(waterV);
        if (waterV < 60)
        {
          waterVW = "LOW - " + String(waterV);
          startBuzzer(500);  // Beep for low water level
        }
        displaySensorReading("Water Value", waterVW);
        currentState = TempC;
        displayStartTime = currentMillis;
      }
      break;

    case TempC:
      if (currentMillis - displayStartTime >= displayTime)
      {
        tempC = HT.readTemperature();
        tempC = round(tempC); // Round the temperature value
        Serial.print("TempC is being read. TempC: ");
        Serial.println(tempC);
        if (tempC >= 16 && tempC <= 25)
        {
          tempCV = "Good - " + String(tempC);
        }
        if (tempC <= 15)
        {
          tempCV = "LOW - " + String(tempC);
          startBuzzer(500);  // Beep for low temperature
        }
        if (tempC >= 25)
        {
          tempCV = "HIGH - " + String(tempC);
          startBuzzer(1000);  // Beep for high temperature
        }
        displaySensorReading("TempC", tempCV);
        currentState = TempF;
        displayStartTime = currentMillis;
      }
      break;

    case TempF:
      if (currentMillis - displayStartTime >= displayTime)
      {
        tempF = HT.readTemperature(true);
        tempF = round(tempF); // Round the temperature value
        Serial.print("TempF is being read. TempF: ");
        Serial.println(tempF);
        if (tempF >= 59 && tempF <= 77)
        {
          tempFV = "Good - " + String(tempF);
        }
        if (tempF <= 59)
        {
          tempFV = "LOW - " + String(tempF);
          startBuzzer(500);  // Beep for low temperature
        }
        if (tempF >= 77)
        {
          tempFV = "HIGH - " + String(tempF);
          startBuzzer(1000);  // Beep for high temperature
        }
        displaySensorReading("TempF", tempFV);
        currentState = Humidity;
        displayStartTime = currentMillis;
      }
      break;
  }
}

// Function to display sensor reading on the LCD
void displaySensorReading(const char *sensorName, String sensorValue)
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(sensorName);
  lcd.setCursor(0, 1);
  lcd.print(sensorValue);
}

// Function to handle IR remote input
void handleRemoteInput(unsigned long value){
  if(value == 0xFFA25D){
    stopBuzzer();
  }
}

// Function to start buzzer with specific frequency
void startBuzzer(int frequency){
  Serial.println("Buzzer On");
  tone(BuzzerPin, frequency);
}

// Function to stop buzzer
void stopBuzzer(){
  Serial.println("Buzzer Stopped");
  noTone(BuzzerPin);
}

Most likely there is a conflict with the timer when using IR and tone(). See if another timer can be set on either function.

What type of "buzzer" if an old electro mechanical type then the issue is likely generated electrical noise from the buzzer.

Replace the buzzer with a resistor and LED. If it works OK then the buzzer is the issue.

I've purchased a few boards from ebay that have 4 led's with their respective resistors. I've found them great for testing as their pins go directly into a solderless breadboard.

I also purchase a similar board with 4 buttons on it. Again great for testing.

You read this?

nope but i will

I don't know so much about timers, what I did understand from what you said is that there is a pin with a timer that is interfering with the IR, is that correct, and how do I set it to an other timer?

Well that was the issue, I replaced the buzzer with an LED and it just worked, why then is the buzzer not letting the IR cath the info? And is there any fix to this issue so I can put back my buzz? Would the passive type work?

I just downloaded this and this is just the new IR library, I didn't like this version cause I didn't know how to use it, so I switched to an older one

Buzzers create a lot of electrical noise. Noise like high voltage (10s of volts) spikes on the lines feeding it. If you make a sketch of your wiring I can make suggestions.

After more inspection the problem isn't from the buzzer, I've changed the code In a lot of different ways

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#include <IRremote.h>

#define Type DHT11

// Sensors pins
int DHTPin = 7;
int waterP = A3;
int BuzzerPin = 11;
int IRPin = 3;

DHT HT(DHTPin, Type);

// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define variables for sensor values
int waterV = 0;
float humid, tempC, tempF;
unsigned long IRwait = 0;
bool buzzerEnabled = true;

// Define variables for timing
unsigned long previousMillis = 0;
const long sensorReadTime = 100;      // Update every 0.1 second
const long displayTime = 5000;   // Common display time for all sensors in milliseconds
const long buzzerInterval = 1000; // Minimum interval between buzzer beeps

// Define states for the state machine
enum State
{
  Humidity,
  Water,
  TempC,
  TempF
};

State currentState = Humidity;    // Initial state
unsigned long displayStartTime = 0;  // Variable to store the start time for displaying each sensor
unsigned long buzzerPreviousMillis = 0; // Variable to store the last time the buzzer sounded

// IR sensor
IRrecv IR(IRPin);
decode_results results;

// Function declarations
void displayAndAlert(const char *sensorName, float sensorValue, const char *unit);
void handleRemoteInput(unsigned long value);
void startBuzzer(int frequency, int beepDuration, int beepPause, int beepCount);
void stopBuzzer();
void handleState(unsigned long currentMillis);

// Degree symbol for tempC and F
byte degreeSymbol[8] = {
  0b00110,
  0b01001,
  0b01001,
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

void setup() {
  // Initialize LCD
  lcd.begin();
  lcd.backlight();

  // Initialize sensors
  pinMode(waterP, INPUT);
  HT.begin();
  pinMode(BuzzerPin, OUTPUT);
  digitalWrite(BuzzerPin, LOW);
  IR.enableIRIn();

  // Serial start
  Serial.begin(115200);

  // Upload custom character to position 0
  lcd.createChar(0, degreeSymbol);
}

void loop() {
  // Current time
  unsigned long currentMillis = millis();

// IR Manager
  if (IR.decode()) {
    unsigned long value = IR.decodedIRData.decodedRawData;
    Serial.println("IR Code: " + String(value, HEX));
    handleRemoteInput(value);
    if (currentMillis - IRwait >= 1000) {
      IRwait = currentMillis;
    }
    IR.resume();
  }

  // Check if the sensorReadTime has passed
  if (currentMillis - previousMillis >= sensorReadTime) {
    // Save the current time
    previousMillis = currentMillis;

    // Handle the state transitions and display sensor readings
    handleState(currentMillis);
  }
}

// Function to handle state transitions + display sensor readings
void handleState(unsigned long currentMillis) {
  switch (currentState) {
    case Humidity:
      if (currentMillis - displayStartTime >= displayTime) {
        humid = round(HT.readHumidity()); // Round the humidity value
        displayAndAlert("Humidity", humid, "%");
        currentState = Water;
        displayStartTime = currentMillis;
      }
      break;

    case Water:
      if (currentMillis - displayStartTime >= displayTime) {
        waterV = analogRead(waterP);
        displayAndAlert("Water Value", waterV, "");
        currentState = TempC;
        displayStartTime = currentMillis;
      }
      break;

    case TempC:
      if (currentMillis - displayStartTime >= displayTime) {
        tempC = round(HT.readTemperature()); // Round the temperature value
        displayAndAlert("TempC", tempC, "C");
        currentState = TempF;
        displayStartTime = currentMillis;
      }
      break;

    case TempF:
      if (currentMillis - displayStartTime >= displayTime) {
        tempF = round(HT.readTemperature(true)); // Round the temperature value
        displayAndAlert("TempF", tempF, "F");
        currentState = Humidity;
        displayStartTime = currentMillis;
      }
      break;
  }
}

// Function to display sensor reading on the LCD and alert with buzzer
void displayAndAlert(const char *sensorName, float sensorValue, const char *unit) {
  Serial.print(sensorName);
  Serial.print(" is being read. ");
  Serial.print(sensorName);
  Serial.print(": ");
  Serial.println(sensorValue);

  String sensorValueStr = String(sensorValue, 1); // Limit to 1 decimal place
  String alertStr = "";

  if (sensorName == "Humidity") {
    if (sensorValue >= 60 && sensorValue <= 80) {
      alertStr = "Good";
    } else if (sensorValue < 60) {
      alertStr = "Low";
      if (buzzerEnabled) startBuzzer(250, 200, 100, 4);  // Change the number of beeps to 4 for low humidity
    } else if (sensorValue > 80 && sensorValue <= 90) {
      alertStr = "High";
      if (buzzerEnabled) startBuzzer(500, 200, 100, 4);  // Change the number of beeps to 4 for high humidity
    } else if (sensorValue > 90) {
      alertStr = "Extreme";
      if (buzzerEnabled) startBuzzer(750, 200, 100, 4);  // Change the number of beeps to 4 for extreme humidity
    }
  } else if (sensorName == "TempC" || sensorName == "TempF") {
    if (sensorValue >= 20 && sensorValue <= 25) {
      alertStr = "Good";
    } else if (sensorValue < 20) {
      alertStr = "Low";
      if (buzzerEnabled) startBuzzer(250, 200, 100, 4);  // Change the number of beeps to 4 for low temperature
    } else if (sensorValue > 25 && sensorValue <= 30) {
      alertStr = "High";
      if (buzzerEnabled) startBuzzer(500, 200, 100, 4);  // Change the number of beeps to 4 for high temperature
    } else if (sensorValue > 30) {
      alertStr = "Extreme";
      if (buzzerEnabled) startBuzzer(750, 200, 100, 4);  // Change the number of beeps to 4 for extreme temperature
    }
  } else if (sensorName == "Water Value") {
    // Water value thresholds
    if (sensorValue < 300) {
      alertStr = "Low";
      if (buzzerEnabled) startBuzzer(250, 200, 100, 4);  // Change the number of beeps to 4 for low water value
    } else if (sensorValue >= 300 && sensorValue <= 350) {
      alertStr = "Good";
    } else if (sensorValue > 350 && sensorValue <= 400) {
      alertStr = "High";
      if (buzzerEnabled) startBuzzer(500, 200, 100, 4);  // Change the number of beeps to 4 for high water value
    } else if (sensorValue > 400) {
      alertStr = "Extreme";
      if (buzzerEnabled) startBuzzer(750, 200, 100, 4);  // Change the number of beeps to 4 for extreme water value
    }
  }

  // Add the '%' symbol for humidity
  unit = (sensorName == "Humidity") ? "%" : unit;

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(sensorName);
  lcd.setCursor(0, 1);
  lcd.print(alertStr);
  lcd.print(" - ");
  lcd.print(sensorValueStr);
  lcd.print(unit);
}



// Function to handle IR remote input
void handleRemoteInput(unsigned long value) {
  if (value == 0xBA45FF00) {
    // Toggle the buzzer status
    buzzerEnabled = !buzzerEnabled;
    if (!buzzerEnabled) stopBuzzer();
  }
}

// Function to start buzzer with specific frequency
void startBuzzer(int frequency, int beepDuration, int beepPause, int beepCount) {
  // Check if enough time has passed since the last buzzer sound
  unsigned long currentMillis = millis(); // Declare currentMillis here

  if (currentMillis - buzzerPreviousMillis >= buzzerInterval) {
    Serial.println("Buzzer On");

    for (int i = 0; i < beepCount; i++) {
      unsigned long startTime = millis();

      while (millis() - startTime < beepDuration) {
        tone(BuzzerPin, frequency);

        // Check for IR signals periodically
        if (millis() - IRwait >= 1000) {
          IRwait = millis();
          if (IR.decode()) {
            unsigned long value = IR.decodedIRData.decodedRawData;
            Serial.println("IR Code: " + String(value, HEX));
            handleRemoteInput(value);
            IR.resume();
          }
        }
      }

      noTone(BuzzerPin);

      if (i < beepCount - 1) {
        // Add a pause between beeps
        unsigned long pauseStartTime = millis();
        while (millis() - pauseStartTime < beepPause) {
          // Check for IR signals periodically during the pause
          if (millis() - IRwait >= 1000) {
            IRwait = millis();
            if (IR.decode()) {
              unsigned long value = IR.decodedIRData.decodedRawData;
              Serial.println("IR Code: " + String(value, HEX));
              handleRemoteInput(value);
              IR.resume();
            }
          }
        }
      }
    }

    // Update the last time the buzzer sounded
    buzzerPreviousMillis = currentMillis;
  }
}



// Function to stop buzzer
void stopBuzzer() {
  Serial.println("Buzzer Stopped");
  noTone(BuzzerPin);
}

for some reason, whenever the Arduino passes by the Start buzzer function the problem begins, the IR starts to show random values, I've replaced the buzzer with a led but kept the same code but still the same problem, probably because of the timer or something, any fixes?

what app or website do i use to do the schematic?

TinyCad is a small program that just draws schematics. Pretty simple to learn.

Kicad is a larger program that you can draw schematics and design PC Boards. Pretty intuitive but more difficult than TinyCad.

There are websites that allow you to draw schematics but you are then tied to their website. I know they exist but I don't use them.

I hate to say it but I barley know how to draw schematics, I could do it but I will 100% get it wrong.

Well, now is the time to learn. Start by drawing blocks representing each part and connect them together with the wires you are using.
Good place to start. We've all been there.

Hello everyone, the problem is not with the buzzer itself, I connected an LED and changed the code a bit more

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#include <IRremote.h>

#define Type DHT11

// Sensors pins
int DHTPin = 7;
int waterP = A3;
int BuzzerPin = 11;
int IRPin = 3;

DHT HT(DHTPin, Type);

// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define variables for sensor values
int waterV = 0;
float humid, tempC, tempF;
unsigned long IRwait = 0;
bool buzzerEnabled = true;
bool isBuzzerActive = false;

// Define variables for timing
unsigned long previousMillis = 0;
const long sensorReadTime = 100;      // Update every 0.1 second
const long displayTime = 6000;   // Common display time for all sensors in milliseconds
const long buzzerInterval = 1000; // Minimum interval between buzzer beeps

// Define states for the state machine
enum State
{
  Humidity,
  Water,
  Temp
};

State currentState = Humidity;    // Initial state
unsigned long displayStartTime = 0;  // Variable to store the start time for displaying each sensor
unsigned long buzzerPreviousMillis = 0; // Variable to store the last time the buzzer sounded

// IR sensor
IRrecv IR(IRPin);
decode_results results;

// Function declarations
void displayAndAlert(const char *sensorName, float sensorValueC, float sensorValueF, const char *unitC, const char *unitF);
void handleRemoteInput(unsigned long value);
void startBuzzer(int frequency, int duration, int numBeeps);
void stopBuzzer();
void handleState(unsigned long currentMillis);

void setup() {
  // Initialize LCD
  lcd.begin();
  lcd.backlight();

  // Initialize sensors
  pinMode(waterP, INPUT);
  HT.begin();
  pinMode(BuzzerPin, OUTPUT);
  digitalWrite(BuzzerPin, LOW);
  pinMode(IRPin,INPUT);
  IR.enableIRIn();

  tone(BuzzerPin, 4000);
  delay(250);
  tone(BuzzerPin, 5000);
  delay(250);
  tone(BuzzerPin, 4000);
  delay(300);
  noTone(BuzzerPin);
  // Serial start
  Serial.begin(115200);
}

void loop() {
  // Current time
  unsigned long currentMillis = millis();

  // Skip IR processing if the buzzer is active
  if (!isBuzzerActive) {
    // IR Manager
    if (IR.decode() && buzzerEnabled) {
      unsigned long value = IR.decodedIRData.decodedRawData;
      handleRemoteInput(value);
      if (currentMillis - IRwait >= 500) {  // 500 milliseconds wait time
        IRwait = currentMillis;
      }
      IR.resume();
    }
  }

  // Check if the sensorReadTime has passed
  if (currentMillis - previousMillis >= sensorReadTime) {
    // Save the current time
    previousMillis = currentMillis;

    // Handle the state transitions and display sensor readings
    handleState(currentMillis);
  }
}

// Function to handle state transitions + display sensor readings
void handleState(unsigned long currentMillis) {
  switch (currentState) {
    case Humidity:
      if (currentMillis - displayStartTime >= displayTime) {
        humid = round(HT.readHumidity()); // Round the humidity value
        displayAndAlert("Humidity", humid, 0, "%", "");  // TempF is set to 0 for humidity
        currentState = Water;
        displayStartTime = currentMillis;
      }
      break;

    case Water:
      if (currentMillis - displayStartTime >= displayTime) {
        waterV = analogRead(waterP);
        displayAndAlert("Water Value", waterV, 0, "", "");  // TempC and TempF are set to 0 for water value
        currentState = Temp;
        displayStartTime = currentMillis;
      }
      break;

    case Temp:
      if (currentMillis - displayStartTime >= displayTime) {
        tempC = round(HT.readTemperature()); // Temperature value C
        tempF = round(HT.readTemperature(true)); // Temperature value F
        displayAndAlert("Temp", tempC, tempF, "C", "F");
        currentState = Humidity;
        displayStartTime = currentMillis;
      }
      break;
  }
}

// Function to display sensor reading on the LCD and alert with buzzer
void displayAndAlert(const char *sensorName, float sensorValueC, float sensorValueF, const char *unitC, const char *unitF) {
  String sensorValueStrC = String(sensorValueC, 0); // No decimal places for tempC
  String sensorValueStrF = String(sensorValueF, 0); // No decimal places for tempF
  String alertStr = "";

  lcd.clear();
  lcd.setCursor(0, 0);

  if (sensorName == "Humidity") {
    if (sensorValueC < 60) {
      alertStr = "Low";
      if (buzzerEnabled) {
        startBuzzer(1000, 250, 3);  // Buzzer for low humidity or water value
      }
    } else if (sensorValueC >= 60 && sensorValueC <= 80) {
      alertStr = "Good";
      if (buzzerEnabled) {
        startBuzzer(4000, 100, 1);
        startBuzzer(3000, 100, 1);
        startBuzzer(4000, 100, 1);
      }
    } else if (sensorValueC > 80 && sensorValueC <= 90) {
      alertStr = "High";
      if (buzzerEnabled) {
        startBuzzer(1500, 200, 3);  // Buzzer for high humidity or water value
      }
    } else if (sensorValueC > 90) {
      alertStr = "Extreme";
      if (buzzerEnabled) {
        startBuzzer(2000, 100, 3);  // Buzzer for extreme humidity or water value
      }
    }

    lcd.print(sensorName);
    lcd.print(":");
    lcd.setCursor(0, 1);
    lcd.print(alertStr);
    lcd.print(" - ");
    lcd.print(sensorValueStrC);

  } else if (sensorName == "Water Value") {
    if (sensorValueC < 60) {
      alertStr = "Low";
      if (buzzerEnabled) {
        startBuzzer(1000, 250, 3);  // Buzzer for low humidity or water value
      }
    } else if (sensorValueC >= 60 && sensorValueC <= 80) {
      alertStr = "Good";
      if (buzzerEnabled) {
        startBuzzer(4000, 100, 1);
        startBuzzer(3000, 100, 1);
        startBuzzer(4000, 100, 1);
      }
    } else if (sensorValueC > 80 && sensorValueC <= 90) {
      alertStr = "High";
      if (buzzerEnabled) {
        startBuzzer(1500, 200, 3);  // Buzzer for high humidity or water value
      }
    } else if (sensorValueC > 90) {
      alertStr = "Extreme";
      if (buzzerEnabled) {
        startBuzzer(2000, 100, 3);  // Buzzer for extreme humidity or water value
      }
    }

    lcd.print(sensorName);
    lcd.print(":");
    lcd.setCursor(0, 1);
    lcd.print(alertStr);
    lcd.print(" - ");
    lcd.print(sensorValueStrC);
  }
  else if (sensorName == "Temp") {
    if (sensorValueC >= 20 && sensorValueC <= 25) {
      alertStr = "Good";
      if (buzzerEnabled) {
        startBuzzer(4000, 100, 1);
        startBuzzer(3000, 100, 1);
        startBuzzer(4000, 100, 1);
      }
    } else if (sensorValueC < 20) {
      alertStr = "Low";
      if (buzzerEnabled) {
        startBuzzer(1000, 250, 3);  // Buzzer for low temperature
      }
    } else if (sensorValueC > 25 && sensorValueC <= 30) {
      alertStr = "High";
      if (buzzerEnabled) {
        startBuzzer(1500, 200, 3);  // Buzzer for high temperature

      }
    } else if (sensorValueC > 30) {
      alertStr = "Extreme";
      if (buzzerEnabled) {
        startBuzzer(2000, 100, 3);  // Buzzer for extreme temperature
      }
    }

    lcd.print("Temp: ");
    lcd.print(alertStr);
    lcd.setCursor(0, 1);
    lcd.print("C:");
    lcd.print(sensorValueStrC);
    lcd.print(unitC);
    lcd.print(" F:");
    lcd.print(sensorValueStrF);
    lcd.print(unitF);
  }
}

// Function to handle IR remote input
void handleRemoteInput(unsigned long value) {
  Serial.print("Received IR Code: ");
  Serial.println(value, HEX);

  if (value == 0xb847ff00) {
    // Toggle the buzzer status
    buzzerEnabled = !buzzerEnabled;
    if (!buzzerEnabled) {
      stopBuzzer();
      Serial.println("Buzzer Disabled");
      lcd.clear();
      lcd.print("Buzzer status off");
    } else {
      Serial.println("Buzzer Enabled");
      lcd.clear();
      lcd.print("Buzzer status on");
    }
  }

  // Reset IR decoding
  IR.resume();
  IRwait = millis();  // Reset the wait time
}

// Function to start buzzer with specific frequency, duration, and number of beeps
void startBuzzer(int frequency, int duration, int numBeeps) {
  isBuzzerActive = true; // Set the flag to indicate that the buzzer is iactive
  for (int i = 0; i < numBeeps; i++) {
    tone(BuzzerPin, frequency);
    delay(duration);
    noTone(BuzzerPin);
    delay(duration);
  }
  isBuzzerActive = false; // Set the flag to indicate that the buzzer is inactive
  Serial.println("Buzzer On");
}

// Function to stop buzzer
void stopBuzzer() {
  noTone(BuzzerPin);
  isBuzzerActive = false; // Set the flag to indicate that the buzzer is inactive
  Serial.println("Buzzer Stopped");
}

I will draw the schematic now and will send it after it is finished.
Thank you all for helping me :heavy_heart_exclamation:


The problem seems to be from the code not from the hardware, i know this because I changed the buzzer to a LED and a passive, I think because of the Tone function but i just don't know how to fix it, and even after not using the function after the buzzer ringed the IR stopped working properly and started to read faulty readings

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