Jump to content
ELFORUM - Forumul electronistilor
bogdan666

Problema senzor de curent acs758

Recommended Posts

Am facut un incarcator solar cu arduino, si am urmatoarea problema cu senzorul de curent, cand nu trece curent prin el ar trebui sa fie 0V, dar defapt e 0.590V, care e citit de un adc, si anume ads1115. Cum pot sa spun adc-ului sa inceapa numaratoarea doar de la 590mV?

 

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads(0x4A);
float V1 = 0.0;
float V2 = 0.0;
float V3 = 0.0;
float V4 = 0.0;
float en1 = 0.0;
float en2 = 0.0;

void setup(void)
{
  pinMode(9, OUTPUT);
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  ads.begin();
}
unsigned long startMillis;
unsigned long currentMillis;
unsigned long elapsedMillis;
byte pulseWidth = 0;

void loop(void)
{

  V1 = ((ads.readADC_SingleEnded(0)) * 0.0001875) * 7;
  V2 = ((ads.readADC_SingleEnded(1)) * 0.0001875) * 20;
  V3 = ((ads.readADC_SingleEnded(2)) * 0.0001875) * 10;
  V4 = ((ads.readADC_SingleEnded(3)) * 0.0001875) * 8;

  currentMillis = millis();
  elapsedMillis = (currentMillis - startMillis);
  unsigned long SS = (elapsedMillis / 1000) % 60;
  unsigned long MM = (elapsedMillis / (60000)) % 60;
  unsigned long HH = (elapsedMillis / (3600000));

  en1 = en1 += (V3 * V4) * 1 / 36000;
  en2 = en2 += (V1 * V2) * 1 / 36000; 

  lcd.setCursor(0, 0);
  lcd.print(V4, 2);
  lcd.setCursor(5, 0);
  lcd.print("V");
  lcd.setCursor(7, 0);
  lcd.print(V3, 3);
  lcd.setCursor(12, 0);
  lcd.print("A");
  lcd.setCursor(14, 0);
  lcd.print(V3 * V4, 1);
  lcd.setCursor(19, 0);
  lcd.print("W");

  lcd.setCursor(0, 1);
  lcd.print(V1, 3);
  lcd.setCursor(5, 1);
  lcd.print("V");
  lcd.setCursor(7, 1);
  lcd.print(V2, 3);
  lcd.setCursor(12, 1);
  lcd.print("A");
  lcd.setCursor(14, 1);
  lcd.print(V1 * V2, 1);
  lcd.setCursor(19, 1);
  lcd.print("W");

  lcd.setCursor(0, 2);
  lcd.print("IN");
  lcd.setCursor(4, 2);
  lcd.print(en1, 1);
  lcd.setCursor(10, 2);
  lcd.print("W/H");
  lcd.setCursor(0, 3);
  lcd.print("OUT");
  lcd.setCursor(4, 3);
  lcd.print(en2, 1);
  lcd.setCursor(10, 3);
  lcd.print("W/H");
 
  lcd.setCursor(14, 3);
  lcd.print(MM);
  lcd.print(":");
  lcd.print(SS);

  if (V1 < 28 )
  {
    if (pulseWidth != 255) pulseWidth++;
  }
  if (V1 > 28 )
  {
    if (pulseWidth = 0);
  }
  analogWrite(9, pulseWidth);
}

 

Edited by bogdan666
Link to post
Share on other sites

Foarte simplu...dupa mai multe teste, defapt functioneaza cu 588: V2 = (((ads.readADC_SingleEnded(1)) * 0.0001875) - 0.588) * 20;

mersi mult, o alta problema este faptul ca ecranul o ia razna cand chiar se foloseste energie, deci trebuie sa rotunjesc citirile...inapoi la studiat.

Link to post
Share on other sites

Poate intereseaza pe cineva sau are aceeasi problema, am rezolvat problema cu "rotunjirile"

 

 V1 = 0;
  V2 = 0;
  V3 = 0;
  V4 = 0;
  for (int i = 0; i < 10; i++)
  {
    V1 += ads.readADC_SingleEnded(0) * 0.0001875 * 7.0;
    V2 += (ads.readADC_SingleEnded(1) * 0.0001875 - 0.588) * 20;
    V3 += (ads.readADC_SingleEnded(2) * 0.0001875 - 0.588) * 10;
    V4 += ads.readADC_SingleEnded(3) * 0.0001875 * 8.0;
    delay(1);
  }
  V1 /= 10;
  V2 /= 10;
  V3 /= 10;
  V4 /= 10;

 

Link to post
Share on other sites

Felicitari pentru rezolvarea problemei, numai ca metoda folosita nu-i rotunjire, e mediere - calculezi media unui numar de masuratori (in cazul tau 10).

 

Stiu, teoria chbritului...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines