Arduino control 8 devices via Android Bluetooth





Arduino control 8 devices via Android Bluetooth

























Hardware สำหรับ การสร้างอุปกรณ์ภาครับ
  จะใช้ Bluetooth Module และ Arduino Microcontroller Board และ Relay Output Board
Hardware อุปกรณ์ที่ใช้

  •           Serial Port Bluetooth Module( TTL )
  •           Arduino Microcontroller Board (ET-BASEAVR EASY328 ) Arduino Compatible Board
  •           8 channel Output Relay Board


Wiring Diagram การต่อสายใช้งาน

Output 1 to Pin 4 ( Arduino Board )
Output 2 to Pin 5
Output 3 to Pin 6
Output 4 to Pin 7
Output 5 to Pin 8
Output 6 to Pin 9
Output 7 to Pin 10
Output 8 to Pin 11

Bluetooth Module Tx to  Pin 0

Bluetooth Module Rx to  Pin 1

For Arduino Board



For ET-BASEAVR EASY328





Download Micro controller firmware


For Arduino Microcontroller Board Source code

#define LED_PIN1  4
#define LED_PIN2  5
#define LED_PIN3  6
#define LED_PIN4  7

#define LED_PIN5  8
#define LED_PIN6  9
#define LED_PIN7  10
#define LED_PIN8  11

int firstSensor = 0;         // first analog sensor
int secondSensor = 0;    // second analog sensor
int thirdSensor = 0;        // digital sensor
int inByte = 0;               // incoming serial byte
boolean status_unlock;
boolean status_bluetooth;

long interval = 1000;           // interval at which to blink (milliseconds)
long previousMillis = 0;        // will store last time LED was update
int minite,sec;


void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  //pinMode(2, INPUT);   // digital sensor is on digital pin 2
  //establishContact();    // send a byte to establish contact until receiver responds
 
  pinMode(LED_PIN1, OUTPUT);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(LED_PIN3, OUTPUT);
  pinMode(LED_PIN4, OUTPUT);

  pinMode(LED_PIN5, OUTPUT);
  pinMode(LED_PIN6, OUTPUT);
  pinMode(LED_PIN7, OUTPUT);
  pinMode(LED_PIN8, OUTPUT);
 
  digitalWrite(LED_PIN1, LOW);  // switch off LED
  digitalWrite(LED_PIN2, LOW);  // switch off LED
  digitalWrite(LED_PIN3, LOW);  // switch off LED
  digitalWrite(LED_PIN4, LOW);  // switch off LED
   
  digitalWrite(LED_PIN5, LOW);  // switch off LED
  digitalWrite(LED_PIN6, LOW);  // switch off LED
  digitalWrite(LED_PIN7, LOW);  // switch off LED
  digitalWrite(LED_PIN8, LOW);  // switch off LED
 
  status_bluetooth = true;
  status_unlock = false;
  sec = 0;
}

void loop()
{
  if (Serial.available() > 0) {  
      
    inByte = Serial.read();                      // get incoming byte: 

    if(inByte == 'A'){   
      digitalWrite(LED_PIN1, HIGH);        // switch on LED
      Serial.print('A', BYTE);                    // send a char
      //delay(800);
      digitalWrite(LED_PIN1, LOW);        // switch off LED
      status_unlock = false;
      inByte = 0;    
    }
   
    if(inByte == 'a'){   
      digitalWrite(LED_PIN2, HIGH);        // switch on LED
      Serial.print('a', BYTE);                    // send a char
      //delay(800);
      digitalWrite(LED_PIN2, LOW);        // switch off LED
     
      status_unlock = true;
      sec = 0;
      inByte = 0;    
    }
   
    if(inByte == 'B'){   
      digitalWrite(LED_PIN3, HIGH);        // switch on LED
      Serial.print('B', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'b'){   
      digitalWrite(LED_PIN3, LOW);        // switch off LED
      Serial.print('b', BYTE);                   // send a char
      inByte = 0;    
    }
   
    if(inByte == 'C'){   
      digitalWrite(LED_PIN4, HIGH);        // switch on LED
      Serial.print('C', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'c'){   
      digitalWrite(LED_PIN4, LOW);        // switch off LED
      Serial.print('c', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'D'){   
      digitalWrite(LED_PIN5, HIGH);        // switch on LED
      Serial.print('D', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'd'){   
      digitalWrite(LED_PIN5, LOW);        // switch off LED
      Serial.print('d', BYTE);                   // send a char
      inByte = 0;    
    }
   
    if(inByte == 'E'){   
      digitalWrite(LED_PIN6, HIGH);        // switch on LED
      Serial.print('E', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'e'){   
      digitalWrite(LED_PIN6, LOW);        // switch off LED
      Serial.print('e', BYTE);                   // send a char
      inByte = 0;    
    }
   
    if(inByte == 'F'){   
      digitalWrite(LED_PIN7, HIGH);        // switch on LED
      Serial.print('F', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'f'){   
      digitalWrite(LED_PIN7, LOW);        // switch off LED
      Serial.print('f', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'G'){   
      digitalWrite(LED_PIN8, HIGH);        // switch on LED
      Serial.print('G', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'g'){   
      digitalWrite(LED_PIN8, LOW);        // switch off LED
      Serial.print('g', BYTE);                   // send a char
      inByte = 0;    
    }   
   
    if(inByte == 'S'){   
     
      Serial.print('S', BYTE);                  // send a char
      status_bluetooth = true;
      sec = 0;
         
    }   
  } // if(Serial
 
  /*
  unsigned long currentMillis = millis();
     
              if(currentMillis - previousMillis > interval) {           
                previousMillis = currentMillis;         // save the last time you blinked the LED
               
                sec++;
               
                if(status_unlock==true){
               
                  if(sec== 11){
               
                      digitalWrite(LED_PIN1, HIGH);        // switch on LED
               
                      delay(800);
                      digitalWrite(LED_PIN1, LOW);        // switch off LED
               
                      status_unlock = false;                 
                      sec = 0;
                  }
                }
                else sec = 0;               
               
              }
 
 */
   
} //Loop

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('.', BYTE);                   // send a capital A
    delay(500);
  }
}










Android Bluetooth Control Device

 
Android Bluetooth Control Device Application is to allow you to control various electricaldevices up to eight devices and independentlycontrolled.
Use Android Bluetooth mobile device to  remote control your device with Bluetooth Receiver hardware Device.
เป็น Application ที่ทำให้คุณสามารถควบคุมอุปกรณ์ไฟฟ้าต่างๆได้ ถึง 8 อุปกรณ์โดย แยกควบคุมกันได้อย่างอิสระ
ผ่านระบบ Bluetooth ของเครื่องโทรศัพท์มือถือ Android เป็นตัว Remote Control ไปยังอุปกรณ์ภาครับ ( Bluetooth Receiver Hardware Device )

The program features.
- control up to  8 devices.
- Can be set Timer to ON / OFF the device and show the time.(the timer can be set to 1minute, 15 minutes, 30 minutes, 1hour, 2 hours,4 hours).
- Use with Receivingdevice (Bluetooth Receiver Hardware Device see below).
Design for the Android version 4 and a screen resolution of 480 x 800 (WVGA).
Freeware with AD (free software)


คุณสมบัติโปรแกรม
-          ควบคุมอุปกรณ์ได้ 8 อุปกรณ์
-          สามารถตั้งเวลา ปิด/เปิด แต่ละอุปกรณ์ได้ และแสดงเวลาการทำงาน และเวลาคงเหลือการตั้งเวลา 
(  เวลาที่สามารถตั้งได้ 1 นาที,15 นาที, 30 นาที, 1 ชั่วโมง ,2 ชั่วโมง , 4 ชั่วโมง ) 
-          ต้องใช้งานร่วมกับ อุปกรณ์ภาครับ ( Bluetooth Receiver Box )
ออกแบบ ค่าเริ่มต้น สำหรับ Android version 4 และ หน้าจอความละเอียด 480 x 800 ( WVGA )

A data transmission via Bluetooth. รูปแบบการส่งข้อมูลผ่าน Bluetooth
Device1 ON sent “A” , Device1 OFF sent “a”
Device2 ON sent “B” , Device2 OFF sent “b”
Device3 ON sent “C” , Device3 OFF sent “c”
Device4 ON sent “D” , Device4 OFF sent “d”
Device5 ON sent “E” , Device5 OFF sent “e”
Device6 ON sent “F” , Device6 OFF sent “f”
Device7 ON sent “G” , Device7 OFF sent “g”
Device8 ON sent “H” , Device8 OFF sent “h”