High Current Measuring with ACS712 and Buzzer Module

Hi,
Need code for HIGH CURRENT ALARM
Arduino Uno R3 along with current sensor (ACS712)/(20A) and buzzer module to be used.
The buzzer operate only after exceeding certain limit by ACS7121.

there are tons of tutorials on line , here is one

it's a simple matter of reading the current, comparing with the threshold and triggering an alarm if you exceeds the limits. Where are you struggling?

in coding.

Have you tried anything ?

Hi,
Google

acs712 20a current sensor arduino code

It is surprising what is there?
What is the application?
Can you please tell us your electronics, programming, arduino, hardware experience?

Tom... :grinning: :+1: :coffee: :australia:

i had just communicated with acs712 and buzzer module(three pin) independently with arduino uno r3

Hi,
Please read and answer post #5.
Can you post a link to data/specs of the buzzer please?

Tom... :grinning: :+1: :coffee: :australia:

Start with the basics

Have connected your ACS712?
What are the readings you get?

There is no need to discuss anything else but getting readings reliably.

Step TWO
Can you make your alarm sound with the Arduino?
Use the BLINK sketch.
Set for 500 on and 5000 off.

Let us know once you can do those things.

Read how to use this forum and how to post code.
Then post the code.

One you can read the value and make a noise.
We can help you with the alarm level part. And that will be easy.

Please verify this code.

int analogPin = A0;
const int averageValue = 500;
long int sensorValue = 0;
float voltage = 0;
float current = 0;
int buzzerPin = 11;
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);

}
void loop() {
for (long int sensorValue = 0.2;

{ void beep(unsigned char delayms)

{ analogWrite(buzzerPin, 20);
delay(delayms);
analogWrite(buzzerPin , 0);
delay(delayms);
}
sensorValue = sensorValue / averageValue;
voltage = sensorValue * 5.0 / 1024.0;
current = (voltage - 2.5) / 0.185;
}}

Please read the posts at the Beginning of the forum.

They explain how to post code.

Please auto-format you code.
It will set indents and such to make it easier to read and troubleshoot

Also please verify you code will complie using the verify button.

At first look
It seems like you are trying to do two things. Read a value and sound the alarm.

It would be much easier for you to follow if you get it to read the value and display the value.

Then, once you have that working, then add the alarm.

Try the analog input example in the ide.

#include<stdio.h>
#include <Arduino.h>
int analogPin = A0;
const int mode =2;
float i = 0.2;
int buzzerPin = 11;
void setup()
{
Serial.begin(9600);
pinMode(i,INPUT);
}
void loop()
{
i = analogRead(i);
if (i >= 0.2)
analogWrite(buzzerPin, 20);
else
analogWrite(buzzerPin, 0);
delay(100);
}

i am having problem in coding. Please help.
Buzzer Continuously on irrespective of current sensor

Hi,
Look at your code with the proper formating;

#include<stdio.h>
#include <Arduino.h>
int analogPin = A0;
const int mode = 2;
float i = 0.2;
int buzzerPin = 11;
void setup()
{
  Serial.begin(9600);
  pinMode(i, INPUT);
}
void loop()
{
  i = analogRead(analogPin);
  if (i >= 0.2)
  {
    analogWrite(buzzerPin, 20);
  }

  else
  {
    analogWrite(buzzerPin, 0);
    delay(100);
  }
}

I don't know if this will work either.

You need to understand how if.. else.. statements are constructed.

Please read THIS;
To add code please click this link;

Tom... :grinning: :+1: :coffee: :australia:

Here is the example Analog in serial out
with some changes for your sketch.

all this will do is to display the serial value on the monitor.

it does no math, no average, only displays the value that it reads on the Analog pin

/*
  Analog input, analog output, serial output

  Reads an analog input pin, 
  Also prints the results to the Serial Monitor.

  created 29 Dec. 2008 ,   by Tom Igoe
  This example code [ has been changed for posting in the forum and] is in the public domain.
 */

/* first list constant pins.  these are physical pins
 * next  list constant variables
 * then  list variables that change
 */

// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0;  // Analog input pin that the SENSOR
const int buzzerPin = 11; // DIGITAL output pin that the BUZZER  is attached to

// these are constant values that will not change


// these are variables that change by the program
float voltage = 0;
float current = 0;
int averageValue = 500;
long int sensorValue = 0;


void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);

// this will be from 0 to 1023  

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(2);
}

there are many things in your sketch that do not seem to be correct.

analog read is a whole number aka integer, 0 to 1023

you have the buzzer making noise if that value is ever over 0.2
since the value of ( i ) is an integer of 0 to 1023, your buzzer will be on all the time.
any noise at all will trigger it.

you call two libraries. no notes why and they are not used in this sketch.

the example program in post #14, will show you on the serial monitor, the input value.

Again, please do ONE THING, get it working as you expect and need.
only THEN add a second thing.

step 1 get the sensor to read in the raw format of 0-1023

once you have the analog input working, you can scale it to something. like amps.

=====
please post what buzzer you are using.
the alarm output does an analog write from 0-512 and you are outputting 20.
that seems very low if it is for a light.
if your buzzer needs the PWM pulse to make noise, then you would be getting a noise.

Please stop asking for help, we know that.
Please post what happens when you do these things.



ADDED

if you use the serial plotter output, you will see the results in a more meaningful way.
if the results are very noisy, we can add a way to average them to make them smoother.
but the idea is to get a feel for the bits working.
only after you show they are working, can you start to make them easier to read, or make the reading represent your amps.

here is code for the buzzer.
this is very simple and it should beep for you.
but this is a guess as we do not know what you have for a buzzer.

/*
  MODIFED Blink example to sound buzzer

*/

const int buzzerPin = 11;  // pins should be set as constant


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  
}

// the loop function runs over and over again forever
void loop() {

  analogWrite(buzzerPin, 20);           // should make noise
  digitalWrite(LED_BUILTIN, LOW);  
  delay(500);                       // wait for a half second
  
  digitalWrite(LED_BUILTIN, HIGH);     // turn the LED off by making the voltage LOW
  analogWrite(buzzerPin, 0);            // should be quiet
  delay(5000);                       // wait for a 5 seconds
}