Touch Switch DIY

Wednesday, 26 June 2013

Touch Sensor WTXM-TCS1


2 Channel Touch Sensor Module TCS01

2 Channel Touch Sensor Module WTXM-TCS1 complete with 2 Channel touch sensing IC 9802. Low current consumption <= 2uA + MCU 3uA during sleep.Specially designed for battery operated and rechargeable battery type AAA. Upgradeable to wireless by adding a RF Transmitter module.






Picture 1 :Touch Sensor WTXM - TCS1 - 2 Channel Touch Sensor





Testing a 2 Channel Touch Sensor






Friday, 5 April 2013

C Code for IR Learning Module


#define MAIN_Fosc 12000000L
#define D_TIMER0 125
#define User_code 0xFD02



#include "reg51.H"
#define uchar unsigned char
#define uint unsigned int

#define freq_base (MAIN_Fosc / 1200)
#define Timer0_Reload (65536 - (D_TIMER0 * freq_base / 10000))



sbit P_TXD1 = P3^1;
sbit P_IR_RX = P0^1;

bit P_IR_RX_temp; //Last sample
bit B_IR_Sync;
uchar IR_SampleCnt;
uchar IR_BitCnt;
uchar IR_UserH;
uchar IR_UserL;
uchar IR_data;
uchar IR_DataShit;

bit B_IrUserErr; //User code error flag
bit B_IR_Press; //Key press flag,include repeat key.
uchar IR_code; //IR code



void Tx1Send(uchar dat);
uchar HEX2ASCII(uchar dat);
void InitTimer(void);
void PrintString(unsigned char code *puts);



void main(void)
{
InitTimer();

PrintString("****** STC 2010-12-10 ******\r\n");
while(1)
{
if(B_IR_Press)
{
PrintString("ºìÍâÂë: 0x");
Tx1Send(HEX2ASCII(IR_code >> 4));
Tx1Send(HEX2ASCII(IR_code));
if(B_IrUserErr)
{
Tx1Send(' ');
Tx1Send(' ');
PrintString("Óû§Âë: 0x");
Tx1Send(HEX2ASCII(IR_UserH >> 4));
Tx1Send(HEX2ASCII(IR_UserH));
Tx1Send(HEX2ASCII(IR_UserL >> 4));
Tx1Send(HEX2ASCII(IR_UserL));
}
Tx1Send(0x0d);
Tx1Send(0x0a);
B_IR_Press = 0;
}
}
}


uchar HEX2ASCII(uchar dat)
{
dat &= 0x0f;
if(dat <= 9) return (dat + '0'); //Êý×Ö0~9
return (dat - 10 + 'A'); //×ÖĸA~F
}




//*******************************************************************
//*********************** IR Remote Module **************************

//*********************** IR Remote Module **************************
//this programme is used for Receive IR Remote (HT6121).

//data format: Synchro,AddressH,AddressL,data,/data, (total 32 bit).

//send a frame(85ms), pause 23ms, send synchro of another frame, pause 94ms

//data rate: 108ms/Frame


//Synchro:low=9ms,high=4.5/2.25ms,low=0.5626ms
//Bit0:high=0.5626ms,low=0.5626ms
//Bit1:high=1.6879ms,low=0.5626ms
//frame space = 23 ms or 96 ms



#if ((D_TIMER0 <= 250) && (D_TIMER0 >= 60))
#define D_IR_sample D_TIMER0 //¶¨Òå²ÉÑùʱ¼ä£¬ÔÚ60us~250usÖ®¼ä
#endif

#define D_IR_SYNC_MAX (15000/D_IR_sample) //SYNC max time
#define D_IR_SYNC_MIN (9700 /D_IR_sample) //SYNC min time
#define D_IR_SYNC_DIVIDE (12375/D_IR_sample) //decide data 0 or 1
#define D_IR_DATA_MAX (3000 /D_IR_sample) //data max time
#define D_IR_DATA_MIN (600  /D_IR_sample) //data min time
#define D_IR_DATA_DIVIDE (1687 /D_IR_sample) //decide data 0 or 1
#define D_IR_BIT_NUMBER 32 //bit number

//*******************************************************************************************
//**************************** IR RECEIVE MODULE ********************************************

void IR_RX_HT6121(void)
{
uchar SampleTime;

IR_SampleCnt++; //Sample + 1

F0 = P_IR_RX_temp; //Save Last sample status
P_IR_RX_temp = P_IR_RX; //Read current status
if(F0 && !P_IR_RX_temp) //Last sample is high£¬and current sample is low, so is fall edge
{
SampleTime = IR_SampleCnt; //get the sample time
IR_SampleCnt = 0; //Clear the sample counter

if(SampleTime > D_IR_SYNC_MAX) B_IR_Sync = 0; //large the Maxim SYNC time, then error
else if(SampleTime >= D_IR_SYNC_MIN) //SYNC
{
if(SampleTime >= D_IR_SYNC_DIVIDE)
{
B_IR_Sync = 1; //has received SYNC
IR_BitCnt = D_IR_BIT_NUMBER; //Load bit number
}
}
else if(B_IR_Sync) //has received SYNC
{
if(SampleTime > D_IR_DATA_MAX) B_IR_Sync=0; //data samlpe time to large
else
{
IR_DataShit >>= 1; //data shift right 1 bit
if(SampleTime >= D_IR_DATA_DIVIDE) IR_DataShit |= 0x80; //devide data 0 or 1
if(--IR_BitCnt == 0) //bit number is over?
{
B_IR_Sync = 0; //Clear SYNC
if(~IR_DataShit == IR_data) //ÅжÏÊý¾ÝÕý·´Âë
{
if((IR_UserH == (User_code / 256)) &&
IR_UserL == (User_code % 256))
B_IrUserErr = 0; //User code is righe
else B_IrUserErr = 1; //user code is wrong

IR_code      = IR_data;
B_IR_Press   = 1; //Êý¾ÝÓÐЧ
}
}
else if((IR_BitCnt & 7)== 0) //one byte receive
{
IR_UserL = IR_UserH; //Save the User code high byte
IR_UserH = IR_data; //Save the User code low byte
IR_data  = IR_DataShit; //Save the IR data byte
}
}
}
}
}


/**************** Timer³õʼ»¯º¯Êý ******************************/
void InitTimer(void)
{
TMOD = 0; //for STC15FxxxϵÁÐ Timer0 as 16bit reload timer.
TH0 = Timer0_Reload / 256;
TL0 = Timer0_Reload % 256;
ET0 = 1;
TR0 = 1;

EA  = 1;
}


/********************** Timer0ÖжϺ¯Êý************************/
void timer0 (void) interrupt 1
{
IR_RX_HT6121();
}


/********************** Ä£Äâ´®¿ÚÏà¹Øº¯Êý************************/

void BitTime(void) //λʱ¼äº¯Êý
{
uint i;
i = ((MAIN_Fosc / 100) * 104) / 140000 - 1; //¸ù¾ÝÖ÷ʱÖÓÀ´¼ÆËãλʱ¼ä
while(--i);
}

//Ä£Äâ´®¿Ú·¢ËÍ
void Tx1Send(uchar dat) //9600£¬N£¬8£¬1 ·¢ËÍÒ»¸ö×Ö½Ú
{
uchar i;
EA = 0;
P_TXD1 = 0;
BitTime();
for(i=0; i<8; i++)
{
if(dat & 1) P_TXD1 = 1;
else P_TXD1 = 0;
dat >>= 1;
BitTime();
}
P_TXD1 = 1;
EA = 1;
BitTime();
BitTime();
}

void PrintString(unsigned char code *puts) //·¢ËÍÒ»´®×Ö·û´®
{
    for (; *puts != 0; puts++)  Tx1Send(*puts); //Óöµ½Í£Ö¹·û0½áÊø
}

Thursday, 28 March 2013

Turn your conventional wall switch into wireless method 2

Descriptions:

Method 2 will show you  how to turn conventional wall switch into wireless transmitter.

Figure 1

Connect the switch and battery wires to the wall switch transmitter module PCB terminals and your switch is ready use as a wireless wall switch.





Advantages

1. Convenience :- Flexibility control

3. No Additional Wirings :- Wireless Technology reduces wiring cost. Is a Battery powered switch.

4. Can be placed anywhere to suit your needs. Turn On/Off the lightings, make you more
   convenient.

5. Easily install and relocate. Just stick it anywhere and the switch is ready to use !

Turn your conventional wall switch into wireless method 1

Turn your conventional wall switch into wireless ( Method 1 )


Figure 1


Description:

Figure 1 show typical wiring of  conventional 1 gang wall switch to lighting. We will need 2 devices to complete upgrading to the wireless system. First device is a Mini-Remote while the second device is the lighting control receiver. Figure 2 show the wireless wall switch system.

Figure 2

Switch 1 will be left permanently on. Mini Remote will take over the job. It enable you to turn on or off the lighting anywhere in your home, provide you the comfort and convenience.