Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bridge.h>
- #include <BridgeClient.h>
- #include <BridgeServer.h>
- #include <HttpClient.h>
- #include <ArduinoJson.h>
- BridgeServer _Server;
- // ===================================================
- // ** PowerCheck - DIVERTEKA (J.C.G.P.) ** v. 1.0
- // ===================================================
- //
- // -- variables and pins definition ------------------
- const int analogInPin = A0; // analog input pin
- int retardo = 2 ; // (tiempo (s.) entre visionados)
- float lectura,ff,pKW,iA,vV,vS,S_Ratio;
- // -- initialize serial comm & parameters ------------
- void setup() {
- Serial.begin(9600);
- digitalWrite(13, LOW);
- Bridge.begin();
- digitalWrite(13, HIGH);
- _Server.listenOnLocalhost();
- _Server.begin();
- S_Ratio = 36.5; // Sensor/ratio (mV/mA ) : 36.5
- vV = 110; // valor de tension a computar
- ff = 4.15; // freq. factor / (50Hz -> 5 / 60Hz -> 4.15)
- }
- // -- smooth read routine ----------------------------
- float smoothread(float fc){ // fc (factor corrector)
- int ni = 35; // n. de iteraciones => smooth
- // (ni) => rango 10 a 50 mejor promedio [smoothing]
- float retorno = 0.0;
- for (int x = 0; x< ni; x++){
- do { // espero paso por cero
- delayMicroseconds(100);
- } while (analogRead(0) != 0) ;
- delay (ff); // espera centro de ciclo
- delay (10); // estabilizacion CAD
- retorno = retorno +(analogRead(0)*fc);
- }
- return retorno / ni;
- }
- // -- main loop --------------------------------------
- void loop() {
- lectura = smoothread (1) / 1.41; // lectura (rms)
- vS = (lectura * 0.0048); // valor de C.A.D.
- iA = (lectura * S_Ratio)/1000; // Intensidad (A)
- pKW = (vV * iA); // Potencia (kW)
- Serial.print("\n" );
- Serial.print("\n================================" );
- Serial.print("\n *** PowerCheck - DIVERTEKA *** " );
- Serial.print("\n================================\n" );
- Serial.print("\n- Tension predefinida [V] --> " );
- Serial.print(vV,0);
- Serial.print("\n- Lectura del sensor [V] --> " );
- Serial.print(vS,3);
- Serial.print("\n- Intensidad calculada [A] --> " );
- Serial.print(iA,3);
- Serial.print("\n- Potencia calculada [kW] --> " );
- Serial.print(pKW,3);
- Serial.print("\n-------------------------------\n" );
- delay(retardo * 1000);
- BridgeClient client = _Server.accept();
- if (client) {
- StaticJsonBuffer<200> jsonBuffer;
- JsonObject& json = jsonBuffer.createObject();
- json["vS"] = vV;
- json["iA"] = validateValue(iA).toFloat();
- json["pKW"] = validateValue(pKW).toFloat();
- json["pKW"] = validateValue(pKW).toFloat();
- json["phKW"] = validateValue(pKW).toFloat() * 60;
- json.prettyPrintTo(client);
- client.stop();
- }
- }
- String validateValue(float value) {
- return String(abs(value), 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement