Boa Noite pessoal, Good evening everyone,
Encaminho aqui os codigos do programa que deu certo aqui : eu comprei a placa com 24 reles (esp12f _relay_x24_VI_2)
I forward here the codes of the program that worked here: I bought the board with 24 relays (esp12f _relay_x24_VI_2)
o codigo :
// Pinos conectados ao 74HC595
int latchPin = 12; // Latch pin do 74HC595
int clockPin = 13; // Clock pin do 74HC595
int dataPin = 14; // Data pin do 74HC595
int oePin = 5; // Não utilizado no código, mas configurado como OUTPUT
void setup() {
// Configura todos os pinos como OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(oePin, OUTPUT);
// Inicializa a comunicação serial
Serial.begin(115200);
// Inicia todos os relés desligados
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0x00); // Primeiro registrador (8 relés)
shiftOut(dataPin, clockPin, MSBFIRST, 0x00); // Segundo registrador (8 relés)
shiftOut(dataPin, clockPin, MSBFIRST, 0x00); // Terceiro registrador (8 relés)
digitalWrite(latchPin, HIGH);
}
void loop() {
for (int i = 0; i < 24; i++) {
// Liga o relé correspondente
Serial.print("Turning on relay: ");
Serial.println(i + 1);
activateRelay(i);
delay(500); // Mantém o relé ligado por 500 ms
// Desliga todos os relés
Serial.println("Turning off all relays");
deactivateAllRelays();
delay(500); // Aguardando antes de passar para o próximo relé
}
}
// Função para ativar um relé específico
void activateRelay(int relay) {
byte relayState1 = 0x00;
byte relayState2 = 0x00;
byte relayState3 = 0x00;
if (relay < 8) {
relayState1 = (1 << relay); // Ativa o bit correspondente no primeiro registrador
} else if (relay < 16) {
relayState2 = (1 << (relay - 8)); // Ativa o bit correspondente no segundo registrador
} else {
relayState3 = (1 << (relay - 16)); // Ativa o bit correspondente no terceiro registrador
}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, relayState3);
shiftOut(dataPin, clockPin, MSBFIRST, relayState2);
shiftOut(dataPin, clockPin, MSBFIRST, relayState1);
digitalWrite(latchPin, HIGH);
}
// Função para desativar todos os relés
void deactivateAllRelays() {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0x00);
shiftOut(dataPin, clockPin, MSBFIRST, 0x00);
shiftOut(dataPin, clockPin, MSBFIRST, 0x00);
digitalWrite(latchPin, HIGH);
}
consegui tambem o codigo com 16 reles : I also got the code with 16 relays:
// LCTech 16ch Relay board with 2x74HC595 shift registers - replicates close to out of box relay testing function
int latchPin = 12; // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 13; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 14; // Data pin of 74HC595 is connected to Digital pin 4
int oePin = 5; // oePin - not using this
void setup()
{
// Set all the pins of 74HC595 as OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(oePin, OUTPUT);
// Setup serial comms
Serial.begin(115200);
}
void loop()
{
Serial.println("Relay #16 = 0b0000");
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 0b0000);
digitalWrite(latchPin, HIGH);
delay(3000);
Serial.println("Relay #8 = 0b0001");
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 0b0001);
digitalWrite(latchPin, HIGH);
delay(3000);
}
Utilizando estes modelos junto com chatgbt vcs podem desenvolver qualquer programa…
Using these models together with chatgbt you can develop any program…