ITEAD Intelligent Switch Work With Arduino And Android

ITEAD now offer the Intelligent switchs that support touch and remote control, and it will be very easy to hack and make it work with your Arduino and Andriod phone. Here we show you a small demo, and more pleasantly surprised will be released post by post, and keep following our blog and welecom  to discuss in our forum. 

Here we briefly introduce this small DEMO.

First, the ITEAD intelligent switch support one line power supply, so you don't need to change anything but just replace it to your traditional wall switch directly, and them the hardware will connect like this:

In order to better display effect., we use the small table lamp, but it's the same effect to your ceiling lights when you replace it to your wall switch.

And we need a Iteaduino BT and a couple of 433M RF link kit. Using the Iteaduino BT, we can make the Arduino talk with Android phone by Bluetooth, and with the RF link kit, we can control the ITEAD intelligent switch.  Connec the TX module of RF link kit to the D3 of the Iteaduino, and connect the RX module to D2 pin – which can be used as external interrupt. RF link kit module can get the 5V power supply on Iteaduino BT board – there are much 3pin electronic brick interface, you can use any GND and VCC pin of them.  

Please remember to deploy the HC-05 serial Bluetooth module first, set it into slave mode but master mode, and the right baud rate – depend on your code. About how to config the Iteaduino BT, please refet to the Iteaduino BT datasheet , and you can find more information about Itaduino BT on its product page here: http://imall.iteadstudio.com/featured-product/im120411006.html

Upload the demo code below into Iteaduino BT. This part of the code is written in very rough. Just to show you a demo : )

const unsigned int tx_pin=3;
const unsigned int rx_pin=2;
 
unsigned int countvalue;
unsigned long key;
unsigned int bits;
unsigned int flag;
unsigned int flag1;
char command;
#define on 0x02001012
#define off 0x03001012
#define reverse 0x01001012
#define return_on 0x06001012
#define return_off 0x07001012
#define falling 0
#define rising 1
 
void setup(){
Serial.begin(57600);
pinMode(tx_pin, OUTPUT);
init0();
 
 
}
 
void loop(){
 
  if(Serial.available())
{
EIMSK &=~ (1<<INT0);
command = Serial.read();
EIMSK |= (1<<INT0);
}
 
  if(command>0)
  {
 
 
	if(command == 'O')
	{
        command=0;
		send_control(on);
	}
	else if(command == 'C')
	{
          command=0;
		send_control(off);
	}
 
 
 
  }
 
 
      if(flag1==1)
  {
    EIMSK &=~ (1<<INT0);
    TCCR1B=0x00;
    TCNT1=0; 
    EICRA |= (1<<ISC01) ;
    EICRA &=~(1<<ISC00); 
     flag1=0;	  
     if(key==return_on)
     {
     Serial.write("K");
     }
     else if(key==return_off)
     {
     Serial.write("G");
     }
 
  EIMSK |= (1<<INT0);
  }
 
}
 
void init0()
{
cli();
EICRA |= (1<<ISC01) ;
EICRA &=~(1<<ISC00);
EIMSK |= (1<<INT0);
sei();
 
}
 
ISR(INT0_vect)
{
EIMSK &=~ (1<<INT0);
 
 
if((EICRA&0x01)==1)
{
  TCCR1A = 0x00;
  TCCR1B=0x00;
  countvalue= TCNT1;
  TCNT1=0;
  //flag=1;
	if(flag==0)
	{
		if((countvalue>700)&&(countvalue<800))
		{
			countvalue=0;
			flag=1;
 
		}
		else
		{
			countvalue=0;		
		}
 
	}
	else
	{
		if(countvalue<30)
		{
			countvalue=0;
			bits++;
			if(bits==32)
			{
				bits=0;
				key=key;
				flag=0;
				flag1=1;
 
			}
			else
			{
			key=key<<1;
			}
 
		}
		else if(countvalue<85)
		{
			countvalue=0;
			bits++;
			if(bits==32)
			{
				bits=0;
				key=key|0x00000001;
				flag=0;
				flag1=1;				
			}
			else
			{
				key=(key|0x00000001)<<1;
			}
 
		}
		else 
		{
				bits=0;
				key=0;
				flag=0;				
		}
 
 
	}
 
 
  EICRA |= (1<<ISC01) ;
  EICRA &=~(1<<ISC00);
}
else
{
init_count();
EICRA |= ((1<<ISC01) | (1 << ISC00));
}
 
EIMSK |= (1<<INT0);
}
 
 
void init_count()
{
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x00; // 16bit counter register
TCCR1B=0x04;
 
}
 
 
void send_control(unsigned long key)
{
    EIMSK &=~ (1<<INT0);
    TCCR1B=0x00;
    TCNT1=0; 
    EICRA |= (1<<ISC01) ;
    EICRA &=~(1<<ISC00); 
uint8_t a,b;
for(a=0;a<3;a++)
{
	digitalWrite(tx_pin,LOW);
	sendleadercode();
	for(b=0;b<32;b++)
	{
		if((key>>(31-b))&0x01)
		{
		sethigh();
 
		}
		else
		{
		setlow();
		}
	}
}
delay(10);
 
 
EIMSK |= (1<<INT0);
}
 
void sendleadercode()
{
	digitalWrite(tx_pin,HIGH);
	delayMicroseconds(450);
	digitalWrite(tx_pin,LOW);
	delayMicroseconds(12000);
}
 
void sethigh()
{
	digitalWrite(tx_pin,HIGH);
	delayMicroseconds(450);
	digitalWrite(tx_pin,LOW);
	delayMicroseconds(1100);
}
void setlow()
{
	digitalWrite(tx_pin,HIGH);
	delayMicroseconds(450);
	digitalWrite(tx_pin,LOW);
	delayMicroseconds(300);
}

Install the Droidlight app on your phone. Open the software and connect your phone with Iteaduino BT, and you can use it to switch the ITEAD Intelligent Switch now. 

Now just the beginning, and we will go on publishing more posts about hack the ITEAD Intelligent switch and bulid your smart home step by step. Stay tuned and enjoy! 

Download the demo code of Iteaduino BT here:

  Iteaduino BT Demo Code (4.0 KiB, 361 hits)

Download the Droidlight app and source code here:

  Android Control Switch Demo (968.0 KiB, 385 hits)

 

Responses to “ITEAD Intelligent Switch Work With Arduino And Android

  1. Pingback: Make Smart Home Lighting System With Arduino And Android | ITead Intelligent Systems Blog

  2. please provide me necessary information.

    I want to know what are the position of jumpers and the switch, when sending commands using android phone.
    i am implementing similar project on windows phone, but i am able to connect with Iteaduino BT, but not able to send further command,

    and is there necessary to mention the pins for connecting to bluetooth. i am not implementing any RF links. just making bluetooth to communicate with mobile.

    reply asap.

    thanks.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>