Translate

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



No comments:

Post a Comment