How do IR remotes wake up on key press? - Page 1
Forum section: electronics / beginners

author: Peabody
author_rank: Super Contributor
timestamp: September 06, 2019, 02:08:26 pm
content: I'm working on an Arduino-based IR remote code generator that will work like a standard remote, using keypress entry on a 4x3 matrix keypad. And I want the battery to last a long time. I always assumed that remotes were truly OFF, and drawing no current at all, until a key is pressed. But I'm having trouble coming up with a way to do that, so maybe my assumption is wrong. Does anyone here have experience designing remotes?If the processor has to ON, but asleep, until a key is pressed, then with Arduinos in particular I would be concerned about how deep the sleep could be and still wake up fast enough to process the keypress, particularly if the oscillator is off during sleep.

author: agehall
author_rank: Frequent Contributor
timestamp: September 06, 2019, 02:39:13 pm
content: Check the data sheet for whatever MCU you are looking to use. I would not expect the wake up time to be a huge problem for a remote control application. Things move so slowly in the world of user interactions anyway that whatever time it takes the MCU to wake up, it is probably nothing compared to the speed with which the user presses the buttons.

author: Ian.M
author_rank: Super Contributor
timestamp: September 06, 2019, 02:46:34 pm
content: A 455KHz resonator can start and become stable in 1000 cycles. That's under 2.2ms, which is negligible in human button press terms. If you use the stock Arduino ceramic resonator, it may take a few more cycles, but at 16MHz the delay is truly negligible. Other wakeup or reset delays should be insignificant.Use a bare AVR so you don't have all sorts of stuff on the rest of the board leaching off your Vcc rail, and put it in power-down sleep mode waiting for a pin change interrupt to wake it up on any keypress on any of the key matrix lines (e.g monitoring all the rows as inputs with internal weak pullup with all columns set to output '0' immediately before going to sleep), and, assuming you don't need any sort of timed wakeup, an ATmega328P can draw less than a uA, so 3x A76/LR44 alkaline button cells (for Vcc=4.5V dropping to 2.7V at EOL, so use INTOSC or an 8MHz resonator) will basically last as long as their shelf life if the remote is rarely used.In practice board surface leakage current through accumulated spooge under the contact mat will probably dominate. 3x AAA batteries would be a better choice if you can afford the weight and volume, as their larger capacity can tolerate a much higher quiescent current without impacting the usable lifespan.

author: golden_labels
author_rank: Super Contributor
timestamp: September 06, 2019, 03:01:40 pm
content: LR6 (Alkaline AA) at 5mA discharge rate work for 600–800h(1). On log-log scale the current/service hours curve is approximately linear, so Iguessthey may hold for over 4kh with a µC running in sleep mode. And that is half a year. 3Ah, low self-discharge rechargeables are also available and they will easily live that long too.But even if my guess above is wrong, there are switches that are drawingnocurrent when turned off (the default) and are activated by being pulled down/up. Then they conduct until they receive a turn-off signal. This way you may enable the controller whenever a key is pressed. There are existing parts to perform that task, but you may build one yourself. As it happens, Dave even made video on that topic (the first part is of interest to you):Pulling down/up from multiple buttons may be achieved with a simple diode logic OR gate. Turning it off from Arduino may be a bigger problem, because you must keep the disable signal on while the µC itself is already being turned off. For this reason I would stick to just keeping the controller in the sleep mode if that suffices. Otherwise the cost of parts needed for the circuit may exceed the cost of using the solution based on keeping the controller in the sleep mode. Not to mention all the pain of implementing it and space wasted.____(1)Based on the datasheet forDuracell Coppertop, as an example of consumer AA batteries.

author: mikerj
author_rank: Super Contributor
timestamp: September 06, 2019, 03:48:21 pm
content: Many micros can be configured to wake up from sleep by a change in port pin state. Use these pins for your key scanning.

author: Peabody
author_rank: Super Contributor
timestamp: September 06, 2019, 05:57:50 pm
content: Ok, it sounds like I was wrong about remotes being completely powered down. They're just sleeping. And there would be no economic benefit from powering them down because with sleep currents being so low, sleeping would just mean the user might have to replace the batteries a week earlier after a couple years.So the Atmel chip should work fine with no regulator, USB adapter or power LED. And maybe using the internal oscillator at 8 MHz so 3V would work, if that's accurate enough. A better choice might be a Pro Mini with an 8MHz resonator. And deep sleep just waiting for an I/O change on the column lines.Thanks for all the information.

author: MosherIV
author_rank: Super Contributor
timestamp: September 06, 2019, 06:51:45 pm
content: Most infra red remotes use asic chips that have very low power draw.QuoteThe clasic way to do it is to arrange for any keypad press to trigger the wake irq of the micro. As soon as the micro starts running the embedded program, it scans the key matrix to work out which key has been pressed. Then it can generate the pulse train out in infra red.

author: Ian.M
author_rank: Super Contributor
timestamp: September 06, 2019, 11:11:26 pm
content: There's one more trick you can do to optimise battery life (but check compatibility with the specific type of IR receiver its going to be used with): design the IR LED driver for max rated output (less a moderate safety margin), at the 3/4 discharged battery voltage when driven by a 50% duty cycle PWM, use the ADC's 1.1V FVR with ADC Ref from Vcc to calculate the actual battery voltage, then, if its not yet discharged to 3/4, reduce the PWM duty cycle according to the battery voltage to maintain the same average LED current. The effective optical power at the receiver will vary a bit but far less than if you drove the LED at flat out max. pulsed If when the batteries are brand new, and you'll extend the active battery life by your If safety margin. Past 3/4 discharged, you are on the tail of the Alkaline characteristic with increasing internal impedance and an accelerating voltage drop, so in most cases you'll get more use out of them by letting the average current drop off and the range decrease rather than trying to maintain the output power. In all cases, if you don't want it to be a battery hog, you'll need a *LOT* of low leakage bulk decoupling, so the rising battery impedance doesn't prematurely limit the pulsed IR LED load current.

author: amyk
author_rank: Super Contributor
timestamp: September 07, 2019, 12:42:56 am
content: A lot of remotes power the transmitter and encoder IC only when a button is pressed, so they do truly have 0 standby power (possibly neglecting the tiny amount of leakage current through the power switching transistor.)

author: Peabody
author_rank: Super Contributor
timestamp: September 07, 2019, 05:11:05 pm
content: At this point, I'm looking at an Arduino Pro Mini running on an 8 Mhz external resonator. While it has a 3.3V regulator, the schematic suggests that can be completely un-jumpered. The Mini would then be powered directly by a single 18650. I would probably not build in a charger, but just replace the discharged 18650 with a charged one as needed.There are Arduino libraries for both IR remote and keypads, so the programming should be pretty easy. I don't have a demodulating IR receiver, but was able to get the Roku IR codes for Back, Left, Right and OK using my scope and a plain IR phototransistor. For those interested, the Roku format is 32-bit NEC.So any of the three column lines would interrupt the Atmel and wake it up from deep sleep. On waking up, the sketch would identify the current key being pressed, wait for it to be released, then look for another keypress for perhaps a second. If another keypress is found, the first key value would be muliplied by 10, and second key value added in, then wait again for release. When a timeout finally occurs, the accumulated channel number value would be looked up in a table, and its corresponding My Channels position would be compared to the current position, and the number of Left's or Right's needed to get to the new channel calculated.After all the moving is done, the processor is put to sleep.The big problem is probably going to be finding an appropriate box to put it in. There ought to be a law that says anyone who manufactures a keypad has to specify a project box that fits it. :-) Or maybe there's a box that comes with a keypad installed.The IR library controls the duty cycle of the transmitter, and I believe it's 50%. But the recommended value is 25-33%. 25% would in theory save half your power usage unless it also effectively cuts the range in half, which I assume it does (otherwise this would be a free lunch, which is not permitted).

author: amyk
author_rank: Super Contributor
timestamp: September 07, 2019, 05:27:19 pm
content: Quote from: Peabody on September 07, 2019, 05:11:05 pmYou have created a "stateful" remote, and in my experience those will always go out of sync with the receiver side and frustrate you that way, so I suggest redesigning your solution so that the remote is as dumb as possible and all the complex processing happens at the receiver. Pressing a key should do nothing more than continuously transmit that key's code.

author: Peabody
author_rank: Super Contributor
timestamp: September 07, 2019, 10:05:02 pm
content: Quote from: amyk on September 07, 2019, 05:27:19 pmThe receiver is a Roku, and I have no way to change its firmwear or behavior. So if this doesn't work, I'm not sure I have any alternative solution. I could try to use the wifi version of the remote, but I think it would suffer from the same sync issue IR does. Well it isn't going to cost much to try the IR other than my time.

author: amyk
author_rank: Super Contributor
timestamp: September 08, 2019, 01:12:36 am
content: Make a retransmitter, like what used to be common for turning on the TV at the same time as the cable box/VCR, and do the stateful logic there.

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 08, 2019, 02:03:14 am
content: my recent circuit regarding remote control attached for 3 switches... when a button is pressed, mcu will hold power by output HI on gp through either sw1 or/and sw2 nodes, and it can detect which of the 3 buttons is pressed by shifting IO state. after it finish doing the transmitting, gp is set to LO, Q1 and Q2 will shut off everything. current consumption (leakage) during off is 15uA. with 1500mAh battery, thats 11 years of idle but thats too optimistic... C2-C4 can be replaced with resistors but circuit will ON as long as if someone press a button. pic10f206 sleep current is 0.1uA but i was having trouble with sleep/wake up issues last time, so i'm exercising transistor switch in this circuit, will be useful reference for me when i use more power hungry mcu later. by the 0.1uA figure in datasheet, battery direct on pic10f206 mcu and sleeped should be better, suggestion to improve is welcomed. if transmitter is only one switch like my diy door bell, the switch is connecting to battery direct, if switch is not pressed, battery will last till the end of time, theoritically.

author: sokoloff
author_rank: Super Contributor
timestamp: September 08, 2019, 11:24:43 am
content: Does "NA" mean "0" or infinite or something else? (I'm a struggling beginner at analog electronics.)I think it can't mean 0, but I'm not totally sure.

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2019, 12:52:22 pm
content: NA could variously be nA - nanoAmps, or N/A - Not Applicable.In this case I think Mechatrommer is misusing it instead of DNP - do not populate (optional components on the PCB layout but not fitted). It would be vastly preferable to also give the value e.g."DNP 10K" so you know what should be fitted there if it does need populating.

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 08, 2019, 02:43:34 pm
content: Quote from: sokoloff on September 08, 2019, 11:24:43 amsorry. thats a beginner work who stubbornly cant take advice from an expert, NA means Not Available (Not Applicable as Ian spotted), i mean... it can be Not Installed. it is there in case the nodes floating high due to some stray effect (resulting gp high and turning the circuit ON all the time), then i have to install pull down resistors. i'm dealing with less than ideal flux and solder element here. or simply just forget about it, the important idea is how the switching ON/OFF is made.

author: amyk
author_rank: Super Contributor
timestamp: September 08, 2019, 06:27:48 pm
content: Quote from: Ian.M on September 08, 2019, 12:52:22 pmThat's not the only thing misused in that "schematic"...Hint: a bunch of disconnected parts with net labels is NOT a schematic.

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2019, 07:10:41 pm
content: That's the modern OSHW 'style'. If us old farts that are used to being able to follow a wire on a paper schematic without needing an ecopy of it and a compatible viewer that can hilite by net name, went postal on all the young designers using it, we'd all be doing serious jail time and there'd be no-one left who actually remembers the hands on experience of the design lessons of the 20th century.

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 08, 2019, 07:55:19 pm
content: yeah sorry if its hard on some people. i didnt know about the DNP, NA or N/A is much more understandable in any discipline imho. unfortunately i kinda dislike DNP because its too sounds like DXP (Altium executable) sorry. even NA is not really what i meant. what i want is "Populate If Necessary" (PIN) or "Do Not Populate But Please Do If Necessary" (DNPBPDIN) or (DNPBPIN) but that will make nomenclatures much worst.i'm aware about those old style schematics, its neat in one single unit but man, for me its hard to trace or explode smaller circuit units into separate logical circuits. i dont have to take complex circuit like HP/Agilent/Tektronix DSO or PSU, things like alm's PSU in the other thread is hard to understand for ee noobs like me. i have to bend neck 90 and -90 degrees trying to understand what this transistor do and to where its connected logically, i never managed to understand it until today, people who made his circuit i guess is just blind copy paste it onto their circuit, or knowledgable enough first hand, in harser word maybe too clever or too stupid.furthermore, with the era of embedded/mixed signal circuit and EDA, disconnection is inevitable, to avoid spagethiness. we can check how Dave made the schematics in his video, a slight component addition to the old style circuit will be a nightmare, deleting and repopulating traces, rearranging component etc, at least for me. so somehow these aspect have educated me, the not original ee-born chap. in the schematics i linked, you can just make a selection box around those resistors and make it disappear (cut) and the circuit still applies.i know earlier generations are too meticulous and persistent with their work. with eraser, pencil and ruler (this includes mechanical CAD/drafting work) they are well respected, but this is EDA/CAD/CAM age, new generations maybe including me got stiffer, heavier and lazier arse esp if one is a Mechatrommer (3 in 1 master of none)this is off-topic btw. cheers.

author: Peabody
author_rank: Super Contributor
timestamp: September 09, 2019, 01:05:44 am
content: I got the basic device up and running this afternoon, so now I can enter the target channel as the channel number I'm used to using on Cox Cable, and my device will issue the IR commands needed for the Roku to get to that channel. But haven't addressed the sleep and interrupt issues yet. I think that should all be fairly straighforward since I don't need the ISR to do anything except wake up the processor.

author: Ian.M
author_rank: Super Contributor
timestamp: September 09, 2019, 03:11:54 am
content: Lets hope it stays in sync reliably.However if not, the best option may be to be to put a smart controller on your LAN where it can interrogate your Roku for its current status.The *easiest* way to do that would be runningLIRCon a Raspberry Pi Zero W. On the hardware side of things, just add an IR receiver and you can 'drive' it from any 'dumb' remote that doesn't conflict with any of your other AV kit. Add some small IR LEDs and a beefy driver transistor and you can control AV equipment that isn't network aware, e.g. to turn on the TV, select the input your Roku's on and control the TV volume etc.. On the software side of things, LIRC does all the IR protocol 'heavy lifting' but you will have to write the (probably Python) scripts to tie it all together and talk to the Roku ECP network control API.See:https://camp.isaax.io/en/isaax-examples/ir-control-via-lirc-on-raspberry-pi-zero-whttps://developer.roku.com/en-gb/docs/developer-program/discovery/external-control-api.mdand, for an actual implementation of Roku ECP control, albeit on an ESP8266:https://blog.adafruit.com/2018/09/29/homemade-roku-remote-uses-roku-external-control-api-huzzah-esp8266/which should save you much wading through the ECP API documentation and much headscratching!

author: Peabody
author_rank: Super Contributor
timestamp: September 09, 2019, 02:36:21 pm
content: I found that the Roku stays in sync if the interval between IR commands is 400ms, but it couldn't keep up at 250ms, and I ended up one channel short of the target. But at the slower speed it has yet to fail.I did the IR version because I had the parts to do it. But it turns out there are three ways to communicate with the Roku. In addition to IR, there appears to be an RF remote option, which is a direct RF communication (not through the router) between the remote and the Roku. Apparently Roku sticks have to use that because they have no IR, but I think all modern Rokus come with such an RF remote. I haven't found any information about how that works.But then there's the ECP thing, which takes place over the LAN using the Roku's IP address. I assume that's what the iOS and Android Roku apps use. The ESP8266 device you linked to is what I would fall back to if IR doesn't work well in the end. Since this would be battery powered, I think this would be a better option than a Pi, and of course much less expensive.But one thing isn't clear to me. It seems with ECP you can command the Roku to play a specific channel by name. But in my case the channels I want are within Sling, so they are one level down from the Roku Sling channel. I don't see a way to send commands to Sling.I'm thinking of using the * key to tell the Arduino what the current Sling channel actually is - in case it gets out of sync - or maybe just reset it to the first channel. And maybe the # key could tell my TV to toggle the input between HDMI and OTA. I might even throw caution to the winds and get a 4x4 keypad. :-)

author: Ian.M
author_rank: Super Contributor
timestamp: September 10, 2019, 02:47:17 am
content: The Pi would sit next to the Roku powered with a wallwart and itself controlled over IR from a dumb(ish) off-the-shelf remote, e.g. a universal one programmed for a brand of kit you don't own. If not all the commands/functions you need are accessible by ECP, you could use a hybrid approach: Use ECP to get the Roku into a known state as close as possible to the desired state then transmit IR commands from the Pi using LIRC to get the Roku into the desired final state.Although the Pi Zero W sold ''bare board' seems to be in short supply stateside (probably due to the poor profit margin for resellers if they aren't packaging them with accessories), Adafruit have it in stock for $10 USD, rationed to one per customer. Apart from a SD card, the Pi just needs a wallwart, an IR LED + driver transistor, and an IR receiver module, + a remote to control it, all of which can be scavenged from dead AV kit. An 8 GB micro SD card should be findable for around $5, so all in, it should be under $20. I think that's reasonably competitive against having to build custom handheld remote. Heck the case and keypad could well set you back more than that.To get going with it, you can headlessly tether it to your PC as a RNDIS device (USB 'ethernet adapter') and activate SSH, by editing files on its SD card, then once you've got a console over SSH, and have bridged the Pi RNDIS adapter to your PC's LAN adapter to let it use your internet, you can SSH into it to install VNC and then VNC to its desktop with full access (except for video playback) from your PC's mouse, screen and keyboard. Of course its *EASIER* if you can hook it to a monitor to check progress but its certainly not essential.Hint: To tether it, use a really short USB data cable that came with a phone you have retired, as cheap dollar store USB leads tend to drop too much voltage for a Pi Zero W to be stable tethered.

author: Peabody
author_rank: Super Contributor
timestamp: September 10, 2019, 04:59:06 am
content: I'm sorry, Ian, but I think you greatly over-estimate my level of knowledge. I don't know what LIRC, RNDIS or VNC are, and have never used a Pi or Linux. And I don't understand the need for a Pi when it appears even for the networked version an ESP8266 remote could do the same thing without the need for any IR - as in your earlier referenced Huzzah-based remote. As for the cost, the total for the Arduino Pro Mini, keypad, 18650 and 18650 holder would be about $18, and that's even paying up for US sources for fast delivery. Don't know about the enclosure yet. I already have the IR LED and an 18650 charger.Since the breadboard version of the IR remote is already working, I think for now I'm going to just get that into finished form and be done with it. If in the end it's not up to the task, the ESP8266 would be the next step.

author: Ian.M
author_rank: Super Contributor
timestamp: September 10, 2019, 08:34:12 am
content: No worries - just different approaches to the same problem. However a Pi is a cheap and easy introduction to running a Linux box, which with the way Microsoft is heading is good to have some knowhow about in case you need to 'jump ship'. The fact you can do cool stuff with its I/O pins is just the cherry on top. That really puts you back to the early PC days under DOS when you could hook any hardware you liked to a printer port or pop in a 24 line GPIPO card and talk to it direct from BASIC without installing any drivers.If you take away ONE thing from this discussion, I hope its the idea that if you need a WiFi Roku controller, its worth separating the power-hungry WiFi device from the remote you hold, using it as a base-station and giving it its own wallwart supply. Then the handheld end can be run for years on cheap alkalines, just like commercial remotes.

author: Peabody
author_rank: Super Contributor
timestamp: September 10, 2019, 04:53:26 pm
content: I take your point about the wifi power issue. But it remains a puzzle how the Roku RF remotes deal with that. They require pairing, but I don't know if that means they stay on all the time. I read somewhere, but can't find it now, that these modern Roku RF remotes can do straight RF, Bluetooth, or wifi network access. But I don't see complaints about batteries wearing out early. So it's a mystery.

author: Peabody
author_rank: Super Contributor
timestamp: September 19, 2019, 06:39:23 pm
content: I wanted to report where I ended up with this. I used an Arduino Pro Mini, 3.3V, 8MHz, with the regulator and power LED removed. It's powered directly by an 18650 Li-Ion battery. Pictures attached.The remote sleeps in Power_Down mode, with any keypress waking it up via a pin change interrupt. Apparently it awakens pretty quickly because I have yet to experience an instance when it wakes up but the keyboard.h library fails to detect the first keypress. And I'm doing a bunch of pin resetting stuff before I actually read the keypress.As best I can tell, when sleeping, the current draw is a bit below 0.5µA. So there's no ON/OFF switch.I have the following functions enabled:1. If I am already watching a Sling channel, entering a new channel causes the Arduino to issue two Back commands to get back to the My Channels line, then Left or Right commands to get to the new channel, and finally an OK command to start the channel playing.2. If the Arduino loses its place for some reason, entering the actual current playing channel number followed by the "#" key causes the Arduino to reset its currentChannel variable to that channel.3. If I enter the "*" key without a channel number, the Arduino will send the power toggle command to the TV, and issue a Home command to the Roku, which also terminates all streaming. So that's effectively a single-key shut-down of the TV and the Roku.4. If I enter the "#" key without a channel number, the Arduino issues commands to toggle the TV's input between antenna and HDMI.5. If I enter the desired channel number followed by the "*" key, from any state, the Arduino will issue the needed commands to:a. Home the Rokub. Go Right to the Sling iconc. OK on the Sling icon to select itd. Wait for Sling to begine. Move Down to the My Channels linef. Move Left or Right as needed to get to the desired channelg. OK on that channel to begin watching itSo far it seems to be working quite well.Thanks for everyone's help on this. I may put the Arduino sketch on Github at some point, although I "presented" this to my local OSH group meeting last evening, and got the same comments I got here - basically why didn't you do it through the network. So it appears unlikley anyone else would be interested in this IR version for this use, but someone may have a use for the keypad and sleeping stuff.

author: Peabody
author_rank: Super Contributor
timestamp: September 25, 2019, 06:43:45 pm
content: I've put everything in a Github repo in case anyone may be interested down the line.https://github.com/gbhug5a/Roku-Sling-IR-Channel-Number-Remote-for-Arduino