This is part one of a two-part
project. For part one, we will focus on IR remotes and signaling, as
well as IR reception and decoding.
Using IR (InfraRed)
radiation to control electronic devices is widely accepted and
implemented. IR devices are routinely used in alarm systems, automatic
door openers, and similar applications. This project makes use of coded
IR emissions from a Sony TV remote, and a PICAXE microcontroller to
manage the operation of a stepper motor. However, the same principles
could be used for the control of AC or DC motors, relays, buzzers,
lights, or almost any electrical or electro-mechanical device.Background Information
A trove of valuable information about infrared already exists here on AAC. Check it out by entering "infrared" or a similar term in the search box at the top of almost every page. Here are three examples:AAC also has additional knowledge available about the PICAXE microcontrollers. Here is a great place to start if you are not currently familiar with their operation and use, or you can use the AAC search engine to find more PICAXE references.
Not All IR Remotes Are Created Equal
Infrared remote controls come in a variety of sizes, shapes, and capabilities. Perhaps the simplest possible design is shown at the top of the photo below. It consists of an IR LED, a coin cell battery, a switch, and an enclosure to hold everything together (no series resistor is necessary because the battery's internal resistance adequately limits the current through the LED). Operation of the switch connects the battery to the LED and produces IR light; that's all there is to it.The simplest design for infrared remote controls: a switch connects the battery to the LED and produces IR light.
The device at the bottom of the above photo is only a little more complex. The IR LED is housed in the black funnel at the top right of the enclosure; the funnel is intended to help direct the IR radiation toward the target. The printed circuit board just to the left of the funnel contains a push-button momentary switch. When the switch is operated, power is applied to an NE555 configured as an astable multivibrator. An RC (resistor capacitor) circuit controls the frequency of the multivibrator; in this case, the operation is at 40kHz, which is a common frequency for IR remote controls. The IR LED is turned on and off at that frequency for the duration of the time that the push button switch is held operated. Note that this 40kHz pulse is different from the frequency of the light being emitted from the LED, which, in this case, is at a wavelength of 940 nm (nanometers).
The purpose of the 40kHz oscillation is to reduce false triggering that might occur in IR receivers that simply sense the presence or absence of IR light. Better receivers are designed to react only to pulsing IR light and ignore continuous IR light. This reduces the likelihood of false triggering of the receiver by IR light from devices other than the intended transmitters. Not only must the IR light be pulsed, but the pulse frequency of the transmitter (40kHz in this case) must match the frequency to which the receiver is tuned.
A modern IR remote control. Chances are, this is the type of remote you currently have for your TV.
Modern IR remote controls like the one shown above add yet another level of complexity to the mix. Because there are many buttons on the remote and each button conveys a different message to the receiver, each button must send a different code from all the other buttons. The codes can be from one to three digits long and are sent from the remote in one of a few different patterns depending on the brand of the remote. In this article, the focus will be on the Sony protocol which is commonly referred to as SIRC (Sony Infrared Remote Code). It is important to know that some brands of remotes other than Sony use SIRC.
Required Parts
Following are the parts required for the construction in part one of this project; parts needed for part two will be listed in part two. In addition, you will need assorted wire, solder, a well-regulated 5VDC power supply, and a PICAXE programming cable.Part Ref. | Description | Source | Item No. |
---|---|---|---|
R1 | Resistor, ¼ W, 22kΩ | Digi-Key | 22KQBK-ND |
R2 | Resistor, ¼ W, 10kΩ | Digi-Key | 10KQBK-ND |
R3 | Resistor, ¼ W, 1kΩ | Digi-Key | 1.0KQBK-ND |
R4 | Resistor, ¼ W, 470Ω | Digi-Key | 470QBK-ND |
J1 | Jack, 3.5mm, 3-Conductor | Digi-Key | CP1-3533-ND |
U1 | Microcontroller, PICAXE 08M2 | PHAnderson.com | PICAXE 08M2+ |
U2 | Receiver, IR, TSOP4840 | Digi-Key | TSOP4840-ND |
C1 | Capacitor, Ceramic, 0.1µF, 50V | Digi-Key | 399-9797-ND |
Q1 | Transistor, PNP, 2N3906 | Digi-Key | 2N3906-APCT-ND |
LED1 | Diode, Light-emitting, Blue, T1 | Digi-Key | MB5V640EL-ND |
N/A | Breadboard, Solderless, 400 Contacts | Digi-Key | 377-2094-ND |
N/A | Remote Control, TV, IR (must use SIRC protocol) | scrounge | N/A |
Enter the PICAXE
Searching the web for "SIRC protocol" will produce several explanations of the exact details of the SIRC. Fortunately, you don't need to deal with that level of detail. All current members of the PICAXE family of microcontrollers "speak" SIRC using the IRIN and IROUT commands. These commands are explained in the PICAXE Manual 2.Consider the schematic diagram and solderless breadboard layout photograph below. Note that the wire-color labels in the schematic diagram agree with the corresponding wires in the solderless breadboard assembly. You are encouraged to follow the solderless breadboard layout as shown because additional circuitry will be added to the assembly as the project progresses.
The circuit is rather simple thanks to the use of a PICAXE 08M2 µC and a TSOP4840 infrared receiver. Be very careful when making connections to the TSOP4840; it is not tolerant of improper power connections and can be permanently damaged if +V is connected to the wrong pin. The pinout diagram is shown below.
Pinout diagram for connections to the TSOP4840.
Decoding and Displaying Data
The TSOP4840 is an IC (Integrated Circuit) that receives IR signals through the round convex lens on its face and decodes the signals. The resulting data is presented to the PICAXE 08M2 on pinC.3 which is on leg 4 of the chip. From there, the software in the 08M2 (shown below) takes over; the comments in the code explain how it works.Download and install the code on the PICAXE 08M2. With your PICAXE programming cable still connected, when the code runs for the first time, it will start the PE6 (PICAXE Editor 6) terminal program that is built-in. You should see the terminal screen as shown below. If any of the settings in your terminal screen do not agree with those shown below, change your settings to make them consistent.
How your terminal screen should appear in the PE6 terminal program.
Next, using your Sony TV remote (or some other remote that uses SIRC for controlling a television), press the left arrow on the remote. If everything is as it should be, you will see the decoded data in the terminal window. It should be similar to the screen shown below.
How the decoded data from your TV remote should appear if everything in the PE6 terminal program is correctly set up.
Notice that the code "52" should be displayed; 52 is the standard code on a TV remote using SIRC protocol to indicate that the left arrow key has been pressed. If you see numbers other than "52," you may have pressed the wrong button on the remote, or your remote may be non-standard. In either case, don't worry; things are still good.
If gibberish appears when you press buttons on your remote, you probably are trying to use a remote that is not SIRC compatible. If nothing at all appears, your remote may not be compatible or you may have made a wiring error in your breadboard assembly. In either case, you need to troubleshoot your setup and correct whatever problem(s) you find.
Now, you may ask, "Why are there always at least three repetitions of a code?" The answer is that each code is repeated at least three times to help ensure that it is received correctly. If there are more than three repetitions, it is because you are holding the button down longer than necessary.
You can press any button on your SIRC-compatible remote and see what code that button sends by looking at the terminal screen. If you press a button and nothing is displayed, that likely means that the code sent is outside the range that can be received by the PICAXE microcontrollers. They are limited by design to 128 possible codes: 0 through 127.
If your terminal screen becomes too cluttered with numbers, you can click the Clear button in the terminal window to erase the data. If you should close the terminal program or power down the PICAXE, you will need to manually restart the terminal program by clicking "PICAXE" and then "Terminal" in PE6. This is necessary because the terminal program interferes with programming the PICAXE, therefore it must be shut down to allow programming.
You can download the code for this portion of the project by using the button below.
Adding a Visual Data Reception Indicator
While receiving SIRC data from a remote control and displaying the code on your monitor in PE6 has its uses, you aren't always going to be connected to your computer. Therefore, it would be helpful to add a visual indication that data is being received. That is the purpose of the added circuitry in the schematic and the solderless breadboard photo below.As you can see, there are only four additional components in the circuit. When U2 detects a 40kHz IR signal, its output (pin 1) goes low, which takes the base of Q1 low, which in turn switches Q1 on. Current can now flow from +V to ground through Q1, R4, and LED1, and thus a logic-low output from U2 causes the LED to illuminate. If the IR signal is an unmodulated 40kHz signal, LED1 appears to be continuously on, but if the signal is modulated (as determined by the SIRC protocol,) the LED appears to flash very rapidly. With a little practice, you will be able to determine whether 1) no signal is being received, 2) an unmodulated 40kHz signal is being received, or 3) a modulated IR signal is being received. Of course, this doesn't tell you that the signal is a legitimate SIRC signal or which button on the remote was pressed, but it is valuable information nonetheless.
Where's the Stepper?
As stated at the beginning of this article, this is part one of a two-part project. Part two describes controlling a stepper motor for maximum smoothness and the construction of a handheld mini-remote SIRC transmitter; it will also detail the connection of the PICAXE 08M2 to a ULN2003A and of the ULN2003A to a 28BNY-48 stepper motor. Half stepping will be used to make the motor move as smoothly as possible.Don't miss part 2; it's coming soon here on AAC!
No comments:
Post a Comment