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
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);
}
}