a. Nodemcu ESP8266
b. Sensor INA219
c. Sensor PZEM-004T
d. Sensor DC Voltage
e. Aplikasi Android
Note: pada bagian LINK tuliskan seperti berikut ini dan sesuai dengan ID thingspeak dan ID Write apikey pada website / akun thingspeak Anda. yang berwarna merah adalah ID akun thingspeak dan warna biru adalah ID Write apikey.
https://api.thingspeak.com/channels/1223445/feeds/last.json?api_key=5TGHLW6HZUPQH2TF
f. Program Arduino IDE
#include <Wire.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#include <Adafruit_INA219.h>
#include <SoftwareSerial.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(D7,D8); // D6, D5, (RX,TX) connect to TX,RX of PZEM
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 voltage;
float current;
float power;
Adafruit_INA219 sensor219; // Declare and instance of INA219
WiFiClient client;
// ThingSpeak Settings
String apiKey = "5TGHLW6HZUPQH2TF";
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();
//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() {
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
sensor219.begin();
busVoltage = sensor219.getBusVoltage_V();
arusdc = sensor219.getCurrent_mA();
arusdc = arusdc /1000.0;
//dayadc = busVoltage * (arusdc/1000);
adcteg = analogRead(A0);
tegangan = (adcteg * (5.0 / 1023.0) * 4.8) - 2.58;
dayadc = tegangan * arusdc;
Serial.print("VoltageAC: "); Serial.print(voltage); Serial.println("V");
Serial.print("CurrentAC: "); Serial.print(current); Serial.println("A");
Serial.print("PowerAC: "); Serial.print(power); Serial.println("W");
Serial.print("busVoltage: "); Serial.print(busVoltage); Serial.println("V");
Serial.print("VoltageDC: "); Serial.print(tegangan); Serial.println("V");
Serial.print("CurrentDC: "); Serial.print(arusdc); Serial.println("mA");
Serial.print("PowerDC: "); Serial.print(dayadc); Serial.println("W");
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(voltage);
postStr += "\r\n\r\n";
client.print(String("GET ") + resource + apiKey + "&field1=" + voltage + "&field2=" + current + "&field3=" + power + "&field4=" + tegangan + "&field5=" + arusdc + "&field6=" + dayadc + " 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);
}
g. VIDEO HASILNYA
No comments:
Post a Comment