電子工作70 – 赤外線リモートON/OFFスイッチの製作

 

 

概要

   寒くなってきてコタツなどに入っている時、離れているところにある電気機器のスイッチをON/OFFしたいことがよくある。そんな時に役立つように製作したのがこの2個1組からなる装置である。送信器はスイッチ1個が付いた赤外線リモコンで、受信器はその信号を受けて最大10m位離れたAC100Vの電気機器をON/OFFする。実際に使ってみると大変便利である。

 

製作にあたって考えていたこと

1)    構造が簡単で、安価に製作出来ること。

2)    これまでの電子工作で作成したプログラムを利用すること。

3)    送信器は省エネを図りボタン電池1個で実用になること。

 

回路図

送信器側

  下図のように、12F683を用いた理由は赤外線の搬送波38KHzをハード的に出せるPWM機能を備えているからである。電源には3Vのボタン電池1個を使う。当然省エネが必要であるが、ソフトで問題を解決した。待機時(発信SWを押していない時)の消費電流は0.1mA以下であった。したがって用いたボタン電池(CR2032 220mAh)でも充分長持ちすると考えられる。赤外線LEDの出力はトランジスタ2SC1815で増幅した。発信ボタンを押すと赤外線LEDからプログラムで作成したパターンを持った赤外線ビームが受信器に向かって発射される。ボタンから指を離すと電流の消費が極端に低くなる待機状態になる。

 

受信器側

  ここでも12F683を用いた理由は、プログラムが大きく最初導入を考えた12F629のメモリでは満杯になる可能性があったためである。電源にはコンパクトなUSBアダプタ(DC5V500mA)を用いた。送信器からの赤外線ビームは赤外線リモコン受信モジュールで元の波形パターンに復元されGP4より読み込まれる。SSR(Solid State Relay)にはGP2より信号が送られON/OFFされる。SSRがONの時はGP1に接続のSSRの稼働を表示するLED(G)も点灯する。今回使用したSSRはOFF時でも、AC100V電源タップに差込んであると反対側のメス差込口にはAC11−14Vの電圧がかかる。しかしネオン管は点灯できない。勿論、SSRがON時はほぼAC100Vの電圧が出て白熱電球などを普通に点灯させる。

 

送信器の外観: L70XW46XH20mmの透明プラスチックケースに収まった。黄色いボタンが発信SW。

この発信SWを1回押すとSSRがON、次に押すとSSRがOFF、その繰り返し。

 

受信器の外観: L130XW100XH60mmのアルミボックスを使用。右上に赤外線受信モジュール、左下側にUSBアダプタが見える。

 

受信パルス

赤外線リモコン受信モジュールのOUT端子で送信器から送られて来たパルス群をオシロで測定したもの。結構綺麗に再現されているのが分かる。プログラムでこれら

パルス1−24を1個1個数えて正しいパルス群かどうか判定する。幅の狭いパルスの幅は0.85ms、広いパルスの幅は2.5msである。

結果&コメント

1)     正常に動作することが確認された。発信情報のビット数が24個と大きいので、外部環境ノイズ(蛍光燈など)の影響はほとんど受けない。

2)     送信距離は最大で10mほど。

3)     送信SWが押されていない時(待機時)は、電流消費は0.1mA(microA)以下に下がり、ボタン電池(CR2032で220mAh)でも充分持つと考えられる。この件に関し、テスタのuAなどで測定すると時として待機電流が0.32mAと表示され続けるが1ー2分くらいして0.00mAに(正常に)戻る。もう一つ電池を新たに入れて直ぐ発信SWを押しても動作しないことがあるが、この場合も1ー2分後に動作するようになる。理由は不明。

*電池の持ち計算: 220mAh=220000mAh 220000mAh/0.1mA=2200000h  2200000h/24h=91666days 91666days/365=251years?

ただし、発信SWを押した時には一時的に5mAほど流れること、電池の経時劣化、最終使用可能電圧などで勿論そんなに持たない。

4)     ゼロクロスのSSR(Sharp S108T02)を使うとSSRがOFFの時に、AC100V電源タップに接続時AC11-14Vの電圧がメス差込口に出る。しかし差込口に接続したタップの内蔵ネオン管は点灯しなかった。一方、非ゼロクロスのSSR(D2W202KD)の場合はAC99.5Vもの電圧が出ていてネオン管は減光点灯した。メカニカルリレーを用いればこの現象は起こらない。ただ5V5Aのパワーリレーではコイルで100mAほど電流を消費するのでPICのポートにトランジスタなどを付けて駆動する必要がある。

5)     赤外線パルスパターンは送信器のプログラムにならって、ビット数や“0”と“1”の組合せを自由に変えて如何様にも設計できる。このメリットは大きい。

 

プログラム

送信器のプログラム

送信器から発信されるパルスパターンは古いFUNAIのリモコンRCー7の“電源ボタン”のそれをモデルとしている。それに似せて、PicBasic ProのコマンドPauseやPauseusを使って24個のパルスを1個づつ合成し送信している。ここでは“0”と“1”の区別に波長幅を使っている。その際12F683のPWM機能を使って搬送波38Khzを作り出している。このプログラムでは、ボタン電池でも実用になるように割込みアッセンブラーコマンド(@sleep)を使って超省エネを図っている

'********************************************

'(IR Transmitter Program)

'IRTransmitter12F683PWM.bas 2013.12.16, worked OK!

'Based on SLight12F683HPWMC.bas  2011.2.11 works but SW-ON-OFF timing important to exclude H-tailing!

'This produces a PWM-based remote-control command sequence.

'Use of @Sleep command

'12F683 with internal clock 4MHz

'Combined with PWMtestBB1.bas (2009.6.5 Eproj33)

'PicBasic Pro V.2.50A used

'*********Pin connections*********

'Pin 1: Vdd (5.0V)

'Pin 8: Vss (GND)

'Pin 7: GPIO.0: input - from Transmission SW (Port level change detect)

'Pin 5: GPIO.2: output - PWM output driving IRLED via Transistor 1815

'Pin 4: GPIO.3: input - connected to MCLR via 10K resistor

'*********Program*********

CMCON0=7             'Comparator OFF (Note: not CMCON=7)

ANSEL.0=0            'All pin digital

TRISIO=%001001       'GP0 - Transmission SW input (level change interrupt)

PR2=25               'Set PWM for 38KHz (24:40KHz)

CCPR1L=13            'Set PWM for 50% duty cycle

CCP1CON=%00001100    'PWM mode selection

T2CON=%00000100      'Timer2 ON + 1:1 prescale

 

INTCON.7=1         'Use of imterrupt GIE->1

INTCON.3=1         'Use of GPIO port level change interrupt

IOC.0=1            'GPIO pin input change detect  Essential!

 

SleepLoop:

CCP1CON=0  'Essential!

INTCON.0=0      'Clear GPIF   important!

GPIO.2=0    'Essential to remove H-level tailing (save current)

@sleep          'This is a key command

GPIO.2=0    'Essential!

INTCON.0=0      'Clear GPIF

GPIO.2=0    'Essential!

 

'*** Routine to be executed when wake up ***

'Plspattern1:   '"Dengen" key of Funai RC-7 remote controller

Gosub w40msH   '40-ms H pulse

Gosub w3p5msL  '3.50-ms L pulse

Gosub w3p35msH '3.35-ms H pulse + 1-ms L pulse

Gosub w0p85msH '1, 850-us H pulse + 1-ms L pulse - 1-24

Gosub w0p85msH '2, 850-us H pulse + 1-ms L pulse

Gosub w0p85msH '3, 850-us H pulse + 1-ms L pulse

Gosub w2p5msH  '4, 2.5-ms H pulse + 1-ms L pulse

Gosub w0p85msH '5, 850-us H pulse + 1-ms L pulse

Gosub w2p5msH  '6, 2.5-ms H pulse + 1-ms L pulse

Gosub w0p85msH '7, 850-us H pulse + 1-ms L pulse

Gosub w0p85msH '8, 850-us H pulse + 1-ms L pulse

Gosub w0p85msH '9, 850-us H pulse + 1-ms L pulse

Gosub w0p85msH '10, 850-us H pulse + 1-ms L pulse

Gosub w0p85msH '11, 850-us H pulse + 1-ms L pulse

Gosub w2p5msH  '12, 2.5-ms H pulse + 1-ms L pulse

Gosub w2p5msH  '13, 2.5-ms H pulse + 1-ms L pulse

Gosub w2p5msH  '14, 2.5-ms H pulse + 1-ms L pulse

Gosub w2p5msH  '15, 2.5-ms H pulse + 1-ms L pulse

Gosub w0p85msH '16, 850-us H pulse + 1-ms L pulse

Gosub w2p5msH  '17, 2.5-ms H pulse + 1-ms L pulse

Gosub w0p85msH '18, 850-us H pulse + 1-ms L pulse

Gosub w2p5msH  '19, 2.5-ms H pulse + 1-ms L pulse

Gosub w2p5msH  '20, 2.5-ms H pulse + 1-ms L pulse

Gosub w2p5msH  '21, 2.5-ms H pulse + 1-ms L pulse

Gosub w2p5msH  '22, 2.5-ms H pulse + 1-ms L pulse

Gosub w2p5msH  '23, 2.5-ms H pulse + 1-ms L pulse

Gosub w0p85msH '24, 850-us H pulse + 1-ms L pulse

 

Goto SleepLoop

 

'Subroutines ---

w40msH:

CCP1CON=0     '=%00000000  PWM disable

Low GPIO.2

Pause 40

CCP1CON=12    '=%00001100  PWM enable    

Return

 

w3p5msL:

CCP1CON=12

Pauseus 3500

Return

 

w3p35msH:

CCP1CON=0

Low GPIO.2

Pauseus 3350

CCP1CON=12

Pauseus 1000   '1-ms L pulse

Return

 

w0p85msH:

CCP1CON=0

Low GPIO.2

Pauseus 850    '0.85-ms pulse

CCP1CON=12

Pauseus 1000   '1-ms L pulse

Return

 

w2p5msH:

CCP1CON=0

Low GPIO.2

Pauseus 2500

CCP1CON=12

Pauseus 1000   '1-ms L pulse

Return

'*******End of program*************

'Note:

   'melabs Engineering's Programmer's configurations: IMPORTANT!

   'Oscillator - INTOSCIO; Watch-dog Timer - Disable; Powe-up Timer - Disable

   'MCLR - Reset; Brown-out Reset - Disable; Int-Ext SW-over - Enable;

   'Fail-Safe clock monitor - Enable; Code - Not protect; Data EEPROM - Not protect. 2011.2.6

 

受信器のプログラム

  受信器側では送られて来たパルスを1個づつチェックしてどんな幅のパルスかを特定し、そして全部で24個のパルスを受け取った段階で理論上の値 (=%011111010111100000101000).と同じかどうか調べる(PicBasic Proで扱える最大ビット数は16「WORD型」なのでプログラムでは16bitsと8bitsに分けて検討)。もし同じならSSRをONにしたりOFFにしたりする。プログラムの中でToggleというコマンドが2箇所で使われているが、最初の正しいパルスパターンの到着でSSRをONにし、次の正しいパルスパターンの到着でONをOFFに反転させるのがこの便利なToggleなのである。

'********************************************

'(IR Receiver Program)

'IRRelayReceiver12F683.bas 2013.12.19

'Based on IRRelayReceiver12F629.bas 2013.12.17/18  worked OK!

'Based on IRrecTD.bas Works well - confirmed on 2009.1.9

'This program reads IR pulses from "DENGEN" and "TV/Video" keys" of FUNAI RC-7 remote control.

'If those keys are pressed, LED1 or LED2 on the board flashes on and off.  2009.1.8

'PicBasic Pro V.2.50A used

'************** Pin connection **********************

'12F683, 4MHz Internal Clock used

'Pin 1: Vdd (5.0V)

'Pin 8: Vss (GND)

'Pin 3: GPIO.4: input - connected to IR Receiver module

'Pin 5: GPIO.2: output - connected to SSR drive

'Pin 6: GPIO.1: output - connected to LED(R) SSR-ON/OFF indicator

'Pin 4: GPIO.3: input - connected to MCLR via 10K resistor

'*************** Main program ***********************

CMCON0=7  'Comparator off Note: not CMCON=7 (for 12F629 etc)

ANSEL=0  'All pins are digitals

TRISIO=%011000  'all except GP3 and GP4 are outputs.

 

PlsW300 var word

PlsW var word

Code var word

Code1 var word

SSRdrive var GPIO.2

SSRonoffLED var GPIO.1

 

SSRdrive=0

SSRonoffLED=0

 

Loop:

PlsW300=0

PlsW=0

Code=0

Code1=0

Clear     'Clear the content of all variables - Essential!

 

Pulsin GPIO.4,1,PlsW300  'Read the pulse with 3.3 ms

If (300<PlsW300) and (400>PlsW300) then

Goto Countpls

Else

Goto Loop

Endif

 

SSRdrive=0

SSRonoffLED=0

 

Countpls:  'Formation of Code and Code1

'Checking Bit0 - 0-15 (16 bits)                             Power TV/Video

Pulsin GPIO.4,1,PlsW   'Read 24 working pulses               Key   Key

If 150>PlsW then Code.bit0=0  '0 is a small pulse (0.7 ms)   0      0

If 150<PlsW then Code.bit0=1  '1 is a large pulse (2.5 ms)

 

'Checking Bit1

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit1=0   '0     0

If 150<PlsW then Code.bit1=1

 

'Checking Bit2

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit2=0   '0     0

If 150<PlsW then Code.bit2=1

 

'Checking Bit3

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit3=0

If 150<PlsW then Code.bit3=1    '1     1

 

'Checking Bit4

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit4=0    '0     0

If 150<PlsW then Code.bit4=1   

 

'Checking Bit5

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit5=0

If 150<PlsW then Code.bit5=1    '1     1

 

'Checking Bit6

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit6=0    '0     0

If 150<PlsW then Code.bit6=1   

 

'Checking Bit7

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit7=0    '0     0

If 150<PlsW then Code.bit7=1

 

'Checking Bit8

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit8=0    '0     0

If 150<PlsW then Code.bit8=1   

   

'Checking Bit9

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit9=0    '0     0

If 150<PlsW then Code.bit9=1   

 

'Checking Bit10

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit10=0   '0     0

If 150<PlsW then Code.bit10=1   

 

'Checking Bit11

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit11=0

If 150<PlsW then Code.bit11=1   '1     0

 

'Checking Bit12

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit12=0

If 150<PlsW then Code.bit12=1   '1     1

 

'Checking Bit13

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit13=0

If 150<PlsW then Code.bit13=1   '1     1

 

'Checking Bit14

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit14=0

If 150<PlsW then Code.bit14=1   '1     1

 

'Checking Bit15

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code.bit15=0   '0     0

If 150<PlsW then Code.bit15=1   

 

'Code=30760 in first 16 bits =%0111100000101000  (Power Key)

 

'Checking Bit16 - 16-23 (8 bits)

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit0=0

If 150<PlsW then Code1.bit0=1   '1     1

 

'Checking Bit17

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit1=0   '0     0

If 150<PlsW then Code1.bit1=1    

 

'Checking Bit18

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit2=0

If 150<PlsW then Code1.bit2=1   '1     1

 

'Checking Bit19

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit3=0

If 150<PlsW then Code1.bit3=1   '1     1

 

'Checking Bit20

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit4=0

If 150<PlsW then Code1.bit4=1   '1     1

 

'Checking Bit21

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit5=0

If 150<PlsW then Code1.bit5=1   '1     1

 

'Checking Bit22

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit6=0

If 150<PlsW then Code1.bit6=1   '1     1

 

'Checking Bit23

Pulsin GPIO.4,1,PlsW  

If 150>PlsW then Code1.bit7=0   '0     1

If 150<PlsW then Code1.bit7=1   

 

'Code1=125 in last 8 bits =%01111101 (Power Key)

 

Pause 20

If (Code=30760) and (Code1=125) then SSRdriveON

Goto Loop

 

SSRdriveON:

Toggle SSRdrive

Toggle SSRonoffLED

Pause 500   '0.5 sec

Goto Loop

 

'********* End of Program ***********

  'Note:

   'melabs U2 Programmer's configurations for 12F683

   'Oscillator - INTOSCIO; Watch-dog Timer - Enable; Powe-up Timer - Enable

   'MCLR - Reset; Brown-out Reset - Disable; Int-Ext SW-over - Enable;

   'Fail-Safe clock monitor - Enable; Code - Not protect; Data EEPROM - Not protect.

 

 

Simple Infrared Remote Switch (English version of the above Electronics Project 70 in Japanese)

  I made this gadget consisting of IR Transmitter and IR Receiver, to remotely turn on/off an electric appliance, which may be located several to about 10 meters away from me. It works well and is free from interference of various light-related environmental noises.

 

IR Transmitter:

  As shown below, its circuit is simple and straightforward. I used PIC12F683 to utilize its built-in PWM function with which 38KHz carrier could easily be produced. A 3V lithium coin battery was used as power source because the power consumption of the entire system when no Transmission button was being pressed dropped to as low as less than 0.1mA. This became possible by introducing the 'interrupt' and the assembler 'sleep' command into the program. A transistor 1815 is used to amplify the output of infrared beam.

 

IR Receiver:

  Due to its compactness, I used a USB adapter as DC5V power source for the system. Here too, I used PIC12F683 instead of 12F629.because of its larger memory size to accommodate the large IR Receiver’s program. To turn on/off an electric appliance connected to AC100V line, a SSR (solid state relay) is used, which is controlled by the on/off-signal from GP2 of PIC. At the same time, when SSR is ON, the LED (G) connected to GP1 of PIC lights up, indicating that the system is working.

 

IR Transmitter: Size L70XW46XH20mm, the yellow button is for transmission of signal.

 

IR Receiver: Size L130XW100XH60mm, the IR reception module can be seen on the upper right.

 

Program

IR Transmitter Program (IRTransmitter12F683PWM.bas) and IR Receiver Program (IRRelayReceiver12F683.bas) are shown (readable) in the above Japanese section (most part of it is unreadable due to complete garbling under Alphabetical fonts). Both programs were written by using PICBasic Pro V.2.50A.

 

IR Transmitter Program:

The 38KHz carrier that is required for the formation of infrared pulses is produced by using PWM function of 12F683, of which setting is a bit complicated. A total of 24 '0' and '1' pulses used are generated by producing two kinds of pulses with different widths, 0.85ms and 2.5ms, in the program. A 1ms-wide pulse is included between any two adjacent pulses to clearly separate those pulses. The IR transmitter program produces a series of pulses as shown below (measured at GP4 of IR Receiver's 12F683 by oscilloscope). For example, the pulses 1, 2, 3, and 24 correspond to '0' while the pulses 4, 22 and 23 correspond to '1'. The sequence of 24 pulses is '011111010111100000101000', where the leftmost digit '0' corresponds to 24 in the figure below. The assembler 'sleep' command is significantly contributing to the saving of coin battery (CR2032, 220mAh).

IR Receiver Program:

   In the receiver side, the program picks up one pulse by another from IR Transmitter through the infrared reception module and builds up a sequence of bits. If this sequence of bits coincides with the theoretical sequence (=transmitted one), it is interpreted as the right sequence, turning on/off SSR and LED (G). PICBasic Pro's 'Pulsin' command plays the key role in reading and identifying the pulses with different widths. At the same time, its 'Toggle' command makes it possible to alternately turn on and off SSR whenever IR Transmitter's Transmission button is pressed. In the program, the pulse sequence of 24 bits is handled by dividing it into 16 bits and 8 bits because the maximum bit sequence PICBasic Pro (V.2.50A) can deal with is 16 bits.

 

Conclusions and comments

1)       It works well without interference perhaps because 24 bits are used as a pulse signal.

2)       The power consumption of IR Transmitter is very low or less than 0.1 mA (when waiting a key entry).

3)       Occasionally, the power consumption of IR Transmitter increases to a level of around 0.32mA, for example, when the coin battery is replaced but it drops to the normal level within 1 to 2 minute.

4)       When SSR (zero-cross type) is used, the plug-in receptacle of AC100V (when the other side is being connected to a commercial AC100V line) shows a voltage of AC11-14V, which is unable to turn on a neon-pilot lamp.

 

Menu Pageへ戻る

Topへ戻る