Muhammad Fauzi Robbani
Published © CC BY

Kontrol Warna Lampu Menggunakan Android

Merubah warna lampu RGB LED sesuai warna yang kita inginkan menggunkan Android.

IntermediateFull instructions provided24 hours826
Kontrol Warna Lampu Menggunakan Android

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1
Modul Bluetooth LE [ HM-10 ]
×1
RGB LED Strip WS2811
×1

Software apps and online services

Arduino IDE
Arduino IDE
Android Studio
Android Studio

Story

Read more

Schematics

FULL

Skema wxviaugvyy

Bluetooth Schema

Skema3 4pumtbysji

LED Schema

Skema2 58phwhurae

Code

Arduino Sourcode

C/C++
#include <SoftwareSerial.h>
#include <Wire.h>
SoftwareSerial mySerial(10,11); //Define PIN11 & PIN12 as RX and TX pins

int PIN_RED = 3;
int PIN_GREEN = 5;
int PIN_BLUE = 6;

String RGB = ""; 
String RGB_Previous = "255.255.255"; 
String ON = "ON"; 
String OFF = "OFF"; 
boolean RGB_Completed = false;
 
void setup() {
  pinMode (PIN_RED, OUTPUT);
  pinMode (PIN_GREEN, OUTPUT);
  pinMode (PIN_BLUE, OUTPUT);
  Serial.begin(9600); 
  mySerial.begin(9600);
  RGB.reserve(30);
}
 
void loop() {

  while(mySerial.available()){
    char ReadChar = (char)mySerial.read();
 
    if(ReadChar == ')'){
      RGB_Completed = true;
    }else{
       RGB += ReadChar;
    }
  }
  
  if(RGB_Completed){
 
      Serial.print("RGB:");
      Serial.print(RGB);
      Serial.print("     PreRGB:");
      Serial.println(RGB_Previous);
      
      if(RGB==ON){
          RGB = RGB_Previous; 
          Light_RGB_LED();
      }else if(RGB==OFF){
          RGB = "0.0.0"; 
          Light_RGB_LED();
      }else{
          Light_RGB_LED();   
          RGB_Previous = RGB;     
      }
      RGB = "";
      RGB_Completed = false;      
  } 
} 
 
void Light_RGB_LED(){
 
  int SP1 = RGB.indexOf(' ');
  int SP2 = RGB.indexOf(' ', SP1+1);
  int SP3 = RGB.indexOf(' ', SP2+1);
  String R = RGB.substring(0, SP1);
  String G = RGB.substring(SP1+1, SP2);
  String B = RGB.substring(SP2+1, SP3);

  Serial.print("R=");
  Serial.println( constrain(R.toInt(),0,255));
  Serial.print("G=");
  Serial.println(constrain(G.toInt(),0,255));
  Serial.print("B=");
  Serial.println( constrain(B.toInt(),0,255));
 
  analogWrite(PIN_RED,  (R.toInt()));
  analogWrite(PIN_GREEN, (G.toInt()));
  analogWrite(PIN_BLUE,  (B.toInt()));
 
}

Credits

Muhammad Fauzi Robbani

Muhammad Fauzi Robbani

0 projects • 1 follower

Comments

Add projectSign up / Login