Created
September 22, 2017 20:33
-
-
Save gbrennon/bba8a7ea1a1d30780755e4de68d547d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int analogPin = A0; // potentiometer on educational boosterpack connected to analog pin 5 | |
| // outside leads to ground and ~3V | |
| int val = 0; // variable to store the value read | |
| float tensao = 0; | |
| float somaI, somaV,Irms,Vrms,V2rms,I2rms; | |
| float VOLT[800]; | |
| float AMP[800]; | |
| float teninst[800]; | |
| float corrinst[800]; | |
| int i; | |
| float somaInst; | |
| float soma; | |
| float FP, S, pot, Q; | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| } | |
| void loop() | |
| { | |
| somaI=0; | |
| somaV=0; | |
| somaInst=0; | |
| Serial.println("Retomando aquisição"); | |
| for(i=0;i<800;i++){ | |
| delayMicroseconds(20.8333); | |
| VOLT[i]=analogRead(A0); | |
| AMP[i]=analogRead(A1); | |
| } | |
| Serial.println("Carregando..."); | |
| for(i=0;i<800;i++){ | |
| corrinst[i]=(((AMP[i]*3.3)/4096) - 1.60)/5; // 5 voltas no TC | |
| teninst[i]=((VOLT[i]*3.3)/4096) - 1.60; | |
| somaInst = somaInst + ((teninst[i]*133.87084)*(corrinst[i]*24.6)); | |
| somaI = somaI + corrinst[i]*corrinst[i]; | |
| somaV=somaV+(teninst[i]*teninst[i]); | |
| } | |
| Irms=sqrt(somaI/800); | |
| Vrms=sqrt(somaV/800); | |
| V2rms=Vrms*133.87084; | |
| I2rms=(Irms*24.6); | |
| pot=-somaInst/800; | |
| S=V2rms*I2rms; | |
| FP=pot/S; | |
| Q=sqrt((S*S)-(pot*pot)); | |
| //val = analogRead(analogPin); | |
| //tensao = (val*3.3)/4096; | |
| // tensao = map(val, 0, 4096, 0, 3.3); | |
| Serial.println("###################"); | |
| Serial.print("Tensão = "); | |
| Serial.println(V2rms); | |
| Serial.print("Corrente = "); | |
| Serial.println(I2rms); | |
| Serial.print("Potencia Ativa = "); | |
| Serial.println(pot); | |
| Serial.print("Potencia Reativa = "); | |
| Serial.println(Q); | |
| Serial.print("Pot Aparente = "); | |
| Serial.println(S); | |
| Serial.print("Fator de Potência = "); | |
| Serial.println(FP); | |
| Serial.println("###################"); | |
| Serial.println(""); | |
| delay(5000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment