About to buy the parts for domotic project. Asking if this scheme+code will work

Hello, as I said in the title, I’m about to buy the needed parts for a little home automation system. The expected result is to control a desk lightbulb and a general ceiling lightbulb from a TV remote. It consists in an arduino nano v3.0, two magnetic relays like this:

an IR receiver, a desk lamp, and a ceiling lamp.

I don’t want to buy the parts and later find out that nothing works or that I need to buy more parts, so I made an orientative schematic (attached to the post)

And a sketch:

/* This sketch is for controlling two relays connected to an arduino nano, with any IR remote controller */

//This part of the code is for a proper working of the IR receiver
#include <IRremote.h>
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

//We have two relays, the first controlling the desk lightbulb (relay_small_light), and the otrher controlling the ceiling bulb (relay_big_light)
int relay_small_light = 3;
int relay_big_light = 5;

void setup(){
  irrecv.enableIRIn(); //Begin reading the IR receiver data
  pinMode(relay_small_light, OUTPUT);
  pinMode(relay_big_light, OUTPUT);
}
  
void loop()
{
  if (irrecv.decode(&results)) 
  {
     irrecv.resume(); // Receive the next value
  }
  
  //This is the hearth of the program. Arduino reads what has been received and turns on or off the relays. Note that the numbers are made up, it's just an example.
  switch(results.value) 
  {
  case 0xEE1128D7: digitalWrite(relay_small_light, HIGH); break; //When button one is pressed, the small lightbulb turns on
  case 0xEE11A857: digitalWrite(relay_small_light, LOW); break; //When button two is pressed, the small lightbulb turns off
  case 0xEE11A321: digitalWrite(relay_big_light, HIGH); break; //When button three is pressed, the big lightbulb turns on
  case 0xEE13A222: digitalWrite(relay_big_light, LOW); break; //When button four is pressed, the big lightbulb turns off
  }  
}

The sketch must be ok, I used a similar one but with two leds (and an arduino mega), but I don’t know if it will work for relays in my situation.

Will everything work fine? Do I need something else? Am I missing something?

Thank you very much!

It is a very simple project. Easily doable. Be sure to buy opto isolated relay breakout boards instead of normal ones. They protect the arduino in case something goes wrong. For IR sensor I found TSOP 1738 to work best.

Thanks for the reply. I didn’t plan to buy a breakout board, the idea was buying two cheap relays like in the photo ( http://www.fasttech.com/products/0/10000012/1001100-ttl-250v10a-ac-relay-module ) and mount them on a breadboard. Is it safe? Also note that an arduino nano clone costs about 8$, so if the chances that something will go wrong are low, it’s cheaper an arduino reemplacement.

I forgot to say that I already have an IR receiver and it works very well too :slight_smile:

Looking at the photo of the relay board, it looks as if it does have a transistor driver build onboard. Good.
If you have not yet bought the two relay boards, you may want to look at a relay board that has two relays on it. Depends I guess on where you want to place the relays.

Looks doable. I don't see any problems. Let us know as it progresses, or if you have any further questions.

Jack

and mount them on a breadboard. Is it safe?

I would never run power for a mains powered lamp through a breadboard.

akpla:
Thanks for the reply. I didn't plan to buy a breakout board, the idea was buying two cheap relays like in the photo ( http://www.fasttech.com/products/0/10000012/1001100-ttl-250v10a-ac-relay-module ) and mount them on a breadboard. Is it safe? Also note that an arduino nano clone costs about 8$, so if the chances that something will go wrong are low, it's cheaper an arduino reemplacement.

I forgot to say that I already have an IR receiver and it works very well too :slight_smile:

  1. The product you're reffering to is a breakout board. Only relay would mean no PCB. But the one you're referring to has a PCB and a transistor. You can use it.
  2. You can connect the arduino and relay using female to female jumper wires. Using a breadboard may cause problems.
  3. Be sure you don't touch the bottom of the relay board with a conductor like metal or the cement wall directly.
  4. You can mount it all in a plastic box.
  5. Be careful and happy automation.

jackwp:
Looking at the photo of the relay board, it looks as if it does have a transistor driver build onboard. Good.
If you have not yet bought the two relay boards, you may want to look at a relay board that has two relays on it. Depends I guess on where you want to place the relays.

Looks doable. I don’t see any problems. Let us know as it progresses, or if you have any further questions.

Jack

I prefer having them separated, it’s more flexible. Also I’ve only found two-channel relay boards with non-independent relays.

groundfungus:

and mount them on a breadboard. Is it safe?

I would never run power for a mains powered lamp through a breadboard.

It will not run through the breadboard, the pins of the relay that are on the breadboard are isolated from the 220V.

Ufoguy:

akpla:
Thanks for the reply. I didn’t plan to buy a breakout board, the idea was buying two cheap relays like in the photo ( http://www.fasttech.com/products/0/10000012/1001100-ttl-250v10a-ac-relay-module ) and mount them on a breadboard. Is it safe? Also note that an arduino nano clone costs about 8$, so if the chances that something will go wrong are low, it’s cheaper an arduino reemplacement.

I forgot to say that I already have an IR receiver and it works very well too :slight_smile:

  1. The product you’re reffering to is a breakout board. Only relay would mean no PCB. But the one you’re referring to has a PCB and a transistor. You can use it.
  2. You can connect the arduino and relay using female to female jumper wires. Using a breadboard may cause problems.
  3. Be sure you don’t touch the bottom of the relay board with a conductor like metal or the cement wall directly.
  4. You can mount it all in a plastic box.
  5. Be careful and happy automation.

Thanks. I searched in google and haven’t found any cons of using relays on breadboards, can you explain me the problem please? Using f-to-f jumper wires will not do the job, as you can see on the schematic, I need three pins to be connected on the only 5v pin, and other three on the GND pin.

I think you have it under control. Should work fine.
There was a question about having the relay on a breadboard, but I think it was more just a misunderstanding. If you don’t have the 220 volts running around on the bread board, then it should not be a problem.
Let us know how it turns out.