BlueTooth Controlled LED via Arduino Board for cosplay Ideas

Hey guys I just want to demonstrate the possibility of using Bluetooth to control LEDs for future cosplays. Check out the youtube video below and shoot me questions at pandariot779@gmail.com

Links to items used:

Link to Youtube video:

——————————The Code ——————————

//Declare random variables

int ledPin = 3;
int state = 0;
int flag = 0;
int delayPeriod = 500;
int brightness = 0;
int fadeAmount = 5;

//on set up, arduino LED is off and ledPin is set to output
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600); // declare connection baudrate rate of Bluetooth Module
}

//when we are connected to bluetooth, flag is on
void loop() {

if(Serial.available() > 0){
state = Serial.read();
flag=0;
} ///initially sets flag state to zero in the loop and assigns state to BT command

if (state == ‘0’) {
digitalWrite(ledPin, LOW);
if(flag == 0){
flag = 1;
} ///if state is zero then ledPin is off
}

else if (state == ‘1’) {
digitalWrite(ledPin, LOW);
digitalWrite(ledPin, HIGH);
if(flag == 0){
flag = 1;
}///if state is 1 then ledPin is on
}

else if (state == ‘2’) {
delayPeriod = 500;
digitalWrite(ledPin, LOW);
digitalWrite(ledPin, HIGH);
delay(delayPeriod);
digitalWrite(ledPin,LOW);
delay(delayPeriod);
if(flag == 0){
flag = 1;
}///if state is 2 then ledPin blinks every second. Blink mode
}

else if (state == ‘3’) {
digitalWrite(ledPin, LOW);
digitalWrite(ledPin, HIGH);
delay(delayPeriod);
digitalWrite(ledPin,LOW);
delay(delayPeriod);
delayPeriod = delayPeriod + 100;
if (delayPeriod == 1000){
delayPeriod = 0;
if(flag == 0){
flag = 1;
}///if state is 3 then ledPin blinks every gradually. sleepy mode
}
}

else if (state == ‘4’) {
digitalWrite(ledPin, HIGH);
analogWrite(ledPin, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = – fadeAmount;
}
delay(30);
if(flag == 0){
flag = 1;
}///if state is 4 then ledPin dims gradually: fading out mode
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s