The basic principle in this project is that by interfacing an Android phone with a Arduino Board we can turn "off" or "on" some relays.
Components Required
- Serial Port Bluetooth Module( TTL )
- Arduino Microcontroller Board (ET-BASEAVR EASY328 ) Arduino Compatible Board
- 8 channel Output Relay Board
Source Code For Arduino Board
#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);
}
}
-
It can control up to 8 devices.
These devices can be turned off /on by setting Timer to ON / OFF the device and show the time.(the timer can be set to 1 minute, 15 minutes, 30 minutes, 1 hour, 2 hours, 4 hours).
Use with Receiving device (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)