Translate

Deteksi RGB Warna dan Intensitas Cahaya (LUX) ONLINE Blynk sensor TCS34725 Wemos d1 ARDUINO

Deteksi RGB Warna dan Intensitas Cahaya (LUX) ONLINE Blynk sensor TCS34725 Wemos d1 ARDUINO


            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mendeteksi warna dengan media ONLINE menggunakan aplikasi Blynk. variabel yang digunakan untuk mendeteksi yaitu lux, R, G dan B. Alat ini bisa monitor secara jarak jauh karena menggunakan IOT atau internet sehingga kedua device haruslah saling terhubung ke internet. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Wemos D1




b. Sensor warna TCS34725

  




c. Program Arduino IDE

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

uint16_t r, g, b, c, colorTemp, lux;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "EWbWghgfhiouiuoiLKJghgjklkhsxxgfdg";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "myhotspot";
char pass[] = "123456789";

/* Example code for the Adafruit TCS34725 breakout library */

/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */

/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

SimpleTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{

 Blynk.virtualWrite(V5, r);
 Blynk.virtualWrite(V6, g);
 Blynk.virtualWrite(V7, b);
// Blynk.virtualWrite(V6, c);
// Blynk.virtualWrite(V7, colorTemp);
 Blynk.virtualWrite(V8, lux);
 delay(1000);

}

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

Blynk.begin(auth, ssid, pass);

// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);

if (tcs.begin()) {
//Serial.println("Found sensor");
} else {
//Serial.println("No TCS34725 found ... check your connections");
while (1);
}

// Now we're ready to get readings!
}

void loop(void) {

tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);

if((r > 2000)&&(r < 3000)&&(g > 3000)&&(g < 5000)&&(b > 3000)&&(b < 4000)){
  Blynk.notify("Warna Putih");
  }

if((r > 100)&&(r < 600)&&(g > 100)&&(g < 800)&&(b > 100)&&(b < 800)){
  Blynk.notify("Warna Hitam");
  }
 
/*
Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
*/

  Blynk.run();
  timer.run();

}




d. Interface Blynk






e. VIDEO HASILNYA
 








No comments:

Post a Comment