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