電子工作67 – リモコン中継器の製作

 

 

概要

   東京の練馬で暮らす。エアコンなしの長屋暮らしの夏は暑く、室温が37C以上にもなることは珍しくない。そんなときは命の危険があるので地下鉄やバス、あるいは喫茶室に避難する。問題は熱帯夜の場合で、トイレの北側の窓から入る風が比較的温度が低いことが分かっているので、そこに扇風機を置いてずっと離れた寝床からコントロールして冷気を入れることを思いついた。しかし扇風機のリモコンでは距離が長く、さらに途中壁で遮られるので赤外線信号は届かない。そんな訳で出来るだけ簡単なリモコン中継器を製作することにした。

 

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

1)    出来るだけ簡単なシステムにすること。

2)    リモコンに必要な38KHzの搬送波を簡単に作れる12F683を使う(電子工作34)。

3)    いつもの様にPicBasic Proを使いプログラムも出来るだけ簡単にする。

 

回路図と動作原理

  回路図を下に示す。前の電子工作34で8ピンの12F683がPWM機能を持っていてリモコンに必要な38KHzの搬送波を簡単に出せることが分かっていたので、これを利用することにした。Webで検索したら同じP ICを使ったR.yawatta氏の記事"R.yawattaのラジオと工作”があったので一部(ノイズ除去法)を参考にさせて貰った。すなわち、赤外線リモコン受信モジュールに抵抗200ohmとコンデンサ4.7uFを入れることによってリモコンからの信号を認知する確率が飛躍的に上がった。一方、GP2 (Pin5) に赤外線LEDとともに抵抗を介して接続したリモコンから信号を受信して点滅するLED (R)は常時点灯して役目を果たさなくなった。そこでLED (R)をGP4 (Pin3)に接続しなおしプログラムで受信状態を表すようにした。

 

 

                     左が完成したリモコン中継器本体、真中に小さいIR受信時に点滅するLED、ボックスの下に付いている黒いものはリモコンからの信号受信モジュール

                     右下方には15m程のケーブルにつながれた発信用IRLEDが見える。右の写真は本体の内部、電源はUSB5Vでソケットで抜き差しできる

 

扇風機のリモコン受信部の近くに設置した赤外線LED

 

リモコン中継器PLUS:下に示すような上のリモコン中継器と全く同じ回路のものを途中に何台も加えれば30―50mといった長距離もOKのはず

 

 

波形のオシロによる測定 (Signal wave-forms measured by oscilloscope)

 

扇風機のリモコンの入/切SWを押したときの赤外線リモコン受信モジュールからの出力波形(PicのGP5に入る)、受信で5Vが0Vに変化 (Measured at the out of IR remote reception module when ON/OFF SW of the electric fan is pressed)

 

扇風機のリモコンの入/切SWを押したときのPicのGP2からの出力、反転している

 (Output from Pic's GP2 when ON/OFF SW of the electric fan is pressed)

 

                      同じく入/切SWを押したときのGP2の出力を100ohm抵抗のすぐ後で測定したもの、電圧がかなり下がるが正常に動作する (Output from Pic's GP2 via 100 ohm resister when ON/OFF SW of the electric fan is pressed)

 

 

結果&コメント

1)     上記の回路でリモコン中継器は周囲の影響(蛍光燈など)などもなく、違った種類のリモコン(TV1種、扇風機2種をテスト)でキビキビ動作することが分かった。

2)     プログラムの中でリモコンの受信をLEDの点滅で知らせるために入れたOutLEDindicater が誤動作を起こさないか心配されたがOKだった。

2)    GP2+100ohm抵抗の後につなげるケーブルの長さは15m位に伸ばしても問題なかった

3)    Reset SWは蓋の上に移すか、廃止してもOK。

4)    短かいプログラムだが、考えつくまで1週間ほどかかった。

5)    総材料費は1500円ほど。組立て作業に2日ほどかかった。もちろん予備実験はボード上で行った。

6)    リモコン中継器PLUSを製作して実験してみた。リモコン中継器PLUSから約5m 離れたリモコン中継器本体にIRビーム信号を送り、それにケーブル接続で15m離れたところにある扇風機を制御できた(追加:2013.8.5)。

 

プログラム

12F683のPWM機能をいかに正しく設定し、それをプログラムの流れの中でどのようにON/OFFするかがポイントであった。以下に示すように10行ほどの実に簡単なプログラムで目的を達成することが出来た。プログラムの流れは、まずリモコンからの入力をGP5から読み込み、それが0だったらPWMonに飛んでCCP1CON=12 で 38KHzの搬送波を出力させ、ついでGP4をONにしてLEDを光らせ信号を受信したことを知らせる。またLoopでもとに戻り、まだ入力が0なら同じことを繰り返す。したがって入力が0である間は 38KHzの搬送波がGP2より出力される。もし、GP5への入力が1の場合はPWMoffに飛んでCCP1CON=0で搬送波の出力はなく、GP4へ接続されたLEDも消える。Loopで戻って再び2行のIFで選別され、外部のリモコンからの入力に応じて、いろんな幅の搬送波のHパルスといろんな幅のLの部分からなる信号をGP2経て赤外線LEDより出力し続ける。リモコンのどのキーも押していない時はGP5への入力は1となりPWMoffに飛んで搬送波を出さなくし、GP4へ接続のLEDもOFFに保って、Loopでもとに戻ってリモコンからの入力を待ち続ける。

‘********************************************

'12F683HPWMA.bas  2013.7.28 (modified from2010.6.4)  38.75KHz-PWM output from GP2 (Pin5) Works OK!

'12F683 with internal clock 4MHz

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

'Pin 1: Vdd (5.0V)

'Pin 8: Vss (GND)

'Pin 7: GPIO.0: NC

'Pin 6: GPIO.1: NC

'Pin 5: GPIO.2: output - 38KHz-PWM output to IR LED

'Pin 4: GPIO.3: input - connected to MCLR via 4.7kR to Vdd

'Pin 3: GPIO.4: output - LED-indicator output

'Pin 2: GPIO.5: input - from Remote controller (via IR receiver)

 

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

VRCON=0              'A/D voltage reference disabled   以下の初期設定が大変重要!

TRISIO=%101000     'GP3, GP5 - Iput, GP2 - PWM output, GP4 – LED output

ANSEL=0               'All ports are digital

CMCON0=0             'No comparator used

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

CCPR1L=13            'Set PWM for 50% duty cycle

'CCP1CON=%00001100    'PWM mode selection to be used for switching ON/OFF of HPWM function  下のプログラムでこれを操作

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

RconInput var GPIO.5       'Remote controller input  GPIO.5をRconInputと定義する

OutLEDindicater var GPIO.4  'Output LED indicator   GPIO.4をOutLEDindicaterと定義する

 

Loop:                   ‘ここから下のGoto Loopまではリモコンの入力待ちルーチン

If RconInput=0 then PWMon    ‘この2行でリモコンからの入力が0か1かを判断して下のPWMonかPWMoff:に飛ぶ

If RconInput=1 then PWMoff

 

PWMon:             ‘RconInput=0の時、下でCCP1CON=12で38KHzの搬送波を出し、High OutLEDindicaterでLEDをONにする

CCP1CON=12

High OutLEDindicater

Goto Loop           ‘上のLoopに戻って、また上の2個のIFでどこえ飛ぶか判断する

 

PWMoff:             ‘RconInput=1の時、下でCCP1CON=0で38KHzの搬送波の出力を中止し、Low OutLEDindicaterでLEDをOFFにする

CCP1CON=0

Low OutLEDindicater

Goto Loop                  ‘上のLoopに戻って、また上の2個のIFでどこえ飛ぶか判断する。

 

End

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

'Note:

   'Programmer's configuration must be set as follows:

   'OSC – INTOSCIO; WDTE - Enable; PWRTE – Disable; 'MCLR – Reset; Brown-out Reset - Enable

   'Internal External Switch Over – Enable; Fail Clock Monitor - Enable

   'CD – Not Protect; Data EEPROM – Not Protect

                                        上記プログラムのHexadecimal出力。短くて簡単。12F683に焼込めばOKのはず。

(Hexadecimal output of the program 12F683HPWMA.bas for Remote Control Repeater)

 

 

Remote Control Repeater (English version of the above Electronics Project 67 in Japanese)

Summer here in Tokyo is hot and very humid. Daytime is all right because I can escape to subway, bus or cafe, which are normally fully air-conditioned. Nighttime is a problem. When the temperature is over 27 to 30C and humidity is higher than 70 to 80 percent, it is very uncomfortable to sleep. I don't have air-conditioner but have several small and large electric fans. During such hot and humid nights, I bring cooler air (not always cooler) into my bedroom from the windows in the north side of my unit by using an electric fan. The fan is equipped with remote control. I want to control the fan from my bed but the distance between the bed and the fan is over 10 meters and there are two walls between them, blocking the passage of infrared signal beam from the r emote control. So I have decided to make a remote control repeater.

 

Circuit Diagram

Since I know that Pic 12F683 can generate 38KHz-carrier with its PMW function relatively easily, I used it for this purpose. The diagram shown below is found to produce a satisfactory result. As the power supply I used a conventional USB (5V, 1A) adapter due to its simplicity. The IR remote control reception module receives IR signal emitted from a remote control, read into GP5 of 12F683, processed by the program within it, and finally outputted from GP2 to IR LED, which activates the IR system of an electric fan. About signal wave-forms, refer to Signal wave-forms measured by oscilloscope in the above Japanese version.

 

Remote control repeater (outer and inner views) and the electric fan base attached with IR LED

Results:

1) The remote control repeater works well, fairly accurately controlling an electric fan located about 15 meters away from the repeater.

2) The tested work-proven distances between the remote controls and the remote control repeater were 5 to 10 meters.

3) Three kinds of remote controls (one type for TV, two types for electric fans) were tested and found to work well.

 

Program:

Simple is the best! When infrared signals for remote control are dealt with, a carrier of 38KHz is required to prevent the interferences. Pic 12F683 has a hardware PWM function. By simply switching ON/OFF the PWM function, it becomes possible to form the output (from GP2) "1"composed of 38KHz carrier and "0" with no carrier. That is, CCP1CON=12 or =0 is the key statement; when it is set to 12, the carrier is generated, while when it is 0 there is no carrier. The initial set-up list of 10 lines is critical. In the program, the system waits the input from GP5. If the input is 0, it jumps to PWMon and turns on the PWM (generating the carrier), then returning to Loop. This looping lasts as long as the input is 0. Meanwhile, if the input is 1, the system jumps to PWMoff and turns off the PWM, then again returning to Loop. This process lasts as long as the input is 1. Like this, the output signals from Pic’s GP2 are produced. In the program, "High OutLEDindicator" and "Low OutLEDindicater" are included to turn on/off the LED indicator for a very short period of time whenever the IR reception is made at GP5. Initially it was concerned about the occurrence of errors by including these statements but there seems to be no problems.

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

'12F683HPWMA.bas PicBasic Pro V2.50A used, 2013.7.28 modified (2010.6.4)  38.75KHz-PWM output from GP2 (Pin5) Works OK!

'12F683 with internal clock 4MHz

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

'Pin 1: Vdd (5.0V)

'Pin 8: Vss (GND)

'Pin 7: GPIO.0: NC

'Pin 6: GPIO.1: NC

'Pin 5: GPIO.2: output - 38KHz-PWM output to IR LED

'Pin 4: GPIO.3: input - connected to MCLR via 4.7kR to Vdd

'Pin 3: GPIO.4: output - LED-indicator output

'Pin 2: GPIO.5: input - from Remote controller (via IR receiver)

 

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

VRCON=0              'A/D voltage reference disabled

TRISIO=%101000       'GP0 - Input, GP2 - PWM output

ANSEL=0              'All ports are digital?

CMCON0=0             'No comparator used?

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

RconInput var GPIO.5       'Remote controller input

OutLEDindicater var GPIO.4 'Output LED indicator

 

Loop:

If RconInput=0 then PWMon

If RconInput=1 then PWMoff

 

PWMon:

CCP1CON=12          'PWM to ON

High OutLEDindicater

Goto Loop

 

PWMoff:

CCP1CON=0          ''PWM to OFF

Low OutLEDindicater

Goto Loop

 

End

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

'Note:

   'Programmer's configuration must be set as follows:

   'OSC – INTOSCIO; WDTE - Enable; PWRTE – Disable; 'MCLR – Reset; Brown-out Reset - Enable

   'Internal External Switch Over – Enable; Fail Clock Monitor - Enable

   'CD – Not Protect; Data EEPROM – Not Protect

 

Menu Pageへ戻る

Topへ戻る