본문으로 바로가기

AppInventor

category IT Tech/Arduino 2019. 3. 5. 01:06
This post is about choosing color for the RGB LED light from the android app, I used slider to control the LED colors.


Circuit Diagram for common anode RGB LED:



Circuit Diagram for common cathode RGB LED:



components needed for this project:
Arduino Uno
RGB LED
Bluetooth Module
Connecting Wires
Breadboard 

Android app created using MIT app inventor, which is very simple, 3 sliders had created to assign values of primary colors RGB, when these sliders are moved these different colors are mixed and shown in the canvas, same color code will be send to the arduino. 

Android app: 



android app can be download from this link

Blocks to create Android app:




Arduino Program to control Common anode LED: 

#include <SoftwareSerial.h>

int bluetoothTx = 7;
int bluetoothRx = 8;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
 pinMode(3,OUTPUT); // blue pin of RGB LED
 pinMode(5,OUTPUT); // Green pin of RGB LED
 pinMode(6,OUTPUT); // Red pin of RGB LED

 digitalWrite(3,HIGH);
 digitalWrite(5,HIGH);
 digitalWrite(6,HIGH);
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int color1 = bluetooth.read();
    unsigned int color2 = bluetooth.read();
    unsigned int color = (color2 *256) + color1;
    Serial.println(color);
   
    if (color >= 1000 && color <1255){
    int blue = color;
    blue = map(blue, 1000,1255,0,255);
    int blue1 = 255-blue;
    analogWrite(6,blue1);
    Serial.println(blue1);
    delay(10);
    }
   
    if (color >=2000 && color <2255){
      int green = color;
      green = map(green,2000,2255,0,255);
      int green1 = 255 - green;
      analogWrite(5,green1);
      Serial.println(green1);
      delay(10);
    }
   
    if (color >=3000 && color < 3255){
      int red = color;
      red = map(red, 3000, 3255,0,255);
      int red1 = 255 - red;
      analogWrite(3,red1);
      Serial.println(red1);
      delay(10);
     }
  }
}


Arduino program for common cathode RGB LED:

#include <SoftwareSerial.h>

int bluetoothTx = 7;
int bluetoothRx = 8;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
 pinMode(3,OUTPUT); // blue pin of RGB LED
 pinMode(5,OUTPUT); // Green pin of RGB LED
 pinMode(6,OUTPUT); // Red pin of RGB LED

 digitalWrite(3,LOW);
 digitalWrite(5,LOW);
 digitalWrite(6,LOW);
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int color1 = bluetooth.read();
    unsigned int color2 = bluetooth.read();
    unsigned int color = (color2 *256) + color1;
    Serial.println(color);
   
    if (color >= 1000 && color <1255){
    int blue = color;
    blue = map(blue, 1000,1255,0,255);
    analogWrite(6,blue);
    Serial.println(blue);
    delay(10);
    }
   
    if (color >=2000 && color <2255){
      int green = color;
      green = map(green,2000,2255,0,255);
      analogWrite(5,green);
      Serial.println(green);
      delay(10);   
    }
   
    if (color >=3000 && color < 3255){
      int red = color;
      red = map(red, 3000, 3255,0,255);
      analogWrite(3,red);
      Serial.println(red);
      delay(10);
    }
  }
}


'IT Tech > Arduino' 카테고리의 다른 글

Arduino Serial LCD-1602 Shield V2.0  (0) 2019.03.04
Arduino 배열을 이용한 LED 제어  (0) 2019.03.04
아두이노 프로젝트 모음  (0) 2019.03.04
Arduino Pin Map  (0) 2019.03.04
Secrets of Arduino PWM  (0) 2019.03.04