In my living room there is a ceiling fan that I'd like to control via Arduino. It has a infrared remote control and I thought the easiest way to control the fan is to simulate pushing a button on the remote control. The fan has 3 rotation levels and a light. I will only need rotation level 1 and turning it off, controlling the light also.
First, I made a setup controlling an LED via a transistor (2N3904).
int transistor = 3;
int button = 2;
int buttonState = 0;
int powerOn = 0;
int buttonPressing = 0;
void setup() {
pinMode(transistor, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop() {
buttonState = digitalRead(button);
if (buttonState == LOW) {
if (buttonPressing == 0) {
if (powerOn == 0) {
digitalWrite(transistor, HIGH);
powerOn = 1;
} else if (powerOn == 1) {
digitalWrite(transistor, LOW);
powerOn = 0;
}
}
buttonPressing = 1;
} else {
buttonPressing = 0;
}
}
The setup works well and now I hoped I could do the simulation on the remote control the same way.
As far as I understand, the only thing to do for the simulation is to close the circuit (where the push button on the remote control is) and the remote control would do the rest.
So when I connect the emitter to the ground (orange) and the base to the pin on the shift register (green), it should close the circuit (red), simulate pushing the button. It tried it for the button in the left bottom corner which will rotate the fan on level 1. Unfortunately it's rotating on level 3 that way. So... experiment failed.
What am I doing wrong? Am I thinking too short-sighted? Can I achieve it with the transistor at all? Thanks for your answers.
Why don't you get yourself an IR receiver module and IR transmitter module, capture the codes used by the remote and then reproduce them with the Arduino?
PaulRB:
Why don't you get yourself an IR receiver module and IR transmitter module, capture the codes used by the remote and then reproduce them with the Arduino?
Because I hoped that it's way easier to simulate pushing a button on the remote control that already sends the needed data to the fan.
The simplest and guaranteed to work, involving no direct electrical connections (between the Arduino and the remote) nor the challenge they might represent is
to use a relay driven by the Arduino and the relay's NO contacts bridging the switch.
Use a relay. Probably makes sense for one or a few buttons, one relay per. You don need to know anything about anything to get that working. Appropriate small voltage relays are cheap. Since it's momentary, the plainest of them would do. Google us your friend.
Drive the relay with that transistor, use a diode too like you will or have seen.
I'd consider cloning the remote control the most discreet and fairly easy approach. No clunky wires hanging around, empty batteries, no soldering (or glueing for that matter). Just put the remote in the drawer and an Arduino, a compatible clone or an ESP8266 with a IR transmitter attached to it in line of sight of your ceiling fan.
You should be able to record and replay the signals of your remote with the help of the library used in the following tutorials in no time.
Personally, I would (will) give this one a try, since it would potentially allow you to control "any" IR capable device via WiFi (Smartphone, Tablet, PC, ... you name it).
If you connect the grounds, maybe. Depends how the buttons are wired. The chip is a microcontroller. Similar to the one in the Arduino, but can probably only be programmed once, which was done at the factory.
I think trying my IR receiver idea would be simpler than your remote hack idea. It might not work, the IR codes might not be supported by the IR Arduino library. But if it does work, it will be a much simpler and neater circuit, and you won't risk damaging your remote.
This question comes up every few months or so.
The answer: use an opto coupler if you must hack the remote.
Opto transistor across the remote contacts (polarity matters, so measure first).
Opto LED (with 1k current limiting resistor) directly driven from an Arduino pin/ground.
Cloning the remote control, and transmitting that directly from the Uno is indeed a much neater solution.
Leo..