Noise from 5v relay


I have a basic circuit where an attiny84a activates a 5v relay. When the relay it's not activated, it makes a very annoying noise/buzzing.

I'm using this AC-DC power supply (AC-DC Power Supply Buck Converter Step Down Module Chip 5V 700mA 3.5W)

And this 5V One Channel Relay Module Board.

The AC-DC power supply is connected to the +/- of the attiny84a (pin1&14) and also it's connected to the relay's +/- pins. The signal pin from the relay is connected to the PB0 (pin 2) on the ATTINY. The load is connected between common/middle pin and the NO pin. I'm testing it with just a normal 220v lamp, nothing crazy. When attiny activates the relay, lamp on, the noise disappears. When attiny switch the relay off, it starts to make that buzzing.
The noise doesn't come from the relay switching quickly. I tested it basically connecting the relay signal to the negative wire but the noise continues.

Code snippet:

// 10 is pin 2 (PB0)
#define RELAY_PIN 10  
void setup() {
    pinMode(RELAY_PIN, OUTPUT);

void loop() {
    // To activate the relay
    digitalWrite(RELAY_PIN, HIGH); 
    // To deactivate the relay
    digitalWrite(RELAY_PIN, LOW);

Any suggestion?

You need some delay between relay operation.

yeah, it's just a code snippet, not the actual code. Let me clarify that in the code

Why not post a schematic, not a frizzy thing and the code.

Thanks, check the circuit above.

There might me some connectivity issue. If your connection is proper than check that is any relay wire or pin is touching each other. Or you must keep some delay between relay operation.

This would imply that the load is switched on when the relay is inactive.
If there is a buzzing noise coming from the relay, that is a bad sign. Some of those relay modules use a PNP transistor and need the trigger to be very close to Vcc to switch it fully off. The better ones have an opto coupler, then their behaviour is very clear.

1 Like

Yeah sorry, I made a mistake in the comments but the circuit was correct, it's the NO pin. I fixed that.
Thanks for you response. I have a replacement replay, I will confirm that soon.

Surely the logic output of an ATmega/ ATtiny is indeed, very close to either Vcc or ground?

Of course, if the assumption is that the power source for the relay module is Vcc of ATmega/ ATtiny. In the case of the OP's particular circuit it would be true. However, often is the case that you need to use a different power source for the relay module(s) to minimise overloading the Arduino regulator.

Is that a mains power supply? Doesn't look safe. In fact if looks like absolute junk to me, and yes a quick search reveals similar units on eBay for £1. That's probably the source of your buzzing.

Never skimp on mains supplies, especially one's without an earth connection, your life could depend on it.

[ BTW this is not an over-reaction - I had one of these cheap chinese supplies that came with a miniature monitor and I was seeing periodic bursts of noise everywhere in my circuit in the 'scope - tracked it down to the PSU, and discovered the transformer in the PSU had primary and secondary wires tightly cutting past each other, only two layers of enamel between 240V and me - the insulation was partially breaking down and creating pulses of noise, otherwise I'd never have realized. ]

1 Like

Yeap, that's the only power supply and you are right. It ended up being the power supply.
I changed it for the one below and the noise is gone.

What do you think about that power supply?

Could you please recommend a good/safe 5V power supply to use with micro-controllers like atmega?

It's hard to say.

It's all (or mostly all) in the design of that transformer - whether it has adequate insulation between primary and secondary. You can't see that unless you actually pull one apart in sacrifice.

Which is why we tend to recommend using a USB "phone charger" either of a reputable brand such as Samsung or Apple, or at least one you buy from a local retailer who bears some legal responsibility for only selling appliances that are fit for use.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.