enter image description hereI have a fairly simple code to turn a relay on-off every 2 seconds When i attach the USB of the arduino Uno to the laptop, it goes into a frenzy and the relay triggers on off for 6 times within 3-4 seconds and then it settles down. This however doesnt happen when connecting directly to the power output.
Is there something that needs to be wired to stop this happening ?
I am using an arduino Uno with a relay JQC-3FF-S-Z connected directly to the arduino pins.
const int ONOFF_TRIGGER_PIN = 2;
void setup() {
// put your setup code here, to run once:
pinMode(ONOFF_TRIGGER_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(ONOFF_TRIGGER_PIN, LOW);
delay(2000);
digitalWrite(ONOFF_TRIGGER_PIN, HIGH);
delay(2000);
}
-
The code is so simple, this has to be a hardware problem. Please add a schematic or a wiring diagram to your question.JRobert– JRobert2020年10月15日 22:32:24 +00:00Commented Oct 15, 2020 at 22:32
-
Thanks @Jrobert ive added a fritzing image. Couldnt find the the exact same relay component i have JQC-3FF-S-ZLooneystar– Looneystar2020年10月15日 22:44:19 +00:00Commented Oct 15, 2020 at 22:44
-
Put a voltmeter on the pin and to ground while the Uno is starting up with the relay detached. Note any fluctuations. Now, connect the relay with the voltmeter still attached, and restart the Uno. Do you see any difference with the voltage behaviour of the pin?stevieb– stevieb2020年10月15日 23:14:41 +00:00Commented Oct 15, 2020 at 23:14
-
1@hcheung - Ive tried it on both 5v and 3v. it works on both.Looneystar– Looneystar2020年10月16日 01:48:35 +00:00Commented Oct 16, 2020 at 1:48
-
1@hcheung but after the first 3-4 seconds (which i assume is the arduino booting up or something), it starts to work as per the program, So its just the initial phase. Also, when hooking the arduno to a powersupply, the relay pins are still connected to the arduino. So maybe the arduino i have is corrupted somehowLooneystar– Looneystar2020年10月16日 02:48:21 +00:00Commented Oct 16, 2020 at 2:48
1 Answer 1
The markings on your relay suggest the coil is for 5VDC. But you have the coil supply wired to 3V3. Move the coil supply to 5V, and try again.
-
I agree with @Seamus. We don't know what might be going on with the 3v supply during boot up, but going to be marginal for a 5v even at steady state. At least try this and find out.JRobert– JRobert2020年10月16日 17:12:58 +00:00Commented Oct 16, 2020 at 17:12