Kicad "Relay- TIANBO-HJR-4102-L" ngspice model


I am new to this pcb area, I am trying to simulate a circuit using the Kicad, that schematic consists of a SPDT relay model. I am not sure how to simulate relays in kicad will they also have the spice models. If yes, I searched in google I couldn’t find one. If anyone share your spdt spice model and symbol of it that would be great. Thanks in advance.

You will find a symbol for this relay in the standard symbol library (check “Relay”).

Eeschema/ngspice do not provide ngspice models.

Did you check with the relay manufacturer if they offer a spice model?

If not, do you have a data sheet for this relay? One then has to create its own spice model. A very simple model would use a resistor at the input and 2 switches at the output. A more sophisticated model would use an inductor + series resistance at the input, and contact resistance at the outputs. It depends a little on what you want to achieve with the simulation.

1 Like

No reply, no success?

So lets start model building as an exercise (for me).

First of all we need the data sheet for the relay. The internet offers .
Looking at the data sheet it immediately becomes obvious that there is not enough information available in the first post of this thread. Several relay variants are offered, different coil powers and different excitation voltages.

So to start I have chosen a very common variant, 200 mW coil power and 12 V excitation with the model HJR-4102-L 12V.

Then I have found a very simple relay spice model at , which has to be modified accordig to the data sheet which tells me: Max operate voltage 9 V, Min Release voltage 1.2 V. So we will have a hysteresis: on at 9, off at 1.2 V. On the secondary side we have a max. contact resistance of 100 mOhms, so lets take here 50 mOhms. The insulation resistance is min 100 MegOhm, so lets assume 500 Meg. The resulting subcircuit model will be

.subckt HJR-4102L12-simple COM NO NC POS NEG
.model MYSW1 SW(Ron=.05 Roff=500Meg Vh=2.7 Vt=3.9)
.model MYSW2 SW(Ron=.05 Roff=500Meg Vh=2.7 Vt=-3.9)

switching on at Vt+Vh, off at Vt-Vh. We need 2 switches in series due to the double throw.

Put this model into a file, e.g. named spice-models.lib. When you attach this model to the symbol, don’t forget to set the ‘Alternate node sequence’ to 12 6 7 5 8. Thus the node numbers on the symbol and the subcircuit nodes are matched correctly. See for an example.

The above model however is overly simplistic. Especially on the primary side in reality we have a coil with its inductance and ohmic resistance. The switches are actuated not by a voltage, but by a current through the coil. The data sheet gives the series resistance (720 Ohms), no mention of the inductance. But there is a delay specified, max. 5 ms. This will result in a slightly more complex model.

.subckt HJR-4102L12 COM NO NC POS NEG
R1 POS INT1 720   ; coil resistance
Vmeasp INT1 INT2 0 ; to measure the coil current
Vmeasn INT3 INT2 0 ; to measure the coil current (reverse polarity)
L1 INT3 NEG 300m ; just a guess !
W1 COM NO Vmeasp MYSW3
W2 COM NC Vmeasn MYSW4
* Ion=9/720=12.5m, Ioff=1.2/720=1.67m, It=(Ion+Ioff)/2=7.1m Ih=Ion-It=5.4m
.model MYSW3 CSW(Ron=.05 Roff=500Meg Ih=5.4m It=7.1m)
.model MYSW4 CSW(Ron=.05 Roff=500Meg Ih=5.4m It=-7.1m)

The model uses current controlled switches. The current rises, limited by L1 and R1 in series, to its static value (12 V/720 Ohms). The resulting switching delay is about 1 to 1.5 ms. While R1 was given, the inductance is estimated only (see, because the data sheet does not specify a value.

This subcircuit may also be added to the file spice-models.lib, either subcircuit model may be selected during attaching it to the Eeschema HJR-4102 relay symbol.