Sei sulla pagina 1di 9

[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

community.blynk.cc

[SOLVED] ACS712 Voltage & Amps --


Ghost Readings! - Solved
5-7 minutos

READING AC VOLTAGE…

Simply put, I wanted to start using the ACS712 (30amp) in some


of my code, so I thought I’d que it up to run alone just to get a feel
for it. I used the code found in a post by @Jamin to sample the
device.

Link: 2 Way Lighting

Right now I have it configured, the red power light is on and it’s
“Out” is plugged into A0. Why am I getting Voltage Readings of
3530.27 and Amps of 15.61 with nothing running across the bus
terminals? If no AC line voltage is connected across the terminals
wouldn’t you expect to get something close to “0” ??

CHEERS EVERYONE - And THANK YOU

1 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

Here is my code. Simple as it may be:

**#include <Blynk.h>**
**#include <ArduinoOTA.h>**
**#include <ESP8266WiFi.h>**
**#include <BlynkSimpleEsp8266.h>**
**#include <SimpleTimer.h>**

#define BLYNK_PRINT Serial


#define SERIAL_EN
#ifdef SERIAL_EN
#define SERIAL_BAUD 115200
#define DEBUG(input) {Serial.print(input);}
#define DEBUGln(input) {Serial.println(input);}
#define SERIALFLUSH() {Serial.flush();}
#else
#define DEBUG(input);
#define DEBUGln(input);
#define SERIALFLUSH();
#endif

char auth[] =
"023a64434af9***********************";
const char* ssid = "********************";
const char* password = "*************";

int mVperAmp = 66;

2 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

int ACSoffset = 2500;


double Voltage, Amps;

SimpleTimer ACcheck;

void setup() {

#ifdef SERIAL_EN
Serial.begin(SERIAL_BAUD);
#endif
Serial.println();
Serial.println("Serial Comm's Started");
WiFi.mode(WIFI_STA);
Blynk.begin(auth, ssid, password);
while (Blynk.connect() == false) {}

ArduinoOTA.setHostname("AC_Voltage");

Serial.println("");
Serial.println("");
delay(10);
Serial.println(WiFi.status());
Serial.println("");
Serial.println("");
Serial.print("\tAssigned Local IP:\t\t");
Serial.println(WiFi.localIP());
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\tWiFi C O N N E C T E D
!!!.");
Serial.println("");

3 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

Serial.println("");
Serial.println("\tWifi Started");
}
else {
Serial.println("\tWiFi P R O B L E M" );
}
Serial.println("");
Serial.println("\tOTA Starting");

ArduinoOTA.begin();

Serial.println("");
Serial.println("\tACcheck Starting");

ACcheck.setInterval (2000L, readACS712);

Serial.println("");
Serial.println("\tComm's Complete");
Serial.println("");
Serial.println("");

readACS712();
Serial.print("\tVoltage ");
Serial.println(Voltage);
Serial.print("\tAmps ");
Serial.println(Amps);

void loop() {

ArduinoOTA.handle();

4 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

ACcheck.run();
Blynk.run();

void readACS712() {
Voltage = (analogRead(A0) / 1024.0) * 5000;
if (Voltage <= 2500) {

Blynk.virtualWrite(V1, 0);
Voltage = 2500;
Amps = 0;
} else {

Blynk.virtualWrite(V1, 255);
Amps = ((Voltage - ACSoffset) / mVperAmp);
Blynk.virtualWrite(V2, Amps);
}
}

created

Mar '17

last reply

Jul 6

69

replies

5 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

9.9k

views

users

likes

10

links

Frequent Posters

Popular Links

There are 69 replies with an estimated read time of 13 minutes.

I don't have one on hand to test this... but I would suspect it is


similar to how the analog pins on an Arduino will give false &
fluctuating readings until actually hooked up to something that
gives a solid ground reference when off.

In other words, your readings will be random and/or false until


actually hooked up to the AC line, even if no voltage is present, it
will at least be referenced to ground.

6 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

@Gunner, i do not think this is the case.


i use these sensors, and they have separate gnd pin, what you
have to hook up to the mcu gnd, so they are not floating, even
when no wires at all are connected to the hall sensor.

@Lane0138, you didn't specified what proto board are you using,
but what you should consider, that acs712 sensors are 5v
devices, but esp is 3.3v

so, this can be the first problem. the second, that acs712 can
measure current in both direction, and the output range is 0-5v.
so, when no current flowing, it should be around 2.5v (0-2.5v is
one direction, 2.5-5v is other direction)

maybe you should post a photo or link with your acs module, but
i'm pretty sure you are trying to use a 5v version with 3.3v mcu...

I was referring to the sensor end of the device, it is magnetically


isolated from MCU ground... but your catch of the 3.3v power

source makes more sense I am too used to 5v devices

and sensors... must get out more

here is a detailed video about acs712:

That's funny... that was one of the videos I re-watched when I saw
this post. Julian Ilett is one of my favorite subscribed channels... I
particularly like his "Postbag!!" videos... he buys all the cheap
China toys I can't

7 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

And has fun reading the chinglish instructions

i also watch some of his videos. this one is really useful regarding
the presentation of the acs712 module and working principle,
however the code seems a bit over complicated to me...

i use this:

#define ACS A0
#define SENSITIVITY 66
#define SAMPLING 100.0

void setup() {
Serial.begin(115200);
pinMode(ACS, INPUT);
}

void loop() {
float avgAmps;

for (int i = 0; i < SAMPLING; i++) {


int rawACS = analogRead(ACS);
float mv = rawACS / 1023.0 * 5000.0;
float rawAmps = (mv - 2500.0) / SENSITIVITY;
avgAmps += rawAmps;

8 of 9 02/11/2018 11:38
[SOLVED] ACS712 Voltage & Amps -- Ghost Readings! - Solved about:reader?url=https://community.blynk.cc/t/solved-acs712-voltage...

float Amps = avgAmps / SAMPLING;

Serial.println(Amps);
delay(1);
}

9 of 9 02/11/2018 11:38

Potrebbero piacerti anche