Relay module
A logic level on one side, something that has nothing to do with logic on the other.
- 6 pins
- 3 settings
- In 16 projects
- In 2 lessons
The Relay module in brief
What it is, and every setting the properties panel gives it.
A relay module lets a microcontroller pin switch something that has nothing to do with it. A logic level on IN energizes a coil, the coil pulls a metal arm across, and the arm moves from the normally closed contact to the normally open one; COM is the arm. The board’s 5 volts and whatever the contacts switch share nothing at all. Mokxi’s relay is slow in the way a real one is: 10 milliseconds to pull in and 5 to drop out, with neither contact made while the arm is traveling, so a sketch that toggles it very fast gets nothing, here and on the bench. Below 4 volts on the coil supply it does not pull in whatever IN says. The trigger property is high or low, because most cheap blue relay boards switch when IN is pulled to ground and a sketch written for the other kind runs backwards.
- Family
- Outputs
- Pins
- 6
- trigger
- high (or low)
- high (the default here, matching a bare coil and transistor) or low (the cheap blue boards are nearly all active-low, because their opto-coupler is wired to the rail).
- pull_ms
- 10
- 10 and 5 ms, the SRD-05VDC datasheet numbers.
- release_ms
- 5
- 10 and 5 ms, the SRD-05VDC datasheet numbers.
A circuit built around it, running and explained: the Relay simulator.
6 pins
Named as the editor names them, so a wire lands where you expect it.
COM moves to when energized.COM rests when not energized.How to use a relay module with an Arduino
VCC to 5 V, GND to GND and IN to a digital pin. On the other side, COM is the moving arm: wire it to the supply for the thing you are switching, and wire that thing to NO so it is off until the relay pulls in. Then digitalWrite() the IN pin.
Check which way your board triggers. Most cheap blue relay boards are active low and switch when IN goes to ground; set the part’s trigger property to match the one you have. Never switch a relay faster than it can move: it takes about 10 milliseconds to pull in.
What is true about the Relay module, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
A relay is slow, and the timing is the part people get wrong: 10 ms to pull in and
5 ms to drop out, matching the datasheet. During that travel neither contact is
made (the arm is genuinely in the air, which is "break before make"), so a sketch
toggling a relay at a kilohertz does nothing at all here either, exactly as it does
nothing on the bench. Below 4 V across VCC/GND the coil cannot pull the arm over
at all, whatever IN says, which is the failure everyone meets running a relay off
a board's regulator with a motor on the same rail.
Not modeled
Contact bounce on the way in, the arc across an inductive load, and the flyback diode, which is already on the module, and is why nothing here needs one added.
The coil draws its current: while IN is telling it to pull, 70 ohms (the
SRD-05VDC's coil, 71 mA at 5 V) sits across VCC and GND, so a meter in the
supply lead reads it and a battery or regulator feeding it sags by it. It is a
resistance and not a coil: no inductance, and the pull-in threshold is a flat 4 V
with none of the real coil's hysteresis (once in, a real one holds down to about
half a volt). The module's transistor and LEDs, a few milliamps, are left out.
IN is a logic level against half the supply rather than the opto-coupler's LED.
pull_ms and release_ms are exact and identical on every operation, where a real
relay's travel time varies with coil voltage and temperature and gets longer as it
ages. The contacts are ideal metal with no rating, no resistance drift and no welding.
From Relay module (SRD-05VDC style), in full.
See the Relay module in a project
16 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
2 lessons place it in their own circuits.
The boards it is shown on
Each of these 2 boards has a built-in project with the Relay module in it.
The Relay module on each board
The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Relay module
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.