Monitor Tegangan dan Arus DC ESP32 THINGSPEAK
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan dan arus dc dengan menggunakan ESP32 dengan sensor yaitu ACS712 dan modul VDC. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Modul ESP32
b. Sensor Arus ACS712
c. Sensor Tegangan DC
d. Program Arduino IDE
#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
String apiKey = "678GFHGFGHF568GLA"; // Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";
const char *ssid = "wifihpku"; // replace with your wifi ssid and wpa2 key
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
WiFiClient client;
int dataadc1;
int dataadc2;
float tegangan;
float arus;
float arusdc;
void setup() {
lcd.begin();
lcd.noCursor();
lcd.clear();
Serial.begin(9600);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
dataadc1 = analogRead(35); //tegangan
tegangan = dataadc1 * (3.9 / 4095.0) * 4.8;
dataadc2 = analogRead(34); //arus
arus = dataadc2 * (3.5 / 4095.0);
arusdc = (arus - 2.5)/0.1;
if(arusdc < 0){
arusdc = 0;
}
lcd.setCursor(0,0);
lcd.print("V= ");
lcd.print(tegangan);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("I= ");
lcd.print(arusdc);
lcd.print(" ");
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(tegangan);
postStr += "\r\n\r\n";
client.print(String("GET ") + resource + apiKey + "&field1=" + tegangan + "&field2=" + arusdc + " 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(15000);
}
e.. VIDEO HASILNYA
No comments:
Post a Comment