Hello I have an arduino uno, a shield 4 relays for controlling a motor in 2 directions by voice command, so I first wanted to try to run the relay without voice control with LED or a 12v fan pc, nothing works, I have the 12 volt external power required, one for the fan but nothing, I'm the click of the 4 relays with this code:
// Define constants and variables
const int out1 = 5; // define Arduino pin connected to relay 1
const int out2 = 6; // define Arduino pin connected to relay 2
const int out3 = 7; // define Arduino pin connected to relay 3
const int out4 = 8; // define Arduino pin connected to relay 4
// Initialization
void setup()
{
pinMode(out1, OUTPUT); // initialize the digital pin as an output
pinMode(out2, OUTPUT); // initialize the digital pin as an output
pinMode(out3, OUTPUT); // initialize the digital pin as an output
pinMode(out4, OUTPUT); // initialize the digital pin as an output
Serial.begin(9600); // Serial Port initialization
}
// enable or disable a relay (1 to 4)
void setRelay(int relay, int value)
{
if(relay > 0 && relay < 5) digitalWrite((relay + 4), value);
}
// main loop
void loop()
{
setRelay(1, 1); // enable relay 1
Serial.print("Relay 1: Enabled ... ");
delay(1000); // wait for a second
setRelay(1, 0);
Serial.println("Disabled"); // disable relay 1
delay(1000); // wait for a second
setRelay(2, 1); // enable relay 2
Serial.print("Relay 2: Enabled ... ");
delay(1000); // wait for a second
setRelay(2, 0); // disable relay 2
Serial.println("Disabled");
delay(1000); // wait for a second
setRelay(3, 1); // enable relay 3
Serial.print("Relay 3: Enabled ... ");
delay(1000); // wait for a second
setRelay(3, 0); // disable relay 3
Serial.println("Disabled");
delay(1000); // wait for a second
setRelay(4, 1); // enable relay 4
Serial.print("Relay 4: Enabled ... ");
delay(1000); // wait for a second
setRelay(4, 0); // disable relay 4
Serial.println("Disabled");
delay(1000); // wait for a second
}
I also tried this:
void setup()
{
pinMode(5, OUTPUT);
}
void loop()
{
digitalWrite(5, HIGH); delay(1000);
digitalWrite(5, LOW); delay(1000);
But nothing, what should I do? Thank you for answering me .
Best regards .