Assistance with Code to Control 4 Relays with Wireless Remote

Hello!

I am attempting to control 4 relays on a 8 relay board with a latching wireless 4 channel remote board. I used a sample code which is allowing the relays to currently cycle in sequence utilizing Digital pins 5,4,3, and 2 on the Arduino, and I was going to use Analog pins 5,4,3, and 2 to input the on/off trigger from the wireless control board.

Here is the sketch I am currently experimenting with but something is missing (errors); Laugh if you must :slight_smile:

/-----( Import needed libraries )-----/
/-----( Declare Constants )-----/
#define RELAY_ON 0
#define RELAY_OFF 1
/-----( Declare objects )-----/
/-----( Declare Variables )-----/
#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 3
#define Relay_3 4
#define Relay_4 5
#define Switch_1 A2 //Arduino Analog I/O pin number
#define Switch_2 A3
#define Switch_3 A4
#define Switch_4 A5
void setup() /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Switch_1, 0);
digitalWrite(Relay_2, RELAY_ON);
digitalWrite(Switch_2, 0);
digitalWrite(Relay_3, RELAY_OFF);
digitalWrite(Switch_3, 0);
digitalWrite(Relay_4, RELAY_OFF);
digitalWrite(Switch_4, 0);

//---( THEN set pins as outputs )----
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_4, OUTPUT);
pinMode(Switch_1, INPUT);
pinMode(Switch_2, INPUT);
pinMode(Switch_3, INPUT);
pinMode(Switch_4, INPUT);
delay(1000); //Check that all relays are inactive at Reset

}//--(end setup )---

//( THE END )**

As you can see, I tried to modify it to work with the trigger instead of an automatic loop. Again, I am using a latching decoder chip but eventually I will be using a toggle one.
Your assistance is greatly appreciated!

I'm pretty much a noob my self. However I strongly suggest trying to get one point to work then expand from there. Have you verified the RF link to be good ?

Yes, the RF link is good. I did a simple in from wireless board to digital pin 2 to trigger the pin 13 LED test.

Thing is, I can build just about anything, it's coding that I have yet to grasp.

but something is missing

loop() ? arrays?
Code tags.

AWOL:
loop() ? arrays?
Code tags.

Yes indeed. I deleted the loop in the original code, why I don't know. Arrays and code tags are out of my league.

I know I could take some time to actually get the sketch right myself, buy looking at definitions and such, but I have about 7 different projects I am trying to build at this time and I was hoping someone could look at this and give me a cut and paste code. Then, when I have the time, I could study the code, or reverse engineer it, if you will, and that would help me to understand it myself so I could then help others.

code tags are out of my league.

But not quote tags, it seems.

AWOL:
But not quote tags, it seems.

That may be the case.

I actually took a code that was already written on arduino-info site set up to turn the 8 relays on and off (which is currently uploaded and working), and tried to modify it to be controlled by my wireless remote... no success which is the reason for this post.

I appreciate your observations, and someday I hope to be as knowledgeable as you are when it comes to code, but please understand at this time I am looking for a simple copy and paste. If I am out of line as a newbie to this forum I apologize.

Ok here is the "base" code I started with. I need help modifying this code to allow my 4 channel latching wireless device to control the on/off of each relay. I will be inputting the pins from the wireless board onto the Arduino on A2, A3, A4, and A5 to correspond with each relay, unless someone suggests using digital pins instead;

/-----( Declare Constants )-----/
#define RELAY_ON 0
#define RELAY_OFF 1
/-----( Declare objects )-----/
/-----( Declare Variables )-----/
#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 3
#define Relay_3 4
#define Relay_4 5

void setup() /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
digitalWrite(Relay_4, RELAY_OFF);

//---( THEN set pins as outputs )----
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_4, OUTPUT);
delay(4000); //Check that all relays are inactive at Reset

}//--(end setup )---

void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//---( Turn all 4 relays ON in sequence)---
digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second
digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second
digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second
digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
delay(4000); // wait see all relays ON

//---( Turn all 4 relays OFF in sequence)---
digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
delay(1000); // wait for a second
digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
delay(1000); // wait for a second
digitalWrite(Relay_3, RELAY_OFF);// set the Relay OFF
delay(1000); // wait for a second
digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF
delay(4000); // wait see all relays OFF

}//--(end main loop )---

//( THE END )**

It's more usual to set the pin mode then write to the pin, otherwise you're just disabling pullups on input pins

Code tags would be good too.

What's the four channel latching wireless thingy?

AIRA3:
I was hoping someone could look at this and give me a cut and paste code.

Aaaand here we go. If you just want code and don't want help.

http://forum.arduino.cc/index.php?board=26.0

Also, the code tags people keep telling you about and you keep ignoring

is the forum feature that you use to post your code in like this so it sucks less to look at

AWOL:
It's more usual to set the pin mode then write to the pin, otherwise you're just disabling pullups on input pins

Code tags would be good too.

What's the four channel latching wireless thingy?

I am using a Gikfun IC2262/2272 4 Channel Remote Control Kit. It is available in toggle (each of four buttons on the remote work independently to engage on/off, latching (select one button for on, have to touch another button for off) and momentary. I will ultimately be going with toggle, but right now I have latching. This has no effect over the code.

INTP:
Aaaand here we go. If you just want code and don't want help.

Jobs and Paid Consultancy - Arduino Forum

Also, the code tags people keep telling you about and you keep ignoring

is the forum feature that you use to post your code in like this so it sucks less to look at

As both of you mentioned, I will figure out how to use code tags and I do apologize. I thought it had something to do with the way my code was written not the preferred format for this forum.

I will repost on the suggested board. Thank you.