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() {
delay(1000);
...
// To activate the relay
digitalWrite(RELAY_PIN, HIGH);
delay(5000);
...
// To deactivate the relay
digitalWrite(RELAY_PIN, LOW);
delay(5000);
}
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.
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.
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. ]
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.