Skocz do zawartości

Pomiaru prądu - brak wyniku na wyświetlaczu


robunio007

Pomocna odpowiedź

Witam,

Utworzyłem układ, aby móc mierzyć prąd w obwodzie. Znalazłem taki kod programu. Wartości jakieś za duże. Program mi nie zwraca wartości do wyświetlacza.

Gdzie jest błąd programu?

To są wartości mierzonego prądu.

Żarówka ma moc 3,5 W , więc prąd powinien być w granicach 0,015 A

 

Volts Peak : 4.995
Current Through Resistor (Peak) : 24.976 mA Peak to Peak
Current Through Resistor (RMS) : 17.658 mA RMS
Current Through Wire : 17657.740 mA RMS

Volts Peak : 4.995
Current Through Resistor (Peak) : 24.976 mA Peak to Peak
Current Through Resistor (RMS) : 17.658 mA RMS
Current Through Wire : 17657.740 mA RMS

Volts Peak : 4.995
Current Through Resistor (Peak) : 24.976 mA Peak to Peak
Current Through Resistor (RMS) : 17.658 mA RMS
Current Through Wire : 17657.740 mA RMS

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);


int sensorTA12 = A0; // Analog input pin that sensor is attached to

float nVPP;   // Voltage measured across resistor
float nCurrThruResistorPP; // Peak Current Measured Through Resistor
float nCurrThruResistorRMS; // RMS current through Resistor
float nCurrentThruWire;     // Actual RMS current in Wire

void setup() 
 {
    // initialize the LCD
  lcd.begin();
lcd.print("I = ");
  // Turn on the blacklight and print a message.
  lcd.backlight();
   Serial.begin(9600); 
   pinMode(sensorTA12, INPUT);
 }
 
 
 void loop() 
 {
   
   
   nVPP = getVPP();
   
   /*
   Use Ohms law to calculate current across resistor
   and express in mA 
   */
   
   nCurrThruResistorPP = (nVPP/200.0) * 1000.0;
   
   /* 
   Use Formula for SINE wave to convert
   to RMS 
   */
   
   nCurrThruResistorRMS = nCurrThruResistorPP * 0.707;
   
   /* 
   Current Transformer Ratio is 1000:1...
   
   Therefore current through 200 ohm resistor
   is multiplied by 1000 to get input current
   */
   
   nCurrentThruWire = nCurrThruResistorRMS * 1000;

   
   Serial.print("Volts Peak : ");
   Serial.println(nVPP,3);
 
   
   Serial.print("Current Through Resistor (Peak) : ");
   Serial.print(nCurrThruResistorPP,3);
   Serial.println(" mA Peak to Peak");
   
   Serial.print("Current Through Resistor (RMS) : ");
   Serial.print(nCurrThruResistorRMS,3);
   Serial.println(" mA RMS");
   
   Serial.print("Current Through Wire : ");
   Serial.print(nCurrentThruWire,3);
   Serial.println(" mA RMS");
   
   Serial.println();
    
   
   

 }


 /************************************ 
In order to calculate RMS current, we need to know
the peak to peak voltage measured at the output across the
200 Ohm Resistor

The following function takes one second worth of samples
and returns the peak value that is measured
 *************************************/
 
 
float getVPP()
{
  float result;
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
   uint32_t start_time = millis();
   while((millis()-start_time) < 1000) //sample for 1 Sec
   {
       readValue = analogRead(sensorTA12);
       // see if you have a new maxValue
       if (readValue > maxValue) 
       {
           /*record the maximum sensor value*/
           maxValue = readValue;
       }
   }
   
   // Convert the digital data to a voltage
   result = (maxValue * 5.0)/1024.0;
  
   return result;
 }

 

Edytowano przez Gieneq
Zachęcam do korzystania z bloku kodu programu
Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.