Giter VIP home page Giter VIP logo

androidledcontrol's Introduction

AndroidLEDcontrol

Control LED from android using Bluetooth module and Arduino board

This app allows you to: Detect nearby bluetooth devices Pair to a bluetooth device (PIN code authentication might be required) Light up / Turn off all LEDs at once control the brightness of each LED separately ( 25 levels of brighteness ) Disconnect from a bluetooth device

You may need for this project android Studio, Arduino IDE, Bluetooth HC-05 module, arduino board. (connections are specified in comments of arduino code) so it is pretty easy :)

screenshot

entire circuit

Requirements: works on android ICE_CREAM_SANDWICH_MR1 (SDK LEVEL 15) or newer versions.

Arduino code

#include <SoftwareSerial.h>
#include <stdio.h>


int ledONE = 9;
int ledTWO = 2;
int ledTHREE = 3;


int bluetoothTX = 11 ;
int bluetoothRX = 10 ;
char receivedValue ;

SoftwareSerial bluetooth ( bluetoothTX, bluetoothRX );

void setup()
{
  Serial.begin(9600);  
  Serial.println("console> ");
  
  pinMode(ledONE, OUTPUT);
  pinMode(ledTWO, OUTPUT);
  pinMode(ledTHREE, OUTPUT);
 
  bluetooth.begin(115200);
  bluetooth.print("$$$");
  delay(100);
  bluetooth.println("U,9600,N");
  bluetooth.begin(9600);

}


void loop()
{
int brightness = 0;
int led = 0;
signed int data = 0;

 if( bluetooth.available() )
  {
    data = (int) bluetooth.read();
    Serial.println( data );                 // for debugging, show received data

      if(data == 26) 
      {
        allDown() ;
      }else if(data == 89)
      {
        allUp() ;
      }else{
        
      led = data / 100;                     // which led to select ?
      brightness = data % 100 ;             // 0 - 25 , LED brightness ( * 10 ) for actual value
           
    switch(led)                             // Now, let's select the right led.
    {
      
      case 0  : setLEDthree ( brightness * 10 );  break;
      case 1  : setLEDone ( brightness * 10 );    break;
      case 2  : setLEDtwo ( brightness * 10 );    break;
      default : setLEDthree ( brightness * 10 );  break;       // DO NOT know what to do ? must be led 3
      
    }
      }

    bluetooth.flush();                       // IMPORTANT clean bluetooth stream, flush stuck data

  }

}


// SHUT DOWN all leds
void allDown()
{
    digitalWrite(ledONE,  LOW ) ; 
     digitalWrite(ledTWO,  LOW ) ; 
      digitalWrite(ledTHREE,  LOW ) ; 
}

// ALL up now :)

void allUp()
{
    digitalWrite(ledONE,  HIGH) ; 
     digitalWrite(ledTWO,  HIGH ) ; 
     digitalWrite(ledTHREE,  HIGH ) ; 
}


void setLEDone(int brighteness)
{
 analogWrite(ledONE,  brighteness ) ; 
}

void setLEDtwo(int brighteness)
{
 analogWrite(ledTWO,  brighteness ) ; 
}

void setLEDthree(int brighteness)
{
 analogWrite(ledTHREE,  brighteness ) ; 
}



Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.