Manage 4 relays with WIFI and buttons.

Hi, I am new to programming. Would you help me combine these two programs? After pairing, the controller does not want to connect to the phone and I do not know what to do. Thanks!

And here are the programs:

Program 1-BUTTON

const int pushButton ={2,3,4,5};// define push button inputs
const int relayPin={11,10,9,8};// output pins where 4 relays will be connected
String relayNames ={“CH1”, “CH2”,“CH3”,“CH4”};// Just put name for 4 relays
int pushed ={0,0,0,0};// status of each buttons
int relayStatus ={HIGH,HIGH,HIGH,HIGH};// initial status of relay

void setup() {

Serial.begin(9600);// initialize serial monitor
for(int i=0; i<4; i++)
{
pinMode(pushButton*, INPUT_PULLUP);*
_ pinMode(relayPin*, OUTPUT); _
_ digitalWrite(relayPin, HIGH);// initial relay status to be OFF*
* }
}
void loop() {
for(int i=0; i<4; i++)
{
int val = digitalRead(pushButton); *

if(val == HIGH && relayStatus == LOW){_

pushed = 1-pushed*;*
* delay(100);*
* }// if *
_ relayStatus = val;
if(pushed == HIGH){
Serial.print(relayNames*);
Serial.println(" ON");
digitalWrite(relayPin, LOW);*_

* }else{*
_ Serial.print(relayNames*);
Serial.println(" OFF");
digitalWrite(relayPin, HIGH);*_

* }// else *

* }// for*
* Serial.println("==");*
* delay(100);*
}// loop end

Program 2 -WIFI
*// RemoteXY select connection mode and include library *
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
*// RemoteXY connection settings *
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID “SmartHomeLight”
#define REMOTEXY_WIFI_PASSWORD “23456789”
#define REMOTEXY_SERVER_PORT 6377
*// RemoteXY configurate *
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
* { 255,4,0,0,0,87,0,8,16,2,*
* 2,1,9,10,22,11,4,29,22,11,*
* 93,26,36,135,79,70,70,0,79,78,*
* 0,2,1,9,41,22,11,4,53,22,*
* 11,93,26,36,135,79,70,70,0,79,*
* 78,0,2,1,65,10,22,12,38,29,*
* 22,11,93,26,36,136,79,70,70,0,*
* 79,78,0,2,1,64,42,22,11,38,*
* 53,22,11,93,26,36,136,79,70,70,*
* 0,79,78,0 };*

*// this structure defines all the variables of your control interface *
struct {
* // input variable*
* uint8_t switch_1; // =1 if switch ON and =0 if OFF*
* uint8_t switch_2; // =1 if switch ON and =0 if OFF*
* uint8_t switch_3; // =1 if switch ON and =0 if OFF*
* uint8_t switch_4; // =1 if switch ON and =0 if OFF*
* // other variable*
* uint8_t connect_flag; // =1 if wire connected, else =0*
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_SWITCH_1 2
#define PIN_SWITCH_2 3
#define PIN_SWITCH_3 4
#define PIN_SWITCH_4 5
*void setup() *
{
* RemoteXY_Init (); *

* pinMode (PIN_SWITCH_1, OUTPUT);
pinMode (PIN_SWITCH_2, OUTPUT);
pinMode (PIN_SWITCH_3, OUTPUT);
pinMode (PIN_SWITCH_4, OUTPUT);*

* // TODO you setup code*

}
*void loop() *
*{ *
* RemoteXY_Handler ();*

* digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?LOW:HIGH);
digitalWrite(PIN_SWITCH_3, (RemoteXY.switch_3==0)?LOW:HIGH);
digitalWrite(PIN_SWITCH_4, (RemoteXY.switch_4==0)?LOW:HIGH);*

* // TODO you loop code*
* // use the RemoteXY structure for data transfer*
}
Program 3 -Did not work!Where am I wrong?
const int pushButton[] ={2,3,4,5};// define push button inputs
const int relayPin[]={11,10,9,8};// output pins where 4 relays will be connected
String relayNames[] ={“CH1”, “CH2”,“CH3”,“CH4”};// Just put name for 4 relays
int pushed[] ={0,0,0,0};// status of each buttons
int relayStatus[] ={HIGH,HIGH,HIGH,HIGH};// initial status of relay
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
*// RemoteXY connection settings *
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID “SmartHomeLight”
#define REMOTEXY_WIFI_PASSWORD “23456789”
#define REMOTEXY_SERVER_PORT 6377
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
* { 255,4,0,0,0,87,0,8,16,2,*
* 2,1,9,10,22,11,4,29,22,11,*
* 93,26,36,135,79,70,70,0,79,78,*
* 0,2,1,9,41,22,11,4,53,22,*
* 11,93,26,36,135,79,70,70,0,79,*
* 78,0,2,1,65,10,22,12,38,29,*
* 22,11,93,26,36,136,79,70,70,0,*
* 79,78,0,2,1,64,42,22,11,38,*
* 53,22,11,93,26,36,136,79,70,70,*
* 0,79,78,0 };*

*// this structure defines all the variables of your control interface *
struct {
* // input variable*
* uint8_t switch_1; // =1 if switch ON and =0 if OFF*
* uint8_t switch_2; // =1 if switch ON and =0 if OFF*
* uint8_t switch_3; // =1 if switch ON and =0 if OFF*
* uint8_t switch_4; // =1 if switch ON and =0 if OFF*
* // other variable*
* uint8_t connect_flag; // =1 if wire connected, else =0*
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_SWITCH_1 2
#define PIN_SWITCH_2 3
#define PIN_SWITCH_3 4
#define PIN_SWITCH_4 5
void setup() {
* // Robojax.com 4-Relay-4-Push button 20181211*
* Serial.begin(9600);// initialize serial monitor*
* for(int i=0; i<4; i++)*
* {*
pinMode(pushButton*, INPUT_PULLUP);
_ pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);// initial relay status to be OFF*

* }
{_

RemoteXY_Init (); *

* pinMode (PIN_SWITCH_1, OUTPUT);
pinMode (PIN_SWITCH_2, OUTPUT);
pinMode (PIN_SWITCH_3, OUTPUT);
pinMode (PIN_SWITCH_4, OUTPUT);*

* // TODO you setup code*

}
}
void loop() {
// Robojax.com 4-Relay-4-Push button 20181211
* for(int i=0; i<4; i++)*
* {*
_ int val = digitalRead(pushButton*); *
if(val == HIGH && relayStatus == LOW){_

pushed = 1-pushed*;*
* delay(100);*
* }// if *
_ relayStatus = val;
if(pushed == HIGH){
Serial.print(relayNames*);
Serial.println(" ON");
digitalWrite(relayPin, LOW);*_

* }else{*
_ Serial.print(relayNames*);
Serial.println(" OFF");
digitalWrite(relayPin, HIGH);*_

* }// else *

* }*
* {// for*
* Serial.println("==");*
* delay(100);}*
*{ *
* RemoteXY_Handler ();*

* digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?LOW:HIGH);
digitalWrite(PIN_SWITCH_3, (RemoteXY.switch_3==0)?LOW:HIGH);
digitalWrite(PIN_SWITCH_4, (RemoteXY.switch_4==0)?LOW:HIGH);*

* // TODO you loop code*
* // use the RemoteXY structure for data transfer*
}
}

And now with code tags, please.

AWOL:
And now with code tags, please.

I do not understand you. What code tags?

Drago88:
I do not understand you. What code tags?

There are stickies at the top of the forum that you were supposed to read BEFORE you blundered in here. They answer your question.

const int pushButton[] ={2,3,4,5};// define push button inputs
const int relayPin[]={11,10,9,8};// output pins where 4 relays will be connected
String relayNames[] ={"CH1", "CH2","CH3","CH4"};// Just put name for 4 relays
int pushed[] ={0,0,0,0};// status of each buttons
int relayStatus[] ={HIGH,HIGH,HIGH,HIGH};// initial status of relay

Does your Arduino really have enough pins that you need to use int? Does your Arduino really have pins with negative numbers?

Since you don’t intend to change the name of the relays, the name array should be const, too. There is really no excuse for wrapping the strings in instances of the String class.

You posted two pieces of code, incorrectly, but not your attempt to combine them, or even a vague description of what the combined code is supped to do.