INA219 and buzzer problem

I am tryng to low and high current alarm with INA219. lower than 40 ma and gigher than 120 ma buzzer works. I want to off buzzer with push button . Can anyone help me?

#include <Wire.h>
#include <Adafruit_INA219.h>
#include <LiquidCrystal.h>
int buzzerPin = 8;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Adafruit_INA219 ina219;

float voltage_V = 0,shuntVoltage_mV,busVoltage_V;
float current_mA = 0;
float power_mW = 0;
float energy_Wh=0;
long time_s=0;

void setup(void)
{
lcd.begin(16,2);
pinMode(buzzerPin, OUTPUT);
uint32_t currentFrequency;
ina219.begin();
Serial.println(“Measuring voltage and current with INA219”);

delay(1000);

}

void loop(void)
{

getData();
delay(1000);

}

void getData(){

time_s=millis()/(1000); // convert time to sec
busVoltage_V = ina219.getBusVoltage_V();
shuntVoltage_mV = ina219.getShuntVoltage_mV();
voltage_V = busVoltage_V + (shuntVoltage_mV / 1000);
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
power_mW=current_mAvoltage_V;
energy_Wh=(power_mW
time_s)/3600; //energy in watt hour
current_mA = abs(current_mA);

if (current_mA < 40 ){
lcd.setCursor(0, 0);
lcd.print(“Current=”);
lcd.print(current_mA);
lcd.print(“mA”);
lcd.setCursor(5, 1);
lcd.print("low ");
digitalWrite(buzzerPin,HIGH);
delay(1000);
digitalWrite(buzzerPin,LOW);
delay(1000);
lcd.clear();

}

else if (current_mA >120) {
lcd.setCursor(0, 0);
lcd.print(“Current=”);
lcd.print(current_mA);
lcd.print(“mA”);
lcd.setCursor(5, 1);
lcd.print(“high”);
digitalWrite(buzzerPin,HIGH);
delay(250);
digitalWrite(buzzerPin,LOW);
delay(250);
lcd.clear();

}

else if (40<=current_mA<= 120) {
lcd.setCursor(0, 0);
lcd.print(“Current=”);
lcd.print(current_mA);
lcd.print("mA ");
delay(500);
}

}

_al__an_son.ino (1.87 KB)

At least fix this:

else if (40<=current_mA<= 120) {

The syntax is incorrect, besides which logically if you get here, current is already between 40 and 120.

And please explain what you mean by “off buzzer with push button”.

Should the buzzer be silent in some case even if your current is in a range where you want to hear it? A crude but effective technique is to use a switch in the wire to the buzzer: open switch → sweet silence.

a7