Relay 5v 8channel arduino uno

I have relay 5v 8 chennel i connect it with arduino and when i upload a code


// تعيين دبوس الريلاي
int relayPin = 7;

void setup() {
pinMode(relayPin, OUTPUT); // تعيين الدبوس كإخراج
}

void loop() {
digitalWrite(relayPin, HIGH); // تشغيل الريلاي
delay(2000); // انتظار لمدة 2 ثانية
digitalWrite(relayPin, LOW); // إيقاف الريلاي
delay(2000); // انتظار لمدة 2 ثانية
}


So it function just one time and stay on the relay

Hello 38aredamohammed38

Post a connection and wiring diagram to see how we can help.

1 Like

Hi @38aredamohammed38

welcome to the arduino-Forum.
Change your code in this was to make visible what your code is really doing

const byte relayPin      =  7; 
const byte onBoardLEDPin = 13; 

void setup() {
  Serial.begin(115200);
  Serial.println("setup-Start");
  pinMode(relayPin,      OUTPUT); 
  pinMode(onBoardLEDPin, OUTPUT); 
}

void loop() {
  Serial.println("Top of Loop");
  digitalWrite(relayPin, HIGH); // Turn on the relay
  digitalWrite(onBoardLEDPin, HIGH); // Turn on the relay
  Serial.println("relay and onboard LED HIGH");
  delay(2000); // Wait for 2 seconds

  digitalWrite(relayPin, LOW); // Turn off the relay
  digitalWrite(onBoardLEDPin, LOW); // Turn on the relay
  Serial.println("relay and onboard LED LOW");
  delay(2000); // Wait for 2 seconds
}

With this code you have two things that make visible what your code is coding

The onboard-led of the arduino is witched ON/OFF whenever the relais is switched on off
In the serial monitor you see text

If you do not see the LED blink 2 seconds on two seconds off
it is very likely that you have a power-supply-problem or an EMV.

Any kind of microcontroller is NOT a power-supply.
Same applies to relais-boards
You should supply power to things like seros or relays this way

Here is a WOWKI-Simulation of an arduino Uno and a relay

1 Like

try setting relayPin to LED_BUILTIN and see if the Arduino LED toggles on/off

1 Like

I will di thank you stefan

Ok i trying to do this :heart_eyes:

pretty sure that the LED will blink. If the onboard-led does not blink you can conclude the problem is hardware related. Could be the relay not connected correctly or relay-current to high making the microcontroller hang or resetting.

The microcontroller resetting could be easily seen in my code-version.
Be repeated showing
"setup-Start" in the serial monitor

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.