Translate

Monitor Tegangan dan Arus DC (INA219) Thingspeak

Monitor Tegangan dan Arus DC (INA219) Thingspeak 

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan dan arus DC dengan sensor INA219 dan VDC modul. alat ini menggunakan mikrokontroller Nodemcu ESP8266 dan menggunakan server Thingspeak untuk monitor onlinenya.  untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema 



b. Program Arduino IDE

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <Adafruit_INA219.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

float busVoltage = 0;
float arusac = 0; // Measure in milli amps
float dayaac = 0;
float vac;
float arusdc;
float dayadc;
float vdc;
int adcteg;
float tegangan;
float k = 1.2;
float resistansi;
int cacah;
float Vdcaverage;
float Idcaverage;
float resivitas;

Adafruit_INA219 sensor219; // Declare and instance of INA219


WiFiClient client;
// ThingSpeak Settings
String apiKey = "87K76FHGFJKV4VVH";
const char *ssid = "hotspothpku";
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";

 
void setup() {
  Serial.begin(9600);
  sensor219.begin();
  lcd.clear();
  lcd.begin();
  lcd.noCursor();
  
  //setting ke online
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED){\
    delay(200);
    Serial.println(".");
    }
  Serial.println("");
  Serial.println("WiFi connected");

}
 
void loop() {

cacah++;
 
    sensor219.begin();
    busVoltage = sensor219.getBusVoltage_V();
    arusdc = sensor219.getCurrent_mA();
    arusdc = (arusdc / 10.0) * -1;
    
    adcteg = analogRead(A0);
    tegangan = (adcteg * (5.0 / 1023.0) * 4.8) - 3.1;

    Idcaverage = arusdc + Idcaverage;
    Vdcaverage = tegangan + Vdcaverage;
    
    if(cacah > 5){
    cacah = 0;  
    Idcaverage = (Idcaverage / 5.0) - 0.13 ;
    Vdcaverage = Vdcaverage / 5.0;
    resistansi = Vdcaverage / Idcaverage;
    resivitas = k * resistansi;
    
    lcd.setCursor(0,0);
    lcd.print("V= ");
    lcd.print(Vdcaverage);
    lcd.print("  ");
    lcd.setCursor(0,1);
    lcd.print("I= ");
    lcd.print(Idcaverage);
    lcd.print("  ");
    lcd.setCursor(0,2);
    lcd.print("Resiv= ");
    lcd.print(resivitas);
    lcd.print("  ");
    lcd.setCursor(0,3);
    lcd.print("Resis= ");
    lcd.print(resistansi);
    lcd.print("  ");
    
    kirim();
    
    Idcaverage = 0;
    Vdcaverage = 0;
    }

 
delay(200);   
}


void kirim(){
  
 if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
 
                      {
                           
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(Vdcaverage);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + Vdcaverage + "&field2=" + Idcaverage + "&field3=" + resistansi + "&field4=" + resivitas + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                                       
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                         
                             Serial.println(". Send to Thingspeak.");
                        }
                       
          client.stop();

          Serial.println("Waiting...");
 
  // thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(10000);
    
}



c. VIDEO HASILNYA




No comments:

Post a Comment