int val= 0;
void setup() {
// put your setup code here, to run once:
pinMode(29, INPUT);
pinMode(20, OUTPUT);
digitalWrite(20, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(29);
if (val == HIGH)
{
digitalWrite(20, LOW);
}
val = digitalRead(29);
if (val == LOW)
{
digitalWrite(20, HIGH);
}
}
Hi All, need a bit of help with my arduino mega. I'm relatively new, so not got the best coding skills.
Attached is my schematic.
I have a push button which controls a relay, when pushed, the relay turns on and when released, the relay turns off. This works well, but the only issue is when I connect 12v to the output side of the relay, when the relay is turned on it causes the mega to reset, which for my other code is an issue.
I've tried it without the 12v supply and it works fine, any ideas how i can get it to work all the time?
Hi, the power source is a 12v dc wall adapter. 12v+ is connected to COM on the relay and then the output from the relay is connected to NO on the relay.
I've now worked out that the issue comes when I digitalWrite(20, HIGH); this then causes the mega to reset. Wiring is fine, as I have 3 other relays set up the same and they work fine.