Hi, I wrote simple code that triggers the relay after pushing the button. I'am also using build-in led for debugging.
// C++ code
//
int bumper_touch = 0;
void setup()
{
pinMode(7, OUTPUT);
pinMode(4, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(7, HIGH);
digitalWrite(LED_BUILTIN, LOW);
}
void loop()
{
bumper_touch = digitalRead(4);
if (bumper_touch == HIGH) {
digitalWrite(7, LOW);
digitalWrite(LED_BUILTIN, HIGH);
delay(1200); // Wait for 1200 millisecond(s)
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(7, HIGH);
}
}
Everything works fine when the Arduino is powered via USB. However, after connecting it to a power supply in my project, the built-in LED turns off, and the relay switch behaves ein strange way. I replaced the 12V power supply with a different one, and the problem disappeared. I'm really curious why the old power supply didn't work with my Arduino.