Control Relays With AVR

From Electriki
Jump to: navigation, search

How to control relays/coils/selenoids with an AVR (or any other MCU).

Fig.1: The first LED blink on board.

What's this all about?

Want to use high current load outputs in your projects? Here I present you the easiest way of doing it. This allows me to use MCU based low voltage control system in any other automatics standard system.

What is it exactly?

Lawn watering systems got really accessible in recent years. Why not just use few valves to water whole lawn nicely? But these electro-valves (selenoids) take much current... Why not control these via relays? But relays are easier to get for rather high (compared to MCU) voltage control... So why not use the typical common-emitter circuitry? Yeah, the ULN2803 has some protection agains inductive loads built in.

The device

Implementing timer in this device would complicate it a lot. Crystal, inputs to set clock, display to check clock... The PCB would get at least twice as big. I decided to simplify the design and drop the software timer idea. Instead, an electromechanical rotary wall-outlet mount programmer will be used to set when this is going to work.


What I've come up with is a small PCB (visible on Fig.1). What is its rule of operation?

  • It enables up to 8 output relays in order 1 to n. Then it starts from the number 1 again, and so on...
  • The number of output relays used in a cycle is given to the device by 4 input lines (with help of a decimal to BCD encoder). The selected number of outputs is being blinked at every boot.
  • The default number of relays to use is set in firmware (takes effect when encoder isn't attached (or has value 0 set)).
  • The default time for each cycle is 5 minutes. This means, that each relay will be energized for only 5 minutes.
  • Each relay can take up to 500mA with the ULN2803.
  • One connector (left on Fig.3) is to attach the encoder, other connector (bottom) is used to deliver 24VDC, the last connector (right) is used to connect output relays.


The original concept featured some optional LED, but I never used it. Instead there's a switch attached to this AVR input line:

  • If the switch is pressed during the boot up, the device only idles w/o energising any relay. This allows to manually open some valve with the pump enabled, etc.
  • Keeping the switch pressed for 3 seconds during normal cycle forces the driver to another cycle step, i.e. turn off relay 2 and turn on relay 3.


The gallery

Is it good?

So far it's all been only tested on my desk. No flaws noticed so far, no reason to doubt it will work perfectly well. However I will comment the device once the final app serves it's time.


--

Cheers,

pit, 2015-07-15