Translate

Timer Counter Balapan Mini 4WD RACING TAMIYA

Timer Counter Balapan Mini 4WD RACING


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menghitung waktu dalam satuan detik dan milidetik, sehingga dapat diaplikasikan ke balapan mobil mini 4WD atau sejenisnya. untuk lebih jelasnya berikut adalah program dan komponennya.


a. Komponen




b. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h>   //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h>     //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "DejaVuSans9.h"
#include "Droid_Sans_12.h"
#include "Droid_Sans_16.h"
#include "DejaVuSansItalic9.h"
#include "Mono5x7.h"
#include "SystemFont5x7.h"

#define WAKTU_TAMPIL_JAM      10    //detik
#define WAKTU_TAMPIL_KALENDAR 5     //detik

#define DISPLAY_COLUMN_COUNT  2
#define DISPLAY_ROW_COUNT     1

#define PIXELS_PER_COLUMN  32
#define PIXELS_PER_ROW    16

DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;

char lineBuff[20];
char lineBuff2[20];

int lineA;
int lineB;
int lineC;
int mulai;
int seconds;
int cs;
long start_time = 0;
int lapa,lapb,lapc;

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}


void setup(void)
{
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
  dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
  Serial.begin(9600);
   //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
  Timer1.initialize( 1000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
  Timer1.attachInterrupt( ScanDMD );   //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI() 
  //clear/init the DMD pixels held in RAM
  dmd.clearScreen( true );
}


void loop(void)
{

//============================================
lineA = digitalRead(2);
lineB = digitalRead(3);
lineC = digitalRead(4);

if((lineA == 0)&&(lineB == 1)&&(lineC == 1)&&(mulai == 1)){
lapa++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapb++;
delay(100);
}

if((lineA == 1)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapa++;
lapb++;
delay(100);
}

if((lineA == 0)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapc++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapb++;
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapb++;
lapc++;
delay(100);
}

//=============================================
if(lapa > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasila();  
}

if(lapb > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilb();  
}

if(lapc > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilc();  
}

//=============================================
lineA = digitalRead(2);

if((lineA == 0)&&(mulai == 0)){
  delay(200);
  mulai = 1;
  start_time = millis();  
}  

if(mulai == 1){
seconds = (millis() - start_time) / 1000;
cs = ((millis() - start_time) / 10) % 100;;
}

//===========================================================================  
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 37,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, "%d/%d/%d ", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
//===========================================================================

}


void hasila(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " A", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasila();  
}


void hasilb(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " B", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilb();  
}


void hasilc(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " C", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilc();  
}




c. VIDEO HASILNYA




Arduino Smart Home

Arduino Smart Home 


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengendalikan beberapa device di peralatan rumah seperti halnya pintu / door lock, kipas, lampu dan lain-lain. alat ini menggunakan beberapa sensor untuk memonitoring kondisi didalam rumah seperti kondisi gas, api, dan yang lainya. untuk lebih jelasnya berikut adalah komponen dan programnya.



a. Komponen



 

b. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>
#include <Keypad.h>
#include <Adafruit_PN532.h>
#include "DHT.h"  //library dht11
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include <DS3231.h>
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd 16x2
LiquidCrystal_I2C lcd2(0x3E, 20, 4); //library i2c lcd 16x2
SoftwareSerial mySerial(10,11); // RX, TX
#define DHTPIN 28     // pin digital untuk dht11
#define DHTTYPE DHT11   // set dht11
#define trigPin 37
#define echoPin 35
DHT dht(DHTPIN, DHTTYPE);  //set dht11
// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK  (2)
#define PN532_MOSI (3)
#define PN532_SS   (4)
#define PN532_MISO (5)
#define IRQ   (2)
#define RESET (3)
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
//Adafruit_NFCShield_I2C nfc(IRQ, RESET);
int sw1 = A3;
int sw2 = A5;
int sw3 = A7;
int sw1x;
int sw2x;
int sw3x;
float h;
float t;
long duration, distance;
int mq6,mq3;
int suara;
int api;
int hujan;
int pir;
int ledm = 23;
int ledk = 25;
int ledh = 27;
long first;
int relaykipas1 = 31;
int relaykipas2 = 29;
int buzzer = 16;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
DS3231  rtc(SDA, SCL);
char keys[ROWS][COLS] = {
{'/', 'C', '-', '+'},
{'=', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'}
};
byte rowPins[ROWS] = {32,A14,A12,A10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A8,A6,A4,A2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {  
  pinMode(sw1,INPUT_PULLUP); 
  pinMode(sw2,INPUT_PULLUP); 
  pinMode(sw3,INPUT_PULLUP);        
  Serial.begin(9600);
  //Serial.println("Hello!");
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    //Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  //Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  //Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  //Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
  
  //Serial.println("Waiting for an ISO14443A Card ...");
        
  //Serial.begin(9600);
  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd 
  lcd2.begin(); //set lcd i2c
  lcd2.noCursor(); //biar gak ada cursor di lcd
  lcd2.clear(); //clear lcd 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(suara, INPUT);
  pinMode(api, INPUT);
  pinMode(hujan, INPUT);
  pinMode(pir, INPUT);
  pinMode(ledm, OUTPUT);
  pinMode(ledk, OUTPUT);
  pinMode(ledh, OUTPUT);
  digitalWrite(ledm,LOW);
  digitalWrite(ledk,HIGH);
  digitalWrite(ledh,LOW);
  pinMode(buzzer, OUTPUT);
  digitalWrite(buzzer,LOW);
  
  pinMode(relaykipas1, OUTPUT);
  pinMode(relaykipas2, OUTPUT);
  digitalWrite(relaykipas1,HIGH);
  digitalWrite(relaykipas2,HIGH);
      
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(10, 22, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(12, 14, 2022);   // Set the date to January 1st, 2014
  mySerial.begin(9600);
  mp3_set_serial(mySerial);  //set softwareSerial for DFPlayer-mini mp3 module
  delay(1);  //wait 1ms for mp3 module to set volume
  mp3_set_volume(30);  //volume 0-30
  inputkartu();
  inputpasswd();
  
}

void loop() {
customKey = customKeypad.getKey();
switch(customKey)
{
 case 'B':
 inputpasswd();
 break;
}
  
suara = digitalRead(18);
api = digitalRead(26);
hujan = digitalRead(24);
pir = digitalRead(30);
 mq6 = analogRead(A0);
 mq3 = analogRead(A1);
 
 h = dht.readHumidity();  //ambil data humidity
 t = dht.readTemperature();  //ambil data suhu c
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
sw1x = digitalRead(sw1);
sw2x = digitalRead(sw2);
sw3x = digitalRead(sw3);
lcd.setCursor(0,0);
lcd.print("LOGIN");
lcd2.setCursor(0,0);
lcd2.print("T/H:");
lcd2.print(t,0);lcd2.print("/");lcd2.print(h,0);lcd2.print(" ");
lcd2.print("S:");
lcd2.print(distance);lcd2.print("  ");
lcd2.setCursor(0,1);
lcd2.print("Q6:");lcd2.print(mq6);lcd2.print(" ");
lcd2.print("Q3:");lcd2.print(mq3);lcd2.print(" ");
lcd2.setCursor(0,2);
lcd2.print("S/A/H/P:");lcd2.print(suara);lcd2.print("/");lcd2.print(api);lcd2.print("/");lcd2.print(hujan);lcd2.print("/");lcd2.print(pir);
lcd2.setCursor(0,3);
lcd2.print(rtc.getTimeStr());
lcd2.print(" ");
lcd2.print(sw1x);
lcd2.print(sw2x);
lcd2.print(sw3x);
Serial.print("*");
Serial.print(t);
Serial.print(",");
Serial.print(h);
Serial.print(",");
Serial.print(distance);
Serial.print(",");
Serial.print(mq6);
Serial.print(",");
Serial.print(mq3);
Serial.print(",");
Serial.print(suara);
Serial.print(",");
Serial.print(api);
Serial.print(",");
Serial.print(hujan);
Serial.print(",");
Serial.print(pir);
Serial.println("#");
delay(1000);
}


void inputpasswd(){
lcd.setCursor(0,0);
lcd.print("INPUT PASSWD");
    
customKey = customKeypad.getKey();
  switch(customKey)
  {
  case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
    lcd.setCursor(0,1);
    first = first * 10 + (customKey - '0');
    lcd.print(first);
    break;
  case 'C':
      if(first == 1234){
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.print("BENAR");
      mp3_play(1);  //play music file 0001.mp3
      delay(10000);
      mp3_stop();
      digitalWrite(relaykipas1,LOW);
      digitalWrite(relaykipas2,LOW);
      lcd.clear();
      return;
     }
    first = 0;
    lcd.clear();
    break;
  }
inputpasswd();  
}


void inputkartu(void){
lcd.setCursor(0,0);
lcd.print("DEKATKAN KARTU");
   
 uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
    
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  
  if (success) {
    lcd.clear();
    // Display some basic information about the card
    //Serial.println("Found an ISO14443A card");
    //Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    //Serial.print("  UID Value: ");
    //nfc.PrintHex(uid, uidLength);
    
    if (uidLength == 4)
    {
      // We probably have a Mifare Classic card ... 
      uint32_t cardid = uid[0];
      cardid <<= 8;
      cardid |= uid[1];
      cardid <<= 8;
      cardid |= uid[2];  
      cardid <<= 8;
      cardid |= uid[3]; 
      //Serial.print("Seems to be a Mifare Classic card #");
      //Serial.println(cardid); //3495259931
      lcd.setCursor(0,0);
      lcd.print(cardid);
      delay(2000);
      
      if(cardid == 3495259931){
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.print("BENAR");
      digitalWrite(ledm,LOW);
      digitalWrite(ledk,LOW);
      digitalWrite(ledh,HIGH);
      digitalWrite(buzzer,HIGH);
      delay(100);
      digitalWrite(buzzer,LOW);
      delay(100);
      digitalWrite(buzzer,HIGH);
      delay(100);
      digitalWrite(buzzer,LOW);
      delay(2000);
      lcd.clear();
      return;
      }
      else{
      digitalWrite(ledm,HIGH);
      digitalWrite(ledk,LOW);
      digitalWrite(ledh,LOW); 
      digitalWrite(buzzer,HIGH);
      delay(100);
      digitalWrite(buzzer,LOW);
      delay(100);
      digitalWrite(buzzer,HIGH);
      delay(100);
      digitalWrite(buzzer,LOW);
      delay(100);
      digitalWrite(buzzer,HIGH);
      delay(100);
      digitalWrite(buzzer,LOW);      
      digitalWrite(ledm,LOW);
      digitalWrite(ledk,HIGH);
      digitalWrite(ledh,LOW);
      delay(2000); 
      }
    
    //Serial.println("");
  }
  }
  
inputkartu();  
}



c. Program NodeMCU ESP8266

#define BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

int temp;
int x = 5;
int y;

int value1;
int value2;

int t = 0;
int h = 0;
int distance = 0;
int mq6 = 0;
int mq3 = 0;
int suara = 0;
int api = 0;
int hujan = 0;
int pir = 0;

float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;
float datain7;
float datain8;
float datain9;

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

char auth[] = "jkjbgjhgauyfgc6756fghbjhbjhcvghaoih78";
char ssid[] = "wifihpku";
char pass[] = "123456789";

SimpleTimer timer;

void sendSensor()
{
 Blynk.virtualWrite(V1, t);
 Blynk.virtualWrite(V2, h);
 Blynk.virtualWrite(V3, distance);
 Blynk.virtualWrite(V4, mq6);
 Blynk.virtualWrite(V5, mq3);
 Blynk.virtualWrite(V6, suara);
 Blynk.virtualWrite(V7, api);
 Blynk.virtualWrite(V8, hujan);
 Blynk.virtualWrite(V9, pir);
 delay(1000);
}

void setup()
{  
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}

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

if(parsing){
  parsingData();
    
  Blynk.run();
  timer.run();
}

}


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();
datain4 = dt[3].toInt();
datain5 = dt[4].toInt();
datain6 = dt[5].toInt();
datain7 = dt[6].toInt();
datain8 = dt[7].toInt();
datain9 = dt[8].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 4 : ");
Serial.print(datain4);
Serial.print("\n");
Serial.print("data 5 : ");
Serial.print(datain5);
Serial.print("\n");
Serial.print("data 6 : ");
Serial.print(datain6);
Serial.print("\n");
Serial.print("data 7 : ");
Serial.print(datain7);
Serial.print("\n");
Serial.print("data 8 : ");
Serial.print(datain8);
Serial.print("\n");
Serial.print("data 9 : ");
Serial.print(datain9);
Serial.print("\n");

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

t = datain1 / 1;
h = datain2 / 1;
distance = datain3 / 1;
mq6 = datain4 / 1;
mq3 = datain5 / 1;
suara = datain6 / 1;
api = datain7 / 1;
hujan = datain8 / 1;
pir = datain9 / 1;
}



d. VIDEO HASILNYA





Pasien Monitor (Suhu Tubuh, Bpm, SpO2) Server Thingspeak

Pasien Monitor (Suhu Tubuh, Bpm, SpO2) Server Thingspeak

          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur suhu tubuh dan Bpm - SpO2 dengan menggunakan nodemcu esp8266, data yang didapat lalu dikirimkan ke server Thingspeak. untuk lebih jelasnya berikut adalah komponen dan programnya


a. Komponen


b. Program Arduino IDE

#include <Wire.h>
#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MLX90614.h>  
#include <MAX30100_PulseOximeter.h>
#define REPORTING_PERIOD_MS 5000
#include "MAX30100.h" //library sensor

LiquidCrystal_I2C lcd(0x27,16,2); //library lcd

MAX30100* pulseOxymeter;   //library

int cacah; //membuat variabel
int spo;
float bpm;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

float TargetC;
int dataadc;
int suhunya;
int bpmku;
int counter;

PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";
void onBeatDetected()
{
//    Serial.println("Beat!");
}

int pinreset = D6;

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

void setup() {
Wire.begin();
mlx.begin();
Serial.begin(9600);
lcd.begin();
lcd.clear();
pinMode(pinreset,OUTPUT);
digitalWrite(pinreset,HIGH);

//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");

 //Serial.print("Initializing pulse oximeter..");
    if (!pox.begin()) {
        //Serial.println("FAILED");
        for(;;);
    } else {
        //Serial.println("SUCCESS");
    }
    
pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop(){
 
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

    bpm = pox.getHeartRate();
    spo = pox.getSpO2();
    bpmku = bpm;
       
    lcd.setCursor(0,1);
    lcd.print("B/S:");
    lcd.print(pox.getHeartRate());
    lcd.print("/");
    lcd.print(pox.getSpO2());
    lcd.print("     ");
       
    tsLastReport = millis();
}

mlx.begin();
TargetC = mlx.readObjectTempC();
suhunya = TargetC;

lcd.setCursor(0,0);
lcd.print("T: ");
lcd.print(suhunya);
lcd.print(" C   ");

if((bpm > 75)&&(bpm < 110)&&(spo > 95)&&(spo < 100)&&(suhunya > 33)&&(suhunya < 40)){
   
if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {
                           
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(bpm);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + bpm + "&field2=" + spo + "&field3=" + suhunya + " 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...");
delay(10000);
}

}



c.VIDEO HASILNYA




Deteksi Warna RGB TCS3200 Nodemcu WIFI IP Local

Deteksi Warna RGB TCS3200 Nodemcu WIFI IP Local 


        Pada kesempatan kali ini saya akan menjelakan mengenai bagaimana cara membuat sebuah alat yang dapat menampilkan nilai warna yaitu RGB dengan menggunakan wifi, alat ini menggunakan sensor TCS3200 dan Nodemcu sebagai mikrokontrollernya. untuk lebih jelasnya berikut adalah program dan komponennya


a. Komponennya




b. Program Arduino IDE

#include<Wire.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // change your I2C ADDRESS HERE EXAMPLE 0x3F

const char *ssid = "TP-Link"; // Enter your WiFi name
const char *password = "123456789";  // Enter WiFi password

WiFiServer server(80);

const int s0 = D3;  
const int s1 = D4;  
const int s2 = D5;  
const int s3 = D6;  
const int out = D7;   

int red = 0;  
int green = 0;  
int blue = 0;
int redcolor= 0;
int greencolor= 0;
int bluecolor= 0;
int yellowcolor= 0;
int color= 0;


void setup()   
{  

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();

 // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

  pinMode(s0, OUTPUT);  
  pinMode(s1, OUTPUT);  
  pinMode(s2, OUTPUT);  
  pinMode(s3, OUTPUT);  
  pinMode(out, INPUT);  
  digitalWrite(s0, HIGH);  
  digitalWrite(s1, HIGH);  
}  

void loop()
{  

 // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

 
  digitalWrite(s2, LOW);  
  digitalWrite(s3, LOW);  
  //count OUT, pRed, RED  
  red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  

  lcd.setCursor(0,0);
  lcd.print("R:");
  lcd.print(red);
  lcd.print("");
 
  digitalWrite(s3, HIGH);  
  //count OUT, pBLUE, BLUE  
  blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  

  lcd.print("B:");
  lcd.print(blue);
  lcd.print("");
 
  digitalWrite(s2, HIGH);  
  //count OUT, pGreen, GREEN  
  green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

  lcd.print("G:");
  lcd.print(green);
  lcd.print("     ");

 // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Refresh: 1");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
   
  client.println("<center>");
  client.println("<h1>");
  client.println("DETEKSI WARNA");
  client.println("</h1>");
   
  client.println("<h3>");
   
  client.println("R = ");
  client.println(red);
  client.println("<br>");
 
  client.println("B = ");
  client.println(blue);
  client.println("<br>");
 
  client.println("G = ");
  client.println(green);
  client.println("<br>");
 
  client.println("</h3>");  
  client.println("</center>");
  client.println("</html>");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

 delay(1000);

}




c. VIDEO HASILNYA



Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino

Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan kecepatan motor AC dengan menggunakan modul dimmer zero crossing 4A dan Arduino. jadi alat ini hanya mengendalikan kecepatan motor dan juga terdapat pemilihan kecepatan dengan menggunakan tombol, selain itu juga bisa disetting waktu lama putar motornya dari 1 - 30 menit. untuk lebih jelasnya berikut adalah koding dan komponennya.  



a. Arduino Uno dan Modul Zero Crossing 4A




b. Program Arduino IDE

#include <Wire.h>
#include <RBDdimmer.h>//
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd 16x2

#define outputPin  9 
#define zerocross  2 // for boards with CHANGEBLE input pins

//dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero

int outVal = 0;
int btset = A0;
int btok = A3;
int btup = A2;
int btdown = A1;

int btsetx;
int btokx;
int btupx;
int btdownx;
int rpmnya = 1000;
int waktunya = 1;
long watufix;
int detik = 0;
int startrpm;

float kp = 1.15;
float ki = 0.67;
float kd = 0.15;

float p,i,d,suhu,pid;
float error,errorx,sumerr;
float sp;
int buzzer = 7;


void setup() {
  Serial.begin(9600);
  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd 
  pinMode(btset,INPUT_PULLUP);  
  pinMode(btok,INPUT_PULLUP);  
  pinMode(btup,INPUT_PULLUP);  
  pinMode(btdown,INPUT_PULLUP);  
  pinMode(9,OUTPUT);    
  pinMode(buzzer,OUTPUT);   
  digitalWrite(buzzer,LOW);
  setrpm();
  setwaktu();
  mulai();
}


void loop() 
{  
digitalWrite(9,LOW);
dimmer.begin(NORMAL_MODE, OFF);

lcd.setCursor(0,0);
lcd.print("SELESAI");

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

if(btsetx == 0){
delay(200);
setrpm();
setwaktu();
detik = 0;
mulai(); 
}

}


void setrpm(){

digitalWrite(9,LOW);
dimmer.begin(NORMAL_MODE, OFF);

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0);
lcd.print("SET RPM: ");
//lcd.print(btsetx);
//lcd.print(btupx);
//lcd.print(btdownx);
//lcd.print(btokx);
lcd.setCursor(0,1);
lcd.print(rpmnya);
lcd.print("  ");  

if(btupx == 0){
delay(200);
rpmnya = rpmnya + 1000;  
}

if(btdownx == 0){
delay(200);
rpmnya = rpmnya - 1000;  
}

if(rpmnya < 1000){
  rpmnya = 4000;
}

if(rpmnya > 4000){
  rpmnya = 1000;
}

if(btokx == 0){
  delay(2000);
  lcd.clear();
  return;
}

setrpm();  
}



void setwaktu(){

digitalWrite(9,LOW);
dimmer.begin(NORMAL_MODE, OFF);

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

lcd.setCursor(0,0);
lcd.print("SET WAKTU: ");
lcd.setCursor(0,1);
lcd.print(waktunya);
lcd.print(" MENIT  ");  

if(btupx == 0){
delay(200);
waktunya = waktunya + 1;  
}

if(btdownx == 0){
delay(200);
waktunya = waktunya - 1;  
}

if(waktunya < 1){
  waktunya = 30;
}

if(waktunya > 30){
  waktunya = 1;
}

if(btokx == 0){
  delay(1000);
  lcd.clear();
  return;
}

setwaktu();  
}


void mulai(){
  
dimmer.begin(NORMAL_MODE, ON);

//analogWrite(10,pid);
 
  error = sp - rpmnya;
  p = error * kp;
  sumerr = error + errorx;
  i = ki * sumerr;
  d = kd * (error - errorx) ;
  pid = p + i + d;

  if(pid < 1){
  pid = 0;
  }
 
  if(pid > 255){
  pid = 255;
  }

lcd.setCursor(0,0);
lcd.print("RPM: ");
lcd.print(startrpm);
lcd.print("    ");
lcd.setCursor(0,1);
lcd.print("Time: 0:");  
lcd.print(waktunya);
lcd.print(":");
lcd.print(detik);
lcd.print("  ");

detik--;

if(detik < 0){
  detik = 59;
  waktunya--;
}

if(waktunya < 0){
delay(1000);
lcd.clear();
digitalWrite(buzzer,HIGH);
delay(5000);
digitalWrite(buzzer,LOW);
return;  
}

if(rpmnya == 1000){
outVal = 30; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%); 
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(990,1010);
}

if(rpmnya == 2000){
outVal = 50; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%); 
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(1990,2010);
}

if(rpmnya == 3000){
outVal = 70; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%); 
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(2990,3010);
}

if(rpmnya == 4000){
outVal = 90; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%); 
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(3990,4010);
}

delay(1000);
mulai();  
}




c. VIDEO HASILNYA







Monitor Kemiringan Menggunakan IP Local Sensor GY-521 (MPU-6050)

Monitor Kemiringan Menggunakan IP Local Sensor GY-521 (MPU-6050) 

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur tingkat kemiringan suatu dataran atau benda dengan menggunakan sensor GY-521 / MPU-6050 dan mikrokontroller yang dipakai yaitu wemos D1 mini. alat ini bisa memonitor tingkat kemiringan dengan menggunakan IP Address local sehingga membutuhkan suatu router sebagai medianya pengiriman sinyalnya dikarenakan menggunakan wifi. untuk lebih jelasnya berikut adalah komponen dan kodingnya.


a. Komponen

 

b. Program Arduino IDE

#include<Wire.h>
#include <ESP8266WiFi.h>
#include <EEPROM.h>

const char *ssid = "TP-Link_65A4"; // Enter your WiFi name
const char *password = "";  // Enter WiFi password

//int ledPin = D0;
WiFiServer server(80);

//I2C Address for MPU6050
const int MPU=0x68;  // Can be 0x69 if AD0 Pin is True (VCC)

//Variables for raw values from MPU ADC
int AcX,AcY,AcZ,GyX,GyY,GyZ;
int16_t Tmp;

int minVal=0;
int maxVal=65536; //2^16 levels from MPU6050 ADC

int offsetTemp = 35; // from MPU datasheet
int offsetTempLevels = 521; // from MPU datasheet

void setup() {
 
  Serial.begin(9600); // Begin Serial communication
  Wire.begin();
  Wire.beginTransmission(MPU); // begin transmission with MPU address
  Wire.write(0x6B);
   
  //Start MPU-6050 sensor
  Wire.write(0);
  Wire.endTransmission(true);    

  delay(10);

//  pinMode(ledPin, OUTPUT);
//  digitalWrite(ledPin, LOW);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

 Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  //Get data from Sensor (14 consecutive bytes)
  Wire.requestFrom(MPU,14,true);  
  //Read data byte by byte (16 bits is 8 bits | 8 bits)
  //Each value is composed by 16 bits (2 bytes)
  GyX=Wire.read()<<8|Wire.read();  //0x3B (GYRO_XOUT_H) & 0x3C (GYRO_XOUT_L)     
  GyY=Wire.read()<<8|Wire.read();  //0x3D (GYRO_YOUT_H) & 0x3E (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  //0x3F (GYRO_ZOUT_H) & 0x40 (GYRO_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  //0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  AcX=Wire.read()<<8|Wire.read();  //0x43 (ACCEL_XOUT_H) & 0x44 (ACCEL_XOUT_L)
  AcY=Wire.read()<<8|Wire.read();  //0x45 (ACCEL_YOUT_H) & 0x46 (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  //0x47 (ACCEL_ZOUT_H) & 0x48 (ACCEL_ZOUT_L)

  //Adapts to range from 0 to 2000 m/s^2
  AcX = map(AcX,minVal,maxVal,2000,0);
  AcY = map(AcY,minVal,maxVal,2000,0);
  AcZ = map(AcZ,minVal,maxVal,2000,0);
 
  //Adapts to range from -180º to 180º
  int xAng = map(GyX,minVal,maxVal,180,-180);
  int yAng = map(GyY,minVal,maxVal,180,-180);
  int zAng = map(GyZ,minVal,maxVal,180,-180);
   
  //Send X axis accelerometer value for serial monitor
  Serial.print("AcX = "); Serial.print(AcX);
   
  //Send Y axis accelerometer value for serial monitor
  Serial.print(" | AcY = "); Serial.print(AcY);

  //Send Z axis accelerometer value for serial monitor
  Serial.print(" | AcZ = "); Serial.print(AcZ);


  //Send Temperature value for serial
  //Calculates the temperature given the datasheet values (ºC)
  // 340 is the number of levels per ºC (from datasheet)
  Serial.print(" | Tmp = "); Serial.print(float(Tmp + offsetTempLevels)/340 + offsetTemp);   
  //Send X axis gyroscope angle value for serial monitor
  Serial.print(" | GyX = "); Serial.print(xAng);   
  //Send Y axis gyroscope angle value for serial monitor  
  Serial.print(" | GyY = "); Serial.print(yAng);   
  //Send Z axis gyroscope angle value for serial monitor
  Serial.print(" | GyZ = "); Serial.println(zAng);
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Refresh: 1");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
   
  client.println("<center>");
  client.println("<h1>");
  client.println("Monitoring Kemiringan");
  client.println("</h1>");
   
  client.println("<h3>");
   
  client.println("X = ");
  client.println(AcX);
  client.println("<br>");
 
  client.println("Y = ");
  client.println(AcY);
  client.println("<br>");
 
  client.println("Z = ");
  client.println(AcZ);
  client.println("<br>");
 
  client.println("</h3>");
  client.println("<a href = \"/?lighton\"\"><input type = 'button' value = 'DATA LOGGER' ></a>");
  client.println("<a href=" " download>");  
  client.println("</center>");
  client.println("</html>");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

  delay(300);

}


c. VIDEO HASILNYA


Monitor DAYA (Arus Tegangan) AC dan DC Thingspeak + Monitor Android

Monitor DAYA (Arus Tegangan) AC dan DC Thingspeak + Monitor Android


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur 6 buah parameter yaitu tegangan AC, arus AC, Daya AC, Tegangan DC, Arus DC dan Daya DC. data tersebut dikirimkan ke server thingspeak lalu akan dibaca oleh aplikasi android. untuk lebih jelasnya berikut adalah koding dan komponennya.

 

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


Monitor Tegangan Arus AC Sensor PZEM-004T NODEMCU ESP8266

Monitor Tegangan Arus AC Sensor PZEM-004T NODEMCU ESP8266

          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan dan arus AC menggunakan sensor PZEM-004T dengan Nodemcu ESP8266. alat ini bisa dikoneksikan ke internet (IOT) dengan menggunakan wifi. untuk lebih jelasnya berikut adalah koding dan komponennya.

 

a. Komponen


b. Cara Setting Nodemcu ESP8266



c. Program Arduino IDE

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <PZEM004Tv30.h>
 
PZEM004Tv30 pzem(D7,D8);  // D6, D5, (RX,TX) connect to TX,RX of PZEM

float voltage;
float current;
float power;
 

void setup() {
  Serial.begin(9600);  
}
 
void loop() {
 
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
   
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");

delay(1000);
}


 

d. VIDEO HASILNYA

 

Monitor Suhu MLX90614 dan Jarak HC-SRF04 OLED Nodemcu ESP8266 Arduino

Monitor Suhu MLX90614 dan Jarak HC-SRF04 OLED Nodemcu ESP8266 Arduino

        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk monitoring suhu dan jarak dengan menggunakan sensor MLX90614 dan HC-SRF04 dengan interface menggunakan OLED display dan mikrokontroller menggunakan Nodemcu ESP8266. untuk lebih jelasnya berikut adalah komponen dan kodingnya.

 

a. Komponen


b. Program Arduino IDE

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <Adafruit_MLX90614.h>  
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "OakOLED.h"
 
#define trigPin D7  //pin trigger hcsrf04
#define echoPin D6  //pin echo

OakOLED oled;
 
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
 
long duration, distance;
float TargetC;

 
void setup()
{
    Serial.begin(115200);
    oled.begin();
    oled.display();
    mlx.begin();
    
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);

}
 
void loop()
{
    
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 
  mlx.begin();
  TargetC = mlx.readObjectTempC();
    
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(1);
  oled.setCursor(0, 0);
  oled.print("Jarak: ");
  oled.println(distance);

  oled.setTextSize(1);
  oled.setTextColor(1);
  oled.setCursor(0, 16);
  oled.print("Suhu: ");
  oled.println(TargetC);
  oled.display();

delay(200);   
}



c. VIDEO HASILNYA


Pertamini Air Pembayaran Pakai Kode Token

Pertamini Air Pembayaran Pakai Kode Token

        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengisi air dengan menggunakan kode token, jadi alat ini seperti halnya pertamini yang mana bukan bensin yang dialirkan melainkan air sehingga client atau pembeli harus membeli kode token dulu seperti halnya listrik PLN yang menggunakan kode token. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema

 

 

b. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd 16x2

int relay = 11;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
long passwd = 0;
long isiku;
long beli;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {3,4,5,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7,8,9,10}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;

float calibrationFactor = 4.5;

volatile byte pulseCount;  

unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
long totalMilliLitres;
long totalLitres;

unsigned long oldTime;
long dataku = 0;
unsigned long saldo;
int mark,mark1,mark2;


void setup()
{
 
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);  
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
 
  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd
  Serial.begin(9600);   // Initiate a serial communication
}

void loop()
{

lcd.setCursor(0,1);
lcd.print("Token: ");
lcd.print(saldo);
lcd.print(" L  ");

  if((millis() - oldTime) > 1000)    // Only process counters once per second
  {

    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
    totalLitres = totalMilliLitres / 1000;   
    frac = (flowRate - int(flowRate)) * 10;
     
    // Print the cumulative total of litres flowed since starting
    lcd.setCursor(0,0);
    lcd.print("Pakai: ");             // Output separator
    lcd.print(totalLitres);
    lcd.print(" L  ");

    pulseCount = 0;
    
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

  if(totalLitres >= saldo){
    digitalWrite(relay, HIGH); //off
    saldo = 0;
    }

    if(totalLitres < saldo){
    digitalWrite(relay, LOW); //on
    }
    
  }

   
customKey = customKeypad.getKey();
           
 if(customKey == '*'){
 lcd.clear();
 delay(1000);
 beli = 0;
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  totalLitres = 0;
  oldTime           = 0;
 token();
 }
    
delay(200);    
}


void token(){
lcd.setCursor(0,0);
lcd.print("Kode Token");

  customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
    {
     beli = beli * 10 + (customKey - '0');
     lcd.setCursor(0,1);
     lcd.print(beli);
    }
                   
    if(customKey == 'C'){
    lcd.clear();    
    beli = 0;
    }

    if(customKey == '#'){     
       lcd.clear();
       delay(1000);


     if((beli == 12345)&&(mark == 0)){
        saldo = 10;
        mark = 1;
        return;
      }

    if((beli == 12234)&&(mark1 == 0)){
        saldo = 7;
        mark1 = 1;
        return;
     }

    if((beli == 54321)&&(mark2 == 0)){
        saldo = 5;
        mark2 = 1;
        return;
     }

     beli = 0;
     return;    
    }
    
token();  
}


 
void pulseCounter()
{
  pulseCount++;
}



c. VIDEO HASILNYA