• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
ACS712 i prąd przemienny
#1
Cześć!

Mierzę prąd AC z czujnikiem ACS712(ten moduł) i Arduino Mega 2560. Pierwsze co to chciałem zobaczyć wykres, odczytów dla 0A więc skorzystałem z tego kodu:

Kod:
int sensorValue;

void setup()
{
 Serial.begin(9600);  // sets the serial port to 9600
}

void loop()
{
 sensorValue = analogRead(0);       // read analog input pin 0
 Serial.println((511-sensorValue), DEC);  // prints the value read
 delay(100);                        // wait 100ms for next reading
}

Dostałem taki wykres:

[Obrazek: 6iKsH.png]

Czy to normalne? Porównując to np z wykresem z tego postu, jest o wiele gorzej:

[Obrazek: GX1Dw.png] 

Czujnik zasilam 5v z Arduino, gnd z arduino, wyjście analogowe podłączam do A0.

Moduł podłączyłem tak: 

[Obrazek: FSZPN6c.jpg]

Dodatkowo przetestowałem czujnik tym kodem:

Kod:
#define CURRENT_SENSOR A0 // Analog input pin that sensor is attached to

float amplitude_current;               //amplitude current
float effective_value;       //effective current

void setup()
{
  Serial.begin(9600);
  pins_init();
}
 void loop()
{
  int sensor_max;
  sensor_max = getMaxValue();
  Serial.print("sensor_max = ");
  Serial.println(sensor_max);
  //the VCC on the Grove interface of the sensor is 5v
  amplitude_current=(float)(sensor_max-512)/1024*5/185*1000000;
  effective_value=amplitude_current/1.414;
  //minimum_current=1/1024*5/185*1000000/1.414=18.7(mA)
  //Only for sinusoidal alternating current
  Serial.println("The amplitude of the current is(in mA)");
  Serial.println(amplitude_current,1);//Only one number after the decimal point
  Serial.println("The effective value of the current is(in mA)");
  Serial.println(effective_value,1);
}
void pins_init()
{
  pinMode(CURRENT_SENSOR, INPUT);
}
/*Function: Sample for 1000ms and get the maximum value from the S pin*/
int getMaxValue()
{
  int sensorValue;             //value read from the sensor
  int sensorMax = 0;
  uint32_t start_time = millis();
  while((millis()-start_time) < 1000)//sample for 1000ms
  {
      sensorValue = analogRead(CURRENT_SENSOR);
      if (sensorValue > sensorMax)
      {
          /*record the maximum sensor value*/
          sensorMax = sensorValue;
      }
  }
  return sensorMax;
}

Jedyną rzecz którą zmieniłem to wartość 512, oznaczającą 0A, w moim przypadku średnia wychodziła na 516. Z tym kodem podłączając ładowarkę z tabletem dostawałem 200mA. Natomiast watomierz pokazuje 100mA. 

Co robię źle?
 
Odpowiedź
#2
Usuń to
delay(100); // wait 100ms for next reading
i zobacz wykres
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości