Buen día con todos desde ya gracias por el apoyo y los conocimientos que me puedan brindar.
El caso es el siguiente estoy realizando un proyecto que tiene los siguientes componentes.
- 15 relay arduino de canal
- 1 Arduino Mega
- 15 sensor touch arduino ttp223b
El proyecto a realizar es que pretendo prender luces con esos 15 relay pero cuando realizo las pruebas sales de forma correcta hasta el relay numero 5 o 6 después empiezan a tener inconvenientes como no prender o cuando intento prender se apaga otro luz que no debería ser. El Arduino mega esta siendo alimentado de forma independiente con un cargado de router y los relay con una fuente de poder de pc con salida de 5 voltios.
Me parece que es la alimentación como poder confirmar si es eso o como debe de mejorar y estoy realizando algo de forma incorrecta, asimismo al proyecto quiero agregar el arduino ethernet para poder apagar las luces de forma remota....
Le dejo mi código también.
int touchPin = 2; // touch sensor
int relayPin = 3; // relay module
int touchPin01 = 4; // touch sensor
int relayPin01 = 5; // relay module
int touchPin02 = 6; // touch sensor
int relayPin02 = 7; // relay module
int touchPin03 = 8; // touch sensor
int relayPin03 = 9; // relay module
int touchPin04 = 10; // touch sensor
int relayPin04 = 11; // relay module
int touchPin05 = 12; // touch sensor
int relayPin05 = 13; // relay module
int touchPin06 = 22; // touch sensor
int relayPin06 = 23; // relay module
int touchPin07 = 24; // touch sensor
int relayPin07 = 25; // relay module
int touchPin08 = 26; // touch sensor
int relayPin08 = 27; // relay module
int touchPin09 = 28; // touch sensor
int relayPin09 = 29; // relay module
int touchPin10 = 30; // touch sensor
int relayPin10 = 31; // relay module
int touchPin11 = 32; // touch sensor
int relayPin11 = 33; // relay module
int touchPin12 = 34; // touch sensor
int relayPin12 = 35; // relay module
int touchPin13 = 36; // touch sensor
int relayPin13 = 37; // relay module
int touchPin14 = 38; // touch sensor
int relayPin14 = 39; // relay module
int touchPin15 = 39; // touch sensor
int relayPin15 = 40; // relay module
int touchPin16 = 41; // touch sensor
int relayPin16 = 42; // relay module
int touchPin17 = 43; // touch sensor
int relayPin17 = 44; // relay module
int touchPin18 = 45; // touch sensor
int relayPin18 = 46; // relay module
int touchPin19 = 47; // touch sensor
int relayPin19 = 48; // relay module
int touchPin20 = 49; // touch sensor
int relayPin20 = 50; // relay module
int touchPin21 = 51; // touch sensor
int relayPin21 = 52; // relay module
int val = 0;
int lightON = 0;
int touched = 0;
int val01 = 0;
int lightON01 = 0;
int touched01 = 0;
int val02 = 0;
int lightON02 = 0;
int touched02 = 0;
int val03 = 0;
int lightON03 = 0;
int touched03 = 0;
int val04 = 0;
int lightON04 = 0;
int touched04 = 0;
int val05 = 0;
int lightON05 = 0;
int touched05 = 0;
int val06 = 0;
int lightON06 = 0;
int touched06 = 0;
int val07 = 0;
int lightON07 = 0;
int touched07 = 0;
int val08 = 0;
int lightON08 = 0;
int touched08 = 0;
int val09 = 0;
int lightON09 = 0;
int touched09 = 0;
int val10 = 0;
int lightON10 = 0;
int touched10 = 0;
int val11 = 0;
int lightON11 = 0;
int touched11 = 0;
int val12 = 0;
int lightON12 = 0;
int touched12 = 0;
int val13 = 0;
int lightON13 = 0;
int touched13 = 0;
int val14 = 0;
int lightON14 = 0;
int touched14 = 0;
int val15 = 0;
int lightON15 = 0;
int touched15 = 0;
int val16 = 0;
int lightON16 = 0;
int touched16 = 0;
int val17 = 0;
int lightON17 = 0;
int touched17 = 0;
int val18 = 0;
int lightON18 = 0;
int touched18 = 0;
int val19 = 0;
int lightON19 = 0;
int touched19 = 0;
int val20 = 0;
int lightON20 = 0;
int touched20 = 0;
int val21 = 0;
int lightON21 = 0;
int touched21 = 0;
void setup() {
Serial.begin(9600); //sensor buart rate
pinMode(touchPin, INPUT); // touch sensor
pinMode(relayPin, OUTPUT); // Relay Module
pinMode(touchPin01, INPUT); // touch sensor
pinMode(relayPin01, OUTPUT); // Relay Module
pinMode(touchPin02, INPUT); // touch sensor
pinMode(relayPin02, OUTPUT); // Relay Module
pinMode(touchPin03, INPUT); // touch sensor
pinMode(relayPin03, OUTPUT); // Relay Module
pinMode(touchPin04, INPUT); // touch sensor
pinMode(relayPin04, OUTPUT); // Relay Module
pinMode(touchPin05, INPUT); // touch sensor
pinMode(relayPin05, OUTPUT); // Relay Module
pinMode(touchPin06, INPUT); // touch sensor
pinMode(relayPin06, OUTPUT); // Relay Module
pinMode(touchPin07, INPUT); // touch sensor
pinMode(relayPin07, OUTPUT); // Relay Module
pinMode(touchPin08, INPUT); // touch sensor
pinMode(relayPin08, OUTPUT); // Relay Module
pinMode(touchPin09, INPUT); // touch sensor
pinMode(relayPin09, OUTPUT); // Relay Module
pinMode(touchPin10, INPUT); // touch sensor
pinMode(relayPin10, OUTPUT); // Relay Module
pinMode(touchPin11, INPUT); // touch sensor
pinMode(relayPin11, OUTPUT); // Relay Module
pinMode(touchPin12, INPUT); // touch sensor
pinMode(relayPin12, OUTPUT); // Relay Module
pinMode(touchPin13, INPUT); // touch sensor
pinMode(relayPin13, OUTPUT); // Relay Module
pinMode(touchPin14, INPUT); // touch sensor
pinMode(relayPin14, OUTPUT); // Relay Module
pinMode(touchPin15, INPUT); // touch sensor
pinMode(relayPin15, OUTPUT); // Relay Module
pinMode(touchPin16, INPUT); // touch sensor
pinMode(relayPin16, OUTPUT); // Relay Module
pinMode(touchPin17, INPUT); // touch sensor
pinMode(relayPin17, OUTPUT); // Relay Module
pinMode(touchPin18, INPUT); // touch sensor
pinMode(relayPin18, OUTPUT); // Relay Module
pinMode(touchPin19, INPUT); // touch sensor
pinMode(relayPin19, OUTPUT); // Relay Module
pinMode(touchPin20, INPUT); // touch sensor
pinMode(relayPin20, OUTPUT); // Relay Module
pinMode(touchPin21, INPUT); // touch sensor
pinMode(relayPin21, OUTPUT); // Relay Module
digitalWrite(relayPin, HIGH); // Normally Relay
digitalWrite(relayPin01, HIGH); // Normally Relay
digitalWrite(relayPin02, HIGH); // Normally Relay
digitalWrite(relayPin03, HIGH); // Normally Relay
digitalWrite(relayPin04, HIGH); // Normally Relay
digitalWrite(relayPin05, HIGH); // Normally Relay
digitalWrite(relayPin06, HIGH); // Normally Relay
digitalWrite(relayPin07, HIGH); // Normally Relay
digitalWrite(relayPin08, HIGH); // Normally Relay
digitalWrite(relayPin09, HIGH); // Normally Relay
digitalWrite(relayPin10, HIGH); // Normally Relay
digitalWrite(relayPin11, HIGH); // Normally Relay
digitalWrite(relayPin12, HIGH); // Normally Relay
digitalWrite(relayPin13, HIGH); // Normally Relay
digitalWrite(relayPin14, HIGH); // Normally Relay
digitalWrite(relayPin15, HIGH); // Normally Relay
digitalWrite(relayPin16, HIGH); // Normally Relay
digitalWrite(relayPin17, HIGH); // Normally Relay
digitalWrite(relayPin18, HIGH); // Normally Relay
digitalWrite(relayPin19, HIGH); // Normally Relay
digitalWrite(relayPin20, HIGH); // Normally Relay
digitalWrite(relayPin21, HIGH); // Normally Relay
}
void loop() {
val = digitalRead(touchPin);
if(val == HIGH && lightON == LOW){
touched = 1-touched;
delay(1);
}
lightON = val;
if(touched == HIGH)
{
// Serial.println("Light ON");
digitalWrite(relayPin, LOW); // Relay ON
}else
{
// Serial.println("Light OFF");
digitalWrite(relayPin, HIGH); // Relay OFF
}
val01 = digitalRead(touchPin01);
if(val01 == HIGH && lightON01 == LOW){
touched01 = 1-touched01;
delay(1);
}
lightON01 = val01;
if(touched01 == HIGH)
{
digitalWrite(relayPin01, LOW); // Relay ON
}else
{
digitalWrite(relayPin01, HIGH); // Relay OFF
}
val02 = digitalRead(touchPin02);
if(val02 == HIGH && lightON02 == LOW){
touched02 = 1-touched02;
delay(1);
}
lightON02 = val02;
if(touched02 == HIGH)
{
digitalWrite(relayPin02, LOW); // Relay ON
}else
{
digitalWrite(relayPin02, HIGH); // Relay OFF
}
val03 = digitalRead(touchPin03);
if(val03 == HIGH && lightON03 == LOW){
touched03 = 1-touched03;
delay(1);
}
lightON03 = val03;
if(touched03 == HIGH)
{
digitalWrite(relayPin03, LOW); // Relay ON
}else
{
digitalWrite(relayPin03, HIGH); // Relay OFF
}
val04 = digitalRead(touchPin04);
if(val04 == HIGH && lightON04 == LOW){
touched04 = 1-touched04;
delay(1);
}
lightON04 = val04;
if(touched04 == HIGH)
{
digitalWrite(relayPin04, LOW); // Relay ON
}else
{
digitalWrite(relayPin04, HIGH); // Relay OFF
}
val05 = digitalRead(touchPin05);
if(val05 == HIGH && lightON05 == LOW){
touched05 = 1-touched05;
delay(1);
}
lightON05 = val05;
if(touched05 == HIGH)
{
digitalWrite(relayPin05, LOW); // Relay ON
}else
{
digitalWrite(relayPin05, HIGH); // Relay OFF
}
val06 = digitalRead(touchPin06);
if(val06 == HIGH && lightON06 == LOW){
touched06 = 1-touched06;
delay(1);
}
lightON06 = val06;
if(touched06 == HIGH)
{
digitalWrite(relayPin06, LOW); // Relay ON
}else
{
digitalWrite(relayPin06, HIGH); // Relay OFF
}
val07 = digitalRead(touchPin07);
if(val07 == HIGH && lightON07 == LOW){
touched07 = 1-touched07;
delay(1);
}
lightON07 = val07;
if(touched07 == HIGH)
{
digitalWrite(relayPin07, LOW); // Relay ON
}else
{
digitalWrite(relayPin07, HIGH); // Relay OFF
}
val08 = digitalRead(touchPin08);
if(val08 == HIGH && lightON08 == LOW){
touched08 = 1-touched08;
delay(1);
}
lightON08 = val08;
if(touched08 == HIGH)
{
digitalWrite(relayPin08, LOW); // Relay ON
}else
{
digitalWrite(relayPin08, HIGH); // Relay OFF
}
val09 = digitalRead(touchPin09);
if(val09 == HIGH && lightON09 == LOW){
touched09 = 1-touched09;
delay(1);
}
lightON09 = val09;
if(touched09 == HIGH)
{
digitalWrite(relayPin09, LOW); // Relay ON
}else
{
digitalWrite(relayPin09, HIGH); // Relay OFF
}
val10 = digitalRead(touchPin10);
if(val10 == HIGH && lightON10 == LOW){
touched10 = 1-touched10;
delay(1);
}
lightON10 = val10;
if(touched10 == HIGH)
{
digitalWrite(relayPin10, LOW); // Relay ON
}else
{
digitalWrite(relayPin10, HIGH); // Relay OFF
}
val11 = digitalRead(touchPin11);
if(val11 == HIGH && lightON11 == LOW){
touched11 = 1-touched11;
delay(1);
}
lightON11 = val11;
if(touched11 == HIGH)
{
digitalWrite(relayPin11, LOW); // Relay ON
}else
{
digitalWrite(relayPin11, HIGH); // Relay OFF
}
val12 = digitalRead(touchPin12);
if(val12 == HIGH && lightON12 == LOW){
touched12 = 1-touched12;
delay(1);
}
lightON12 = val12;
if(touched12 == HIGH)
{
digitalWrite(relayPin12, LOW); // Relay ON
}else
{
digitalWrite(relayPin12, HIGH); // Relay OFF
}
val13 = digitalRead(touchPin13);
if(val13 == HIGH && lightON13 == LOW){
touched13 = 1-touched13;
delay(1);
}
lightON13 = val13;
if(touched13 == HIGH)
{
digitalWrite(relayPin13, LOW); // Relay ON
}else
{
digitalWrite(relayPin13, HIGH); // Relay OFF
}
val14 = digitalRead(touchPin14);
if(val14 == HIGH && lightON14 == LOW){
touched14 = 1-touched14;
delay(1);
}
lightON14 = val14;
if(touched14 == HIGH)
{
digitalWrite(relayPin14, LOW); // Relay ON
}else
{
digitalWrite(relayPin14, HIGH); // Relay OFF
}
val15 = digitalRead(touchPin15);
if(val15 == HIGH && lightON15 == LOW){
touched15 = 1-touched15;
delay(1);
}
lightON15 = val15;
if(touched15 == HIGH)
{
digitalWrite(relayPin15, LOW); // Relay ON
}else
{
digitalWrite(relayPin15, HIGH); // Relay OFF
}
val16 = digitalRead(touchPin16);
if(val16 == HIGH && lightON16 == LOW){
touched16 = 1-touched16;
delay(1);
}
lightON16 = val16;
if(touched16 == HIGH)
{
digitalWrite(relayPin16, LOW); // Relay ON
}else
{
digitalWrite(relayPin16, HIGH); // Relay OFF
}
val17 = digitalRead(touchPin17);
if(val17 == HIGH && lightON17 == LOW){
touched17 = 1-touched17;
delay(1);
}
lightON17 = val17;
if(touched17 == HIGH)
{
digitalWrite(relayPin17, LOW); // Relay ON
}else
{
digitalWrite(relayPin17, HIGH); // Relay OFF
}
val18 = digitalRead(touchPin18);
if(val18 == HIGH && lightON18 == LOW){
touched18 = 1-touched18;
delay(1);
}
lightON18 = val18;
if(touched18 == HIGH)
{
digitalWrite(relayPin18, LOW); // Relay ON
}else
{
digitalWrite(relayPin18, HIGH); // Relay OFF
}
val19 = digitalRead(touchPin19);
if(val19 == HIGH && lightON19 == LOW){
touched19 = 1-touched19;
delay(1);
}
lightON19 = val19;
if(touched19 == HIGH)
{
digitalWrite(relayPin19, LOW); // Relay ON
}else
{
digitalWrite(relayPin19, HIGH); // Relay OFF
}
val20 = digitalRead(touchPin20);
if(val20 == HIGH && lightON20 == LOW){
touched20 = 1-touched20;
delay(1);
}
lightON20 = val20;
if(touched20 == HIGH)
{
digitalWrite(relayPin20, LOW); // Relay ON
}else
{
digitalWrite(relayPin20, HIGH); // Relay OFF
}
val21 = digitalRead(touchPin21);
if(val21 == HIGH && lightON21 == LOW){
touched21 = 1-touched21;
delay(1);
}
lightON21 = val21;
if(touched21 == HIGH)
{
digitalWrite(relayPin21, LOW); // Relay ON
}else
{
digitalWrite(relayPin21, HIGH); // Relay OFF
}
delay(1);
}
Desde ya gracias por el apoyo.