Translate

Monitor DC Voltage Current (Tegangan dan Arus DC) serta RPM Generator Thingspeak

 Monitor DC Voltage Current (Tegangan dan Arus DC) serta RPM Generator Thingspeak


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan generator sebagai penghasil tegangan dan alat ini digunakan untuk memonitor tegangan dan arus dc yang dihasilkan oleh generator DC tersebut, untuk lebih jelasnya berikut adalah koding dan daftar komponennya.



a. Arduino Uno




b. Nodemcu ESP8266




c. Sensor Arus ACS712




d. Sensor Tegangan DC




e. Sensor RPM





f. Program Arduino Uno

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
SoftwareSerial RFID(4, 5); // RX and TX
LiquidCrystal_I2C lcd(0x27,16,2);

//id kartu55 = 620099C7D3
//id kartu95 = 040088F9FB

volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;

String Teks;
String NoKartu  ;  //No kartu RFID

int adcteg;
float tegangan;
int adcarus;
float v;
float arus;
int relay = 8;
boolean state=false;
char c;

int teganganx;
int arusx;
int rpmx;

void setup(){
  
Serial.begin(9600);
RFID.begin(9600);

attachInterrupt(0, rpm_fun, RISING);
half_revolutions = 0;
rpm = 0;
timeold = 0;
 
lcd.begin();  
lcd.clear();
lcd.noCursor();
pinMode(relay,OUTPUT);
digitalWrite(relay,HIGH);

}

void loop() {
lcd.setCursor(0,0);
lcd.print("Dekatkan Kartu");

while(RFID.available()>0){
delay(5);
c=RFID.read();
Teks += c;
}
if(Teks.length()>20){
Cek();

if(Teks == "620099C7D3"){
lcd.clear();
delay(1000);
Teks="";
proses();
}

Teks="";
}

}

void proses(){
     
adcteg = analogRead(A0);
tegangan = adcteg * (5.0 / 1023.0) * 4.8;

adcarus = analogRead(A1);
v = adcarus * (5.0 / 1023.0);
arus = (v - 2.5)/0.1;

detachInterrupt(0);  
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
attachInterrupt(0, rpm_fun, RISING);

lcd.setCursor(0,0);
lcd.print("V=");
lcd.print(tegangan);
lcd.print("  ");
lcd.setCursor(9,0);
lcd.print("R=");
lcd.print(rpm,DEC);
lcd.print("   ");
lcd.setCursor(0,1);
lcd.print("I= ");
lcd.print(arus);
lcd.print("   ");

teganganx = tegangan * 100;
arusx = arus * 100;
rpmx = rpm * 1;

Serial.print("*");
Serial.print(teganganx);
Serial.print(",");
Serial.print(arusx);
Serial.print(",");
Serial.print(rpmx);
Serial.println("#"); 

delay(1000);
proses();
}

void Cek()
{
Teks=Teks.substring(1,11);

lcd.setCursor(0,1);
lcd.print("ID: "+Teks);
delay(3000);
lcd.clear();
}

void rpm_fun()
{
   half_revolutions++;
}
 
 

g. Program Nodemcu ESP8266

#include <ThingSpeak.h>  
#include <SPI.h>
#include <ESP8266WiFi.h>

int temp;
int x = 5;
int y;
int counter;

int value1;
int value2;

float tegangan = 0;
float arus = 0;
float rpm = 0;

float datain1;
float datain2;
float datain3;

String dataIn;
String dt[10];
int i;
boolean parsing=false;

String apiKey = "HGJHGJHY787BNDFH";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";
const char* server = "api.thingspeak.com";

char ssid[] = "mywifihp";
char pass[] = "123456789";

WiFiClient client;

void setup()
{
  WiFi.begin(ssid, pass);
  dataIn="";
  // Debug console
  Serial.begin(9600);
}

void loop()
{

while(Serial.available()>0) {
//   dataIn="";
    char inChar = (char)Serial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}

if(parsing){
  parsingData();   
}

counter++;

if(counter > 10){
    counter = 0;
    kirimdata();
}

delay(1000);
}

void parsingData(){
int j=0;

//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");

//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]="";       //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}

datain1 = dt[0].toInt();
datain2 = dt[1].toInt();
datain3 = dt[2].toInt();

//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("\n");

//Serial.print("data 3 : ");
//Serial.print(dt[2].toInt());
//Serial.print("\n\n");

 tegangan = datain1 / 100.0;
 arus = datain2 / 100.0;
 rpm = datain3 / 1;

}

void kirimdata(){
   
if(client.connect(server, 80)){
    String postStr= apiKey;
    postStr += "&field1=";
    postStr += String(tegangan);
    postStr += "\r\n\r\n";

   client.print(String("GET ") + resource + apiKey + "&field1=" + tegangan + "&field2=" + arus + "&field3=" + rpm + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
   
    client.print("POST /update HTTP/1.1\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...");
  delay(15000);
  
}



h. VIDEO HASILNYA





No comments:

Post a Comment