Electronic – arduino – Relay Module turns on and off in a loop

arduinopower supplyrelay

I'm creating a box that let's you turn on and off a power source using a button.

The setup

  • Power Supply converting 230AC to 12V DC
  • 12V goes to power the LED on the button
  • 12V goes to a protoboard converting 12V to 5V 1.5A
  • 5V goes to protoboard with an Aurdino, controlling a 2 Relay Module

The problem

If I give the Aurdino power through the micro USB, it works as it should. One click on the button, and the Relay is turned on (light goes on and gives off a clicking sound).

But when I remove the USB and try to give the Arduino power from the converted 5V, through the pins, it goes into some kind of loop when I press the button. I can hear/see that the Relay is turned on/off quickly in a continuous loop.

The question

What's going on here? My guess would be that there is an issue with the protoboard with the Arduino, but I can't successfully debug the problem.

Documentation

Video of the problem

int ledPin = 13;    // choose the pin for the LED
int inputPin = 7;   // choose input pin 7 for the push button
int relay = 8;
 
void setup() {
    pinMode(ledPin, OUTPUT);  // declare LED as output
    pinMode(inputPin, INPUT); // declare push button as input
    pinMode(relay, OUTPUT);
}
 
void loop() {
    int pushed = digitalRead(inputPin);  // read input value
  
    if (pushed == HIGH) { // check if the input is HIGH    
        digitalWrite(ledPin, HIGH);  // turn LED OFF
        digitalWrite(relay, LOW);
    } else {
        digitalWrite(ledPin, LOW);  // turn LED ON
        digitalWrite(relay, HIGH);
    }
}

enter image description here

Best Answer

SAFETY first.

  1. Your 230V input plug (on the right side of the photo) should be shielded using either electrical tape or heatshrink.
  2. There should be a physical barrier preferably made out of acrylic or ABS or any kind of plastic would do the trick.

By the sounds of it, your Arduino board is browning out as soon as you supply power to it using the SMPS. I would recommend that you first shield your 230V mains and make it completely safe for troubleshooting. I also recommend that you test the output of the 5V regulator. Somehow your DC power supply is either not functioning correctly, or has way too much noise for Arduino. Although the noise should be fixed through the 5V regulator but still, something to look into. Also, your 5V regulator may need a heatsink for heat dissipation. 12V - 5V = 7V. Therefore, 7V * 1.5A = 10.5W. Even if you don't use 1.5A of current, your 5V regulator might still be getting warm and you may need a heatsink to keep it cool and happy.

I also recommend not to use breadboard and have mains voltage in the same space. It is not a good practice and certainly quite risky. I would recommend you to build a PCB where all the components are soldered (glued) to the board with no wires that could detach from the breadboard and touch any 'unshielded' 230V terminals which is just a disaster waiting to happen.