Arduino between control panel and the device

I have a fan for ventilation which has its own electronics to control its speed, working time, moisture control, etc. The fan has its own control panel with 5 buttons and 8 LEDs. As the fan is located on the ceiling it is not that easily reachable and I want to add remote control and also connect it to the entire home automation scheme. Also, I want to make it in a non-destructive manner.

My plan is to put an Arduino pro mini (because it is small enough to put it behind the control panel) which to act as a proxy between the OEM control panel and the device. So when a button is pressed on the control panel it sends a signal to the Arduino which simulates the same button press to the device. When an LED is powered/lighted by the device it sends a signal to the Arduino and Arduino light the same LED on the control panel.

The control panel itself is a membrane keypad with 5 buttons and 8 LEDs. All LEDs and buttons share common ground wire. From the control panel a ribbon cable with 14 pins 1 mm pitch comes out.

What I consider to do is to attach those 5 buttons through different resistors (220, 390, 680, 2.2K, 4.7K) to an analog pin on the Arduino and read the button pushes. Then using a TLP281 optocoupler to connect the original wiring from the device to simulate the same pushes back to the device. 5 digital pins will go to the optocouplers for the 5 buttons.

Then again using TLP281 optocouplers I will “read” when the LEDs are powered by the device and pass the signal to the Arduino. The LEDs on the control panel will be connected through a resistor directly to a digital pin on Arduino.

A few questions:

  1. Any suggestions or drawbacks in the suggested approach?

  2. Wiring:
    2.1. LEDs from the control panel will be wired directly to the Arduino through 220 Ohm resistors
    2.2. Buttons will be connected to an analog pin each through different resistor as described above
    2.3. The TLP281 internal IR LED will be wired directly to the device as there is no significant difference from the LEDs on the control panel and everything should be fine

2.4. How to wire the emitter and the collector of the TLP281 IC to the Arduino digital pins (for LEDs input)?

The usual diagram is to connect the collector to the digital pin and pull up resistor (10K?) and the emitter to the ground of the Arduino. But that way the logic will be reverted - right? When the LED is powered the digital pin will be LOW and when the LED is not powered the digital pin will be HIGH. Am I correct?

2.5. How to wire the emitter and the collector of the TLP281 IC to the device buttons pins (considering that buttons use common ground)?

I suggest - emitter to the common ground pin on the device and collector to the selected button pin on the device. No extra pull up or pull down resistors and other components. I assume that the original buttons from the keypad are internally wired to the PIC, probably pulled up or down and debounced internally so I don’t plan to make it more complex. Does this sound feasible?

2.6. Do I need to have a connection to the VCC on the device PCB as only the ground seems to be exposed on the ribbon cable?

As there is no much space between the original front panel and the device PCB I’m planning to use SMD components to save as much as possible space. I was thinking - if the Arduino uses the same power source from the main device (probably 12V DC) can I avoid the optocouplers and use only a few resistors and transistors. Or is it better to use optocouplers?

I have attached a sample schematic but not sure if it is correct?

proxy.jpg

Look up "buck converter" for changing 12V down to 5V.

Buck converters include coils and a lot of components I don't really have that much space to fit. Optocouplers are SMD and are only a few milimeters. And also I don't see how buck converters would help. In theory I can provide external power source for the Arduino or even power it from the 12V power supply of the main device. Even the Pro Mini has a voltage regulator onboard and that should not be a problem.


So far so good, but so far you have only described the Arduino as a relay between your fan controller and its control panel. So what does that do that is useful? If you propose to add a remote control mechanism, then you should describe this first up - what is it?

You need to determine what supply voltage the unit actually uses before you know what regulator will be suitable. The regulator on the Pro Mini - which is in itself a good choice unless you require WiFi - is almost usable at 12 V unless you need to power other 5 V devices. Switchmode "buck" converters are tiny.

Optocouplers are available in multiple packages containing two or four couplers each (TLP281-4).

Indeed, connecting the opto-transistor between the pin and ground using INPUT_PULLUP (so you do not need the 10k) does invert the logic - which is no problem whatsoever as your code simply uses it as such. :grinning:

I would not advise using the resistor chain and analog input of reading a membrane keyboard or "tact" switches - these may accumulate moisture over time and develop resistive leakage or unreliable contact. It is safer to be able to consider a low but non-zero resistance as "closed" and a high resistance as "open" though it appears your keyboard cannot be reconfigured as a matrix which would be more practical.

Thanks, that was helpful. There is no plans to use WiFi or any power consuming components. The connection will be through I2C to a second controller (Arduino Mega) which is located approximately 2 meters from the fan. For the I2C it should not be a problem. That's why I expect that the internal voltage regulator will be fine.

About optocouplers - I know there is TLP281-4 and my plan is to use such. For 5 buttons and 8 LEDs I need 13 optocouplers so I will use 3 x TLP281-4 + 1 x TLP281. The above scheme is shortened to 1 LED and 1 button for simplicity.

The internal space is really tiny. I have about 29 * 50 mm space where I have to fit the Arduino Pro Mimi itself + 4 optocoupler ICs. That's why I dont have space for an extra buck converter.

Arduino Pro Mini has 14 digital pins (inc TX and RX) and 7 analog pins (inc A4 and A5 SCK and SDA) - 21 IO pins in total. That's why I am planing to wire 5 buttons with resistors. The case is sealed so I don't actually expect any moisture inside there.

In theory I need 8 digital pins as input for LEDs and 5 digital pins as outputs for buttons on the device side (left) + 8 pins for LEDs and 1 analog pin for the buttons on the panel side (right). Which is 22 pins in total which is obviously not suitable for a Pro Mini. :frowning:

Paul__B:
Indeed, connecting the opto-transistor between the pin and ground using INPUT_PULLUP (so you do not need the 10k) does invert the logic - which is no problem whatsoever as your code simply uses it as such. :grinning:

Does this means it is fine to connect a pin on Arduino directly to the opto-transistor and ground without any resistors? Or I just can invert the logic by replacing it with a pull down resistor instead of pull up?

Best regards,

babailiica:
Does this means it is fine to connect a pin on Arduino directly to the opto-transistor and ground without any resistors?

That is the way to do it. The connections are at a relatively high impedance - 47k - but given that the connections between the opto-transistor and Arduino are short that will not be a problem. You do not require very much current for the optocoupler LED either, just a few mA. The TLP281 is a fairly efficient device.

babailiica:
Or I just can invert the logic by replacing it with a pull down resistor instead of pull up?

Complete waste of effort. The internal pull-up is provided for your use, and the logic is handled in code - that is why you use a microcontroller.

The Pro Mini (and Nano) have eight analog pins, though A4 and A5 should indeed be reserved for I2C.

Running I2C over two metres is not recommended - lots of luck!

OK, it is starting to get more and more clear (at least for me). Thanks for the advice. I think I will be able to shorten the I2C to almost 1 meter at the best scenario.

One more question: can I wire the 8 LED inputs from the device to the Arduino like on the attached image?

I put LOW on D5 and HIGH on D6, then on D1-4 I read LED 1 - 4, then switch D5 to HIGH and D6 to LOW and on D1-4 I read LED 5 - 8. That way I use 6 pins instead of 8 to read the LEDs. Is that correct?

And yeah, BTW you're right, analog pins are 8, my wrong!

In the following days I will buy a few THO/DIP TLP281-4 and will give it a try on a breadbord. It will be a bit tricky to hookup to the 1mm pitch ribbon cable but I will give it a try :slight_smile:

And yeah, btw you're right, analog pins are 8, not 7, my wrong...

babailiica:
Does this means it is fine to connect a pin on Arduino directly to the opto-transistor and ground without any resistors? Or I just can invert the logic by replacing it with a pull down resistor instead of pull up?

AVR chips have a trick where the resistance is built-in.

You make the pin INPUT and it becomes electrically neutral (within pin-safe voltages).

You make the pin INPUT_PULLUP and it supplies weak VCC as through 20K to 50K resistance.

INPUT_PULLUP is great for buttons. You can ground it safely and it draws very little current from the available total.

Using port manipulation on the port's DDR (data direction register) you can switch between INPUT and INPUT_PULLUP very quickly, with compiler optimization keeping values in GP registers it may happen in a single cycle.

GoForSmoke:
You make the pin INPUT_PULLUP and it supplies weak VCC as through 20K to 50K resistance.

Wow, I have more than 20 years of experience in programming, but in a different area. But I am relatively new to Arduino and PIC programming. Never knew that. Thanks.

babailiica:
Wow, I have more than 20 years of experience in programming, but in a different area. But I am relatively new to Arduino and PIC programming. Never knew that. Thanks.

Did the area you coded in or perhaps your own hobbies teach you event-driven coding?
Do you rely on your tasking OS to make your tasks work?
Arduino has no OS, you have to write your own bugs. Co-operative multi-tasking needs no OS.

The AVR core common to all AVR’s (many families) has 32 8-bit GP registers and a whole lot of totally accessible control registers. They address by chip doc name in Arduino IDE, Microchip bought Atmel so get the full datasheet from the MC site.

One difference; the AVR IP points into flash, not RAM. You can’t load hex files into RAM and run them but you can load flash addresses in RAM and execute those, a bit like pointer to function.

I sometimes refer to the electricity page of Hyperphysics. It covers circuits to components to fields.
http://hyperphysics.phy-astr.gsu.edu/hbase/hframe.html

Microcontrollers are made for real world apps. It should handle asynch events.

PS: Arduino millis() returns an unsigned long msecs +/- .5 since startup. That’s good to 49.71 days.
Arduino micros() returns UL usecs granular 4, the low 2 bits always 0. It’s good to 71 mins and almost 35 secs.
How to use:
end-time - start-time = elapsed time always even across rollover with unsigned subtraction.

AVR's have internal clock source, all it takes to make one run is program, VCC, GND, bypass caps and jumper VCC to reset.

That's the minimum parts list, everything else is IO.

They have built-in flash, RAM, EEPROM, UAART(s), SPI and I2C ports, 10-bit analog, voltage comparator and internal temperature sensor. The 2560 family supports directly addressable external RAM at addresses above the internal RAM.

There are AVR's with built-in USB capable of using USB HID to act as keyboard/mouse/joystick HID controllers.

If you need faster, Arduino and compatible ARM boards can be programmed with Arduino IDE. Teensy 4.0 runs 600 MHz.

Yeah, my previous experience is definitely at a higher level and of course on bigger machines with OS which handles most of the operations transparently for the application. Anyways I have some education in the area and also have done a few things with Arduino and Raspberry... and yeah I know most of the differences.

What really bugs me is the hardware part and I don't feel confident with it. That's why I am asking about the wiring. But I am open for any suggestions...

Do you know Ohm's Law? The Voltage and Current Laws?

Hyperphysics covers those on one page. HyperPhysics

If I jumper a pin to ground and make the pin OUTPUT HIGH then the pin will go smoke.
If I put a resistor in there, what would be a safe value?

current = voltage / resistance
I want to limit current to 25mA or less so I set current = .025A.

resistor = 5V / .025A = 200 or next bigger standard, 220 Ohm.
5V Arduino OUTPUT pins are ground-safe through 220 Ohms but that sucks a lot of juice into heat.

PS -- get that datasheet!

Yeah, I know Ohms law. My physics teacher name was Yuri and I remembered it as U=R*I :slight_smile:

Electronic is kinda my hobby for many years - since high school... (I'm 39 now) and I have some hobbyist knowledge but never got an education in this area so - you know little gaps in the basic knowledge can be a huge problem when you start doing something real in a professional manner.

To be honest programming also was my hobby in the childhood but it went a long educational way in university and then in academy (I am an ungraduated yet PhD in CS)... but lets not vanish the main topic with side talks :slight_smile:

Thanks for the hints and best regards.

babailiica:
One more question: can I wire the 8 LED inputs from the device to the Arduino like on the attached image?

I think that will work as multiplexing. I am just not sure whether phototransistors will exhibit significant gain/ leakage when you swap emitter and collector.

GoForSmoke:
Using port manipulation on the port's DDR (data direction register) you can switch between INPUT and INPUT_PULLUP very quickly

No you can not. The DDR switches between INPUT and OUTPUT. It is the Output register that switches between INPUT and INPUT_PULLUP.

Paul__B:
No you can not. The DDR switches between INPUT and OUTPUT. It is the Output register that switches between INPUT and INPUT_PULLUP.

Sorry, PORT register control HIGH/LOW and write a 1 to a PIN register to flip the matching PORT register bit.

babailiica:
Yeah, I know Ohms law. My physics teacher name was Yuri and I remembered it as U=R*I :slight_smile:

Electronic is kinda my hobby for many years - since high school... (I'm 39 now) and I have some hobbyist knowledge but never got an education in this area so - you know little gaps in the basic knowledge can be a huge problem when you start doing something real in a professional manner.

To be honest programming also was my hobby in the childhood but it went a long educational way in university and then in academy (I am an ungraduated yet PhD in CS)... but lets not vanish the main topic with side talks :slight_smile:

Thanks for the hints and best regards.

Modules go a long way to covering gaps at reasonable prices. You may still want to search on different ways to voltage-level besides using voltage-dividers, a diode and pullup can level without current drain. A 74HC4050 has 6 channels of 5V - 3V leveling for less than 50 cents all nice and clean.

The AddOhms channel on Youtube belongs to a EE member here. He has a nice series of tutorials. If it matters to the subject, it's in the lesson. At the very least you'll be able to ask better questions.

The Arduino Playground has tons of good stuff, including the user's code library.
https://playground.arduino.cc/

That is where I learned to make DIY capacitive touch buttons for 1 pin each.