Go Down

Topic: Need help on ACS712 sensor (Read 613 times) previous topic - next topic

arazajr

Cleaned up your code (untested), so you can try.
Leo..
Code: [Select]
#include "ACS712.h"
ACS712 sensor(ACS712_05B, A1);
int mVperAmp = 185;
byte LED1 = 2;
byte LED2 = 3;
float current;

void setup() {
  Serial.begin (9600);
  sensor.calibrate();
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
}

void loop() {
  // measure
  float current = sensor.getCurrentDC();
  // print
  Serial.print("Current is ");
  Serial.print(current);
  Serial.println(" Amps");
  // control LEDs
  if (current < 0.01) {
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
  }
  else if (current > 0.02) {
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
  }
  else {
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
  }
  delay(1000); // some delay, so we can read it
}

I tried the code you wrote but apparently my Arduino couldn't detect the Serial.printIn code and state that "class HardwareSerial" has no member named printIn

Wawa

#16
Mar 22, 2019, 05:53 am Last Edit: Mar 22, 2019, 06:00 am by Wawa
Serial.println(); // is a common combination of print and newline
Which Arduino are you using?
Did you copy/paste, or re-type it.
Leo..

arazajr

Serial.println(); // is a common combination of print and newline
Which Arduino are you using?
Did you copy/paste, or re-type it.
Leo..
At first, I copy and paste it and then retype it..and I'm using Arduino Uno

Wawa

Should work on an Uno.
Must have done/typed something wrong.
Reference page here.
Leo..

arazajr

Should work on an Uno.
Must have done/typed something wrong.
Reference page here.
Leo..
I have rechecked many times and I even check it lines by lines..
I also read the reference before and I know it should be fine yet it still doesn't work..

Wawa

You probably have typed a capital "I" instead of a lowercase "L".

The "Serial.println" should turn orange when properly entered.
Leo..

arazajr

You probably have typed a capital "I" instead of a lowercase "L".

The "Serial.println" should turn orange when properly entered.
Leo..
I have rechecked all capital sensitive code..it still didn't turn orange...instead its just plain black text like this "Serial.printIn" ....

Wawa

The printIn you typed in post#15 and post#21 is with a capital "i".
You should type a lowercase "L".
The letter that is used in the word linefeed.
Leo..

arazajr

The printIn you typed in post#15 and post#21 is with a capital "i".
You should type a lowercase "L".
The letter that is used in the word linefeed.
Leo..
oh..okay
I will try and change it..

Go Up