1
\$\begingroup\$

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

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Does the Arduino restart ( i.e. run the setup) or just run the loop but think that the button is released? I don't know how much the Arduino consumes but turning on the relay increases the regulator heating by 0.5W, so does the regulator heat up and go into thermal shutdown? Also the mains switching looks a bit hazardous. If you plug that device into ungrounded outlet and it happens to switch off the neutral, you can end up with mains coupled to metal case via filter caps. \$\endgroup\$
    – Justme
    Commented Aug 21, 2020 at 12:42
  • \$\begingroup\$ Thanks for that. Will look at the mains switching. The Arduino does not restart. You can watch the video, and turn on the sound to verify this. Linked above. \$\endgroup\$
    – eivindml
    Commented Aug 21, 2020 at 13:06
  • \$\begingroup\$ Looking at the code, how do you know it does not restart? \$\endgroup\$
    – Justme
    Commented Aug 21, 2020 at 14:54
  • \$\begingroup\$ Is pwr floating when USB gnd is removed? EMI problem? \$\endgroup\$
    – D.A.S.
    Commented Aug 22, 2020 at 5:50
  • 2
    \$\begingroup\$ Try running the power for the relay board directly from the 5V on the 12V-to-5V board. That will reduce the voltage drop along the wires to the Arduino. \$\endgroup\$
    – jfowkes
    Commented Aug 26, 2020 at 7:09

2 Answers 2

3
+100
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ Thank you for your reply. :) I'm new to making things more permanent than protoboards, so will take your suggestion and do some changes. :) I checked the output of the converter, and it keeps consistent. My only issue now, is that I can't reproduce the problem anymore. Tried 10+ times, and it doesn't reboot anymore. :S \$\endgroup\$
    – eivindml
    Commented Aug 25, 2020 at 12:39
  • \$\begingroup\$ The issue probably was with the voltage drop. I did as @jfowkes instructed, and powered the relay directly from the 5v source, and it no longer reboots it looks like. Haven't been able to reproduce the issue. Will mark this as the answer, as it was the clearest answer, but many people helped here. \$\endgroup\$
    – eivindml
    Commented Aug 26, 2020 at 8:14
  • \$\begingroup\$ @eivindml, that is great. happy to have helped \$\endgroup\$ Commented Aug 26, 2020 at 8:25
1
\$\begingroup\$

From your image it looks as if you have your made your own 12v to 5v converter, so what might be happening is that the voltage that goes to your arduino is getting dropped to less than 2.7v and that causes a Brown out reset(since it is on by default). This explains the fact that your Arduino is resetting from external supply but not from USB. However you must check that voltage

\$\endgroup\$
2
  • \$\begingroup\$ I've checked the output voltage of the converter multiple times now, and it keeps consistent. Drops maybe 0.01V. But now I'm not able to reproduce the problem. Tried at least 10 times. \$\endgroup\$
    – eivindml
    Commented Aug 25, 2020 at 12:37
  • \$\begingroup\$ is your problem is fixed now? \$\endgroup\$ Commented Aug 25, 2020 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.