Selasa, 28 November 2017

dummy mini portable


bahan yg dibutuuhkan:
nodemcu
modul step up
powerbank
switch selector
kabel
opto pc817
resistor


rangkai seperti gambar dibawah ini.


masukkan kodiing d bawah ini:
#include <ESP8266WiFi.h>
#include <ModbusTCPSlave.h>
#include <Ticker.h>

//Settings IP Nodemcu
byte ip[]      = { 192, 168, 1, 186};
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[]  = { 255, 255, 255, 0 };

ModbusTCPSlave Mb;
Ticker Stop;

const int lampu =  2 ; 
const int CBclose =  0 ; 
const int CBopen =  4 ; 
const int Sclose =  13 ; 
const int Sopen =  15 ; 

boolean switch1 = false;
boolean switch2 = false;

void monitoring() {

///addres kontrol lampu 0
digitalWrite(lampu,Mb.MBHoldingRegister[0] );


switch1 = digitalRead(Sopen);
switch2 = digitalRead(Sclose);

 if (switch1 == true){
    digitalWrite(CBclose, HIGH);
    digitalWrite(CBopen, LOW);
  }
  else {
   
  }
 if (switch2 == true){
    digitalWrite(CBopen, HIGH);
    digitalWrite(CBclose, LOW);
     }
   
   

Mb.MBHoldingRegister[1]=digitalRead(Sclose);
Mb.MBHoldingRegister[2]=digitalRead(Sopen);

  }

void setup()
{
 pinMode(lampu, OUTPUT);
 pinMode(CBclose, OUTPUT);
 pinMode(CBopen, OUTPUT);
 pinMode(Sclose, INPUT);
 pinMode(Sopen, INPUT);
 digitalWrite(lampu, LOW);
 digitalWrite(CBclose, LOW);
 digitalWrite(CBopen, LOW);
 Serial.begin(115200);
 Mb.begin("nama_wifimu", "password_wipimu", ip, gateway, subnet);
 delay(100);

}

void loop()
{

  Mb.Run();
 Stop.attach_ms(35,monitoring);
 
}

Tidak ada komentar:

Posting Komentar

Cara membuat datalogger blynk di spreadsheet / googlesheet menggunakan akun versi Free

  silahkan video di atas. semoga bermanfaat. jika masih kurang jelas bisa kontak saya