RC hack: how to detect 5 leds that are ON at the same time?

Hello all,

I own an Arduino Uno and I've been playing with it for a while now but I'm about to start my first real "project".

I have a remote control (the guinea pig) for my shutters. It has 4 buttons : - up - down - stop - select

And it has 5 leds: each represents a shutter.

The select button is what I'm interested about. By pressing on it, you loop between all 5 shutters plus a special "all of them" combo. When you're on the "all of them" position, all leds representing all shutters are on.

I can easily connect my arduino to all the buttons (using optocouplers) but I need to be able to synchronize the arduino with the remote selection to know which shutter is selected on the remote. This way there's no chance of being desynchronized if the arduino is powered down and so on.

The whole thing being a loop (1, 2, 3, 4, 5, all), I just need to catch one state and go from there. Given there's no dedicated led for the "all of them" position, my only solution (maybe there's a better one though, feel free to tell me) is to catch the "all lights on" event.

Question is: how can I detect that all leds are on at the same time? I searched and I haven't found something similar to my problem (mostly stuff like voltage ladders and so on). I don't need to detect multiple states but just one: all on.

Looking forward to your comments and questions.

Cheers, Matt

If you pick your pins carefully you can use direct port reading. This will return a byte with one bit for each pin. You can then use the & function to ignore the bits you are not interested in and then do a test to make sure they are all high.

for example

if(( PORTB & 31)==31)
   DO STUFF HERE

Just sensing the buttons won't work because your Arduino code and the remote itself will have different ideas about button scanning and debouncing - there's no guarantee they will agree about if a button is pressed. In practice it may work most of the time, but its not guaranteed. Perhaps sense all the LEDs individually? You'd have to sense at least two anyway.

MarkT:
Just sensing the buttons won’t work because your Arduino code and the remote itself
will have different ideas about button scanning and debouncing - there’s no guarantee
they will agree about if a button is pressed. In practice it may work most of the time, but
its not guaranteed. Perhaps sense all the LEDs individually? You’d have to sense at least
two anyway.

I don’t want to sense the buttons: the remote will be hidden away and only the arduino shall be “pressing” on the buttons. That’s why I just wanted to detect the state I’m in and change it until I’m back to a known spot.

But yes, you made a genius comment, I don’t need to sense all 5 of them. Two is enough because it’s either a single led or all of them on. So if I find two of them on, it means the 3 others are on as well. Thanks, I didn’t think of that.

KenF: If you pick your pins carefully you can use direct port reading. This will return a byte with one bit for each pin.

I get it: using PORTB or PORTD I could detect simultaneous inputs.

Thing is, how do I wire that then? I mean say I have 2 LEDs (thanks MarkT): I just run one wire from each one to two separate digital output? What about ground? What I had learned about eletronics is long gone...

No you won't get anything useful from PORTB or PORTD since those are output registers, you use PINB and PIND for input.

MarkT: No you won't get anything useful from PORTB or PORTD since those are output registers, you use PINB and PIND for input.

That would certainly work better :blush:

Haha true.

But what about wiring though?

I just connect the anode of the led to a digital input and that’s it? No common ground or anything?

I thought you'd have access to the buttons to wire them into the arduino. Is this not the case?

I do have access to the buttons.

But as I mentioned, there's only one select button which cycles through shutter 1 to 5 and all.

So the only way for the arduino to know where it's at, is to catch the state of the leds.

Eg: the arduino starts. Doesn't know in which state the remote is.

  1. Arduino presses select.
  2. Are 2 LEDs on? If yes, that's it we can go from there (as pressing the select button just cycles the sequence). If not, go back to 1.

So having access to the select button doesn't tell me which shutters are selected: I have to know the initial state. Hence the loop above.

Sorry I'm lost. I don't understand. If the arduino can't read the LEDS because they are on the remote, then it won't be able to read the button either (assuming that's on the remote)

If the button is on the arduino and the arduino is playing some part WITHIN the remote then, surely, as it lights up the LEDs it will be able to remember what it did to them last.

I think you've not explained the project very well.

I'm also lost, draw a schematic. IF you only need to detect "all on", wire LEDs in 5 optocoupler in series with the 5 remote led. Wire all optocouplers output in series and conect it to your arduino. Was this an answer to your question?

If you want to know which led are on, conect each optocoupler to 5 inputs and detect in software. Was this an answer to your question?

Pelle

Everything is on the remote, cf first post.

I have a remote control (the guinea pig) for my shutters. It has 4 buttons : - up - down - stop - select

And it has 5 leds: each represents a shutter.

The arduino would be pressing the buttons but if it's shut down for some reason, when it powers up there's no way it can know in what state it left the remote.

I'm not asking to read buttons, I want the arduino to press the buttons (through optocouplers).

So forget about buttons, I just want to read LEDs. That's it.

So yes, I guess I could also use optocouplers to read LED statuses.

The only thing I'm unsure about is how to wire an optocoupler to a LED?

matmat: I'm not asking to read buttons, I want the Arduino to press the buttons (through optocouplers).

Optocouplers are unnecessary.

matmat: So yes, I guess I could also use optocouplers to read LED statuses.

You could use all sorts of things.

I am fascinated by all the answers playing "Blind men and the Elephant".

You need to show a picture of the remote control. While not essential, it is worth the proverbial "thousand words". Note the requirements for a picture - fully focused, resolution no more than 1024 by 768 (or preferably, 768 by 1024!).

Now the serious part. What is important is what voltage it uses (batteries), and whether the buttons (apparently not one but five from your description) and LEDs are connected to the positive or negative side of the battery, and whether there are any other switches on it?

Another thing, is this perhaps an infra-red remote? If so, it may be more practical to use the infra-red library to decode the command structure and simply have the Arduino generate the appropriate control codes with a few IR LEDs.

Paul__B: Optocouplers are unnecessary.

Duly noted.

Paul__B: You need to show a picture of the remote control. While not essential, it is worth the proverbial "thousand words". Note the requirements for a picture - fully focused, resolution no more than 1024 by 768 (or preferably, 768 by 1024!).

Here you go.

Paul__B: Now the serious part. What is important is what voltage it uses (batteries), and whether the buttons (apparently not one but five from your description) and LEDs are connected to the positive or negative side of the battery, and whether there are any other switches on it?

It's powered by 2 x AA batteries. There are 4 buttons (from the bottom up: select, down, stop, up).

I'm not sure how to answer your questions regarding the way buttons and LEDs are connected. I mean how do I know in which direction I'm supposed to measure that?

The LEDs I'm interested in are the 5 at the top (forming a star). They show which shutter is going to be controlled by the up/down/stop buttons. The selection is a loop and lights up one LED at a time or all of them for all shutters: - shutter #1 - shutter #2 - shutter #3 - shutter #4 - shutter #5 - all shutters

The select button is the one at the bottom on the picture. Before I can make the arduino press up/down/stop, I have to know which shutter is selected. I could track all 5 LEDs but given only one can be on at a time or all of them, just tracking 2 is enough. If 2 are on, it means they're all on. At this point, it's easy for the software to know what the selection on the remote is. Then I can make the arduino press select until it selects the shutter I want.

Paul__B: Another thing, is this perhaps an infra-red remote? If so, it may be more practical to use the infra-red library to decode the command structure and simply have the Arduino generate the appropriate control codes with a few IR LEDs.

Nope, it's radio, a proprietary protocol on the 868.3 MHz band with a rolling code. Hence hacking the remote rather than trying to understand what it really does.

Here's the remote when it's not dissassembled.

matmat: It's powered by 2 x AA batteries. There are 4 buttons (from the bottom up: select, down, stop, up).

And eight LEDs in total. All single colour? Do the ones around the button have any special function? OK, I mis-read your original description.

matmat: I'm not sure how to answer your questions regarding the way buttons and LEDs are connected. I mean how do I know in which direction I'm supposed to measure that?

Well, you trace the PCB tracks. For a start, it looks as if the LEDs all return to the positive rail. You can double check with a meter.

OK, so they are running off 3V, of course they are obviously red. :D So to sense them, you need PNP transistors with emitter to positive, and base to the other side of the LED through a 47k resistor. The collector will pull up to 3V (not 5V) when a LED is on. If the buttons go to ground, then NPN transistors can be used to spoof them. Clearly this unit has an automatic "sleep" mode (all LEDs off) if you have not used it for a certain time.

Note that your Arduino will be operating at 5V (though you could I suppose use a 3V 8 MHz Pro Mini and interface it directly to the LEDs and buttons without the transistors - just the resistors for the LEDs) so you need to use a common ground (negative) and you can probably power the remote from whatever supply you are using (not batteries) with a 3V regulator (LM317). Another alternative is to use a 74HCT chip such as a 74HCT14 as a level converter for sensing the LEDs.

matmat: The select button is the one at the bottom on the picture. Before I can make the arduino press up/down/stop, I have to know which shutter is selected. I could track all 5 LEDs but given only one can be on at a time or all of them, just tracking 2 is enough. If 2 are on, it means they're all on. At this point, it's easy for the software to know what the selection on the remote is. Then I can make the arduino press select until it selects the shutter I want.

Yes, but probably nicer to monitor all five. A 74HCT14 would be easy, one chip and a resistor array..

matmat: Nope, it's radio, a proprietary protocol on the 868.3 MHz band with a rolling code. Hence hacking the remote rather than trying to understand what it really does.

Fair enough. Can't argue with that!

I think I get the jist of what you're trying to do. From what I understand:

Usually the user will select which blind to close by cycling through a sequence (indicated by the leds). One option in this sequence is ALL blinds close. Once the user has found the point in this sequence that suits them they press "select" and the appropriate blind(s) will be closed.

Your objective Create a single button for the user that will then cause the remote go go through the selection sequence until it finds "all blinds closed" (indicated by more than one led being illuminated) at this point it will then virtually press the "select" button,

Am I getting close?

Looking at the picture you have posted it appears that the two leds on the left both have their catthodes connected directly to the negative connection of your battery pack.

You should be able to check this out with a multimeter. you could then check the voltage measurement across one of these when it is illuminated (my guess about 0.6 v) or not (my guess floating)

So connecting the positive side of this led to one of your arduino analogue inputs will allow you to detect that signal. If you do that for the other LED into another analogue port. Your task would be achieved. Then all you'll need to do is run a sketch that checks for 0.6v on both leds.

KenF: I think I get the jist of what you're trying to do. From what I understand:

Usually the user will select which blind to close by cycling through a sequence (indicated by the leds). One option in this sequence is ALL blinds close. Once the user has found the point in this sequence that suits them they press "select" and the appropriate blind(s) will be closed.

[...] Am I getting close?

Close enough. Arduino uses select button to select blinds that are to be controlled and then uses up/down to open or to close them (as told by some home automation software). So the user is really the arduino.

KenF: Looking at the picture you have posted it appears that the two leds on the left both have their catthodes connected directly to the negative connection of your battery pack.

You should be able to check this out with a multimeter.

How do I check if the cathode is connected to the negative connection of the battery pack? I mean if I use a multimeter, all I find is everything is connected to everything haha.

KenF: you could then check the voltage measurement across one of these when it is illuminated (my guess about 0.6 v) or not (my guess floating)

If I check the voltage of a led when it is illuminated, I find 2V (and 0 when it's not). I measured the one above the Elero logo, anode to the left, cathode to the right.

KenF: So connecting the positive side of this led to one of your arduino analogue inputs will allow you to detect that signal. If you do that for the other LED into another analogue port. Your task would be achieved. Then all you'll need to do is run a sketch that checks for 0.6v on both leds.

In that case it's 2V but that is still acceptable for the Arduino. So you're saying I could just run a wire from the positive side to an analogue input. That's it. No common ground, nothing else? 2 wires for 2 LEDs and be done with it (I'd like that haha).

Paul__B: And eight LEDs in total. All single colour? Do the ones around the button have any special function? OK, I mis-read your original description.

8 LEDs total. They're all dual colour: red and green! :)

The ones around the buttons have a special function but not one that I'm interested in at the moment. They always glow together as a pair. When you select a blind through the select button, the glow green when the paired blind is available and red if it's not (as in "in range", "we can talk"). When you push an action button (up/down/stop), they glow red to acknowledge your input then green if the blind replied back (it's bidirectionnal so you can tell if the blind really got the order).

The one to the right tells you the status the remote is in (programming or just standard mode).

Finally the 5 blind LEDs always glow green even though they're dual colour.

Paul__B:

matmat: I'm not sure how to answer your questions regarding the way buttons and LEDs are connected. I mean how do I know in which direction I'm supposed to measure that?

Well, you trace the PCB tracks. For a start, it looks as if the LEDs all return to the positive rail. You can double check with a meter.

Well if I measure between the + from the battery pack and what seems to be the anode (the left side of the LED above the elero logo), I mesure 0 Ohm. So that's connected. And looking at the traces the cathodes go to the atmel chip (if that makes any sense).

Paul__B: OK, so they are running off 3V, of course they are obviously red. :D

2V when I measure and red and green. :D

matmat: So to sense them, you need PNP transistors with emitter to positive, and base to the other side of the LED through a 47k resistor. The collector will pull up to 3V (not 5V) when a LED is on. If the buttons go to ground, then NPN transistors can be used to spoof them. Clearly this unit has an automatic "sleep" mode (all LEDs off) if you have not used it for a certain time.

Ok the PNP thing is doable and the NPN as well (I even understand haha). Yes, the remote goes to sleep after a couple of seconds.

matmat: Note that your Arduino will be operating at 5V (though you could I suppose use a 3V 8 MHz Pro Mini and interface it directly to the LEDs and buttons without the transistors - just the resistors for the LEDs) so you need to use a common ground (negative) and you can probably power the remote from whatever supply you are using (not batteries) with a 3V regulator (LM317). Another alternative is to use a 74HCT chip such as a 74HCT14 as a level converter for sensing the LEDs.

Mmmm now you're making me think. Less soldering would be easier I guess. I'll do some reading to understand what the 74HCT does.

matmat: Yes, but probably nicer to monitor all five. A 74HCT14 would be easy, one chip and a resistor array..

Meh, five is overkill really as there's no other combination than only one on or all of them. Plus given I don't know yet what your 74HCT14 does...