Smart Android Remote System

Smart Andoid design for Home Automation

The project uses a standalone MCU specifically the Atmega328P-PU IC, a bluetooth module HC-05 and an adroid app from RemoteXY to control home applainces which consist of three AC bulbs and a load point socket. We begin by first outlining our components; For this project, we will need:

Atmega328P-PU programmable IC

HC-05 Bluetooth module

FTDI programmable cord

20KΩ resistor

Push button

Header pins (male and female types)

Crystal oscillator 16MHz

Variable resistor of value 10KΩ

16×2 Liquid Crystal Display

22pF capacitors

100nF capacitors

*NPN transistors

*Relays (coil voltage 5V)

Relay Module 4 channel, rated 5V

30-100W AC bulbs

10A load point socket

5V (5A or more) rated DC power supply or you can simply build your own.

Start off by studying the circuit diagram as shown below:

Arduino Standalone circuit
Arduino Standalone circuit (proteus version)

A clearer circuit could be obtained using fritzing:

circuit diagram of Arduino Standalone
circuit diagram of Arduino Standalone

In the circuit diagram,  the atmega328P-PU IC  was designed to act as a development board. It uses In-circuit system programming(ISP). Because we could program it using an FTDI cable. The connection is made thus as shown in the diagram below. It is very important to add the 100nF between the reset pin of the microcontroller and the CTR pin of the FTDI programmer. Also between the AVcc pin and the GND pin of the Atmega328P-PU.

For the IC to execute at its clocking speed, the crystal oscillator of 16MHz frequency must be selected  and connected between the pin 9 and pin 10 of the IC. Two 22nF capacitors are connected from these pins to the ground respectively.

A reset button is connected to the pin 1 of the Atmega328P through a 10KΩ resistor which acts as a pull-up resistor which keeps pin 1 at active 5V since it is ACTIVE LOW pin.

Connection Of The LCD:

The LCD used here is a 16×2 LCD. It works on 5V voltage and voltages above this level could fry it. And if not connected properly and polarity are reversed; this could also fry the LCD. For us, the LCD is thus connected as according to the circuit diagram shown. It would be good to ensure that all the resistors used in this circuit are precision 5-band resistors.  There is the option of 10KΩ potentiometer or 4.7KΩ to be chosen as a to tool to adjust the LCD contrast.

The Bluetooth module HC-06 is connected as shown in the circuit diagram. The RX (the receiver) pin of HC-06 is connected to TX (the transmitter) pin of the Atmega328P. While the TX of the HC-06 is connected to the RX of the Atmega328P. While the Vcc pin of HC-06 is connected to the +5V and the GND connected to the ground. This is called hardware serial connection.

The Standalone is powered via a 5V power or simply connecting the 5V power to the Vcc and the GND to the GND of the Arduino development board as an option supply. Once this is done, the HC-05 bluetooth module would be seen flashing its LED. And if connected, the LED blinking would be timed more delayed interval.

Creating Your Mobile App With RemoteXY platform:

The remoteXY app helped us to control the home appliance using Bluetooth connection with the MCU. This android app has a visual drag and drop widget that is very easy to use. To begin, visit the website www.remoteXY.com. After reading their T&Cs, click on the green icon that says Start Now.

How to Using RemoteXY with Arduino
How to Using RemoteXY with Arduino
How to Using RemoteXY with Arduino 2
Using RemoteXY with Arduino

In the next  page,  it would open an interface just like the picture shown above. From the elements you can pick switch since you want to control the states of AC light bulbs and load point switch.

Pick a button switch from the element and drag it to the screen

On the right side of the page, it shows the properties of the element like: What type of state the switch controls, what pin of the MCU it is connected, what name the switch has etc. All of these could be easily modified. Set all your four switches and add a title for your app.

Drag and add a label too

On the right side of the page, it shows the properties of the element like: What type of state the switch controls, what pin of the MCU it is connected, what name the switch has etc. All of these could be easily modified. Set all your four switches and add a title for your app.

increase the number of button switches
increase the number of button switches

Drag the label widget to the topmost side of the app design, and rename it as the title of your app. You can change the background of your app design. Just move your cursor to the right pane and click on the View, change the background color.

 editing the label of remoteXY  to your taste
and edit the label to your taste

To get a new look, you can either change the background color thus;

Changing background color on the remoteXY app
Changing background color on the remoteXY app

Try playing around with the whole thing to get your desired look.

Adding an extra button switch on remoteXY
Add an extra button switch

After this, go to module interface. Change the Connection Interface to Hardware Serial using  digital pin 0 and 1 of  your Atmega328P.

Bluetooth  hardware serial connections
Configure the hardware serial connections

Leave the speed baud rate at 9600 as it is.

Next go to Configuration. Select the type of Bluetooth module you are using, click apply after that.

Select your hardware peripheral

Next click on get code.

From the pictures above, switch 2 through socket 1 was not set specific pinon the MCU hence it wouldn’t show on the source code. It is very important to click on the switch and socket icons and set their snap to pin.

Next, copy the source code to your Arduino IDE and create a new sketch. Make some changes or simply copy off our own here:

//SOURCE CODE FOR ANDROID REMOTE CONTROL FOR HOME APPLIANCE DESIGN BY SMARTECH LABS//

/ include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 7, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__HARDSERIAL

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,4,0,0,0,129,0,8,28,0,
  2,1,2,32,19,9,2,26,31,31,
  76,49,95,79,78,0,76,49,95,79,
  70,70,0,129,0,3,13,92,7,246,
  79,112,101,121,101,109,105,39,115,32,
  65,110,100,114,111,105,100,32,82,101,
  109,111,116,101,0,2,1,27,32,18,
  9,2,26,31,31,76,50,95,79,78,
  0,76,50,95,79,70,70,0,2,1,
  53,32,18,9,2,26,31,31,76,51,
  95,79,78,0,76,51,95,79,70,70,
  0,2,1,78,32,19,9,2,26,31,
  31,83,75,84,95,79,78,0,83,75,
  84,95,79,70,70,0 };
  
// this structure defines all the variables of your control interface 
struct {

    // input variable
  uint8_t Lamp1; // =1 if switch ON and =0 if OFF 
  uint8_t Lamp2; // =1 if switch ON and =0 if OFF 
  uint8_t Lamp3; // =1 if switch ON and =0 if OFF 
  uint8_t Socket; // =1 if switch ON and =0 if OFF 

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

#define PIN_LAMP1 9
#define PIN_LAMP2 10
#define PIN_LAMP3 11
#define PIN_SOCKET 12


void setup() 
{
  lamp_off();
  lamp2_off();
  lamp3_off();
  Socket_off();
  RemoteXY_Init (); 
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Welcome Opeyemi ");
delay(3500);
lcd.setCursor(0, 1);
lcd.print("Android Remote  ");
delay(2500);
lcd.setCursor(0, 1);
lcd.print("Please connect...");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome Opeyemi ");
lcd.setCursor(0, 1);
for(int x = 0; x<9; x++){
  lcd.print('.');
  delay(300);
  }
  lcd.print("    AM Ready        ");
lcd.clear();
  
  pinMode (PIN_LAMP1, OUTPUT);
  pinMode (PIN_LAMP2, OUTPUT);
  pinMode (PIN_LAMP3, OUTPUT);
  pinMode (PIN_SOCKET, OUTPUT);
  
  // TODO you setup code
  
}

void loop() 
{ 
  
  RemoteXY_Handler ();

  lcd.setCursor(0, 0);
lcd.print("L1: L2:  L3: S1:");
  
  if(RemoteXY.Lamp1==0){
    lamp_off();
  }
  else{
    lamp_on();
  }
  
  if(RemoteXY.Lamp2==0){
      lamp2_off();
    }
    else{
       lamp2_on();
    }
    
  if(RemoteXY.Lamp3==0){
    lamp3_off();
  }
  else{
    lamp3_on();
  }
  if(RemoteXY.Socket==0){
    Socket_off();
  }
  else{
    Socket_on();
  }
 }

 
void lamp_on()
{
digitalWrite(PIN_LAMP1, HIGH);
lcd.setCursor(0, 1);
lcd.print("ON ");
}
void lamp_off()
{
digitalWrite(PIN_LAMP1, LOW);
lcd.setCursor(0, 1);
lcd.print("OFF");
}

void lamp2_on()
{
digitalWrite(PIN_LAMP2, LOW);
lcd.setCursor(4, 1);
lcd.print("ON ");
}
void lamp2_off()
{
digitalWrite(PIN_LAMP2, HIGH);
lcd.setCursor(4, 1);
lcd.print("OFF");
}

void lamp3_on()
{
digitalWrite(PIN_LAMP3, LOW);
lcd.setCursor(8, 1);
lcd.print("ON ");
}
void lamp3_off()
{
digitalWrite(PIN_LAMP3, HIGH);
lcd.setCursor(8, 1);
lcd.print("OFF");
}

void Socket_on()
{
digitalWrite(PIN_SOCKET, LOW);
lcd.setCursor(12, 1);
lcd.print("ON ");
}
void Socket_off()
{
digitalWrite(PIN_SOCKET, HIGH);
lcd.setCursor(12, 1);
lcd.print("OFF");
}

Run the source code by compiling it. After successful compiling, power your project and test it.

Your project should work as the youtude video example below.

Enjoy

Leave a Reply

Your email address will not be published. Required fields are marked *