New User problems with relays

I've had an Arduino UNO for some years but recently also bought some nanos and actually got round to trying to use them.

I prefer to learn by trial and error so I am trying to put together a circuit which has 2 relays.

The aim of this project is to use the Nano to switch on some 12v LEDs when it goes dark and switch them off at a specific set time before it gets light again. This is done by controlling a 220v AC to 12v transformer. I'm using some 1.2v recharageable batteries to power the nano and relays up until when the transformer's ON. The transformer 12v output also is stepped down to take over from the batteries and recharge them.

I have got stuck with this, because when the relay passing the 5v current is activated on it's solidly switched on. However, when it's supposed to be unactivated, it chatters (off and on at fairly high speed). Have tried putting a flywheel diode across the relay coil terminals - no effect. Have tried putting a capacitor across the terminals - no effect.

I have tried this BOTH with activating the relay drectly with the output from a digital pin AND using the output to forward bias an NPN transistor to pass current from the nano 5v output pin

Have used a test sketch to trial this and serial monitor/serial plotter show a fluctuation in the digital output apparently causing the chatter. It' happerns both when output is high and low, but the relay stays on when it's high.

In the test sketch the relay gets a current from digital pin D2 in response to a 1.2v signal into analog pin A3

Has anyone any deas on how to stop the chatter?

The test sketch is-

void setup() {

Serial.begin(9600);

pinMode(A3, INPUT);

pinMode(2, OUTPUT);
}

void loop() {

int timStatus =analogRead(A3);

if (timStatus > 0) {

digitalWrite (2, HIGH);

Serial.println(timStatus);

} else {

digitalWrite (2, LOW);

Serial.println(timStatus);

}

}

I think we need to see a schematic.

What is timStatus? It's not surprising if an analog input is not exactly zero so this may be the source of your problem.

You can test/troubleshoot the relay operation by running a modified version of the Blink Example (maybe with a 5-second delay so you can tell if the relay is chattering, and of course write to pin 2.)

You can test/troubleshoot the analog input with the Analog Read Serial Example. You'll probably find that you need to increase the threshold to something higher than zero (assuming you're getting useful readings at all).

This is done by controlling a 220v AC to 12v transformer.

A transformer is AC (input and output) so I assume you actually have a 12V DC power supply? (The main component of a power supply is a transformer.)

“I prefer to learn by trial and error . . . ”

Deepest condolences :frowning:

I prefer to learn by trial and error

The only thing you learn that way with electronics is how to blow stuff up. It really doesn’t result in any learning, the only thing you accomplish is to transform expensive bits of silicon into worthless trash.

Your post is lacking the necessary detail to be able to help you. Please have a read here, especially the topics about providing links to components, schematics and other relevant information.

How to use this forum