Source code coming soon. The GitHub repository is private for now and opens to everyone very soon.
BetterSPICE Beta 0.8.0 Join the beta Download soon
Part VI  Parts and modelsReferenceContentsIndex
34

Devices: relays, switches, motors and audio

Relays, switches and buttons, motors and actuators, buzzers and speakers. The parameter tables use the same columns as Devices: passives. Every part has labelled fields with units in the inspector and in All parameters, and the live stimulus of a sensor (light, temperature, field, strain, distance, load) is its main field, first in the list, with a slider range that fits it. A field that shows auto takes a value derived from other parameters until you type one (for example the must-operate voltage of a relay is 0.75 of its coil voltage). Clear it to go back. A variant placed from the library starts with its own typical values, such as 1 kΩ for a Pt1000 or 1.2 V dropout for an AMS1117. A part placed from the library can start with its own values, and a part made with the Part Wizard takes them from its datasheet fields (Part templates reference).

34.1Relays

Relays
TypePinsVariantsClass
relay (K)spdt: coil+, coil-, com, no, nc. spst_no and reed: coil+, coil-, com, no. spst_nc: coil+, coil-, com, nc. dpst_no: 6 pins. dpdt: coil+, coil-, com1, no1, nc1, com2, no2, nc2. 4pdt: 14 pins.spdt, spst_no, spst_nc, dpst_no, dpdt, 4pdt, reedapproximate, coil exact (verified ±0.01 %)

A real relay: the coil is a resistance in series with an inductance that grows as the armature closes, and the armature picks up when the coil current reaches vpick / rcoil and drops out below vdrop / rcoil, so pick-up and drop-out are found to the exact instant. t_op and t_rel are the datasheet operate and release times: a step to the rated coil voltage closes the NO contact t_op later, the rise of the coil current to pick-up included, and removing the coil power closes the NC contact t_rel later. A lower coil voltage, a hot coil or a flyback diode makes the relay slower, as on the bench. Normally closed contacts open when the armature is 40 % of the way, so a changeover contact breaks before it makes. A pulse shorter than the travel time never closes the NO contact. Placed from the library (K): 5 V coil, 70 Ω, 50 mΩ contacts, 5 ms operate, 3 ms release.

Relays
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Nominal coil voltagevcoilV5> 0Default, inspector, part fileSets the default pick-up and drop-out. A coil voltage above 1.5 x vcoil warns.
Coil resistancercoilΩ70 (reed 500)> 0Default, inspector, part fileDatasheet coil resistance, or V² / P.
Must-operate voltagevpickV0.75 x vcoil> 0Default, inspector, part file
Must-release voltagevdropV0.1 x vcoil≥ 0, below vpickDefault, inspector, part file
Operate timet_ops5 ms (reed 0.5 ms)≥ 0Default, inspector, part fileDatasheet operate time: from the rated coil voltage applied to the NO contact closed.
Release timet_rels3 ms (reed 0.1 ms)≥ 0Default, inspector, part fileDatasheet release time without a diode: from the coil power removed to the NC contact closed.
Contact resistanceronΩ0.05 (reed 0.15)> 0, below roffDefault, inspector, part file
Open resistanceroffΩ1 GΩ> 0File or All parameters
Coil inductance, openlcoilH50 mH (reed 5 mH)≥ 0File or All parameters
Coil inductance, closedlcoil_closedH1.5 x lcoil≥ 0File or All parameters
Contact bouncebounces0≥ 0Default, inspector, part fileEach closing bounces open three times inside this window.
Rated contact currentimaxA10 (reed 0.5)> 0Default, inspector, part fileWarns when a contact carries more.
Max switching voltagevmaxV250> 0Default, inspector, part fileWarns when an open contact sees more.
Coil diodediode0 / 10Default, inspector, part fileA suppression diode across the coil. It also makes the coil polarised.
Polarised coilpolar0 / 10File or All parametersOnly positive coil current operates it.
Initial statestate0 / 10File or All parameters1 starts operated.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Readouts: state, armature position and coil current. The logic analyzer shows coil and state.

Try it
Hear the flyback spike
  1. Place a 5 V source, a switch, the relay coil and ground in series. Probe the coil+ pin.
  2. Run, click the switch closed, then open.

You should seeOpening the switch makes a large negative spike on the coil, the stored energy of its inductance. Set the relay's diode to 1 and the spike is clamped to about -0.7 V, and the release gets slower.

34.2Latching relays

Latching relays
TypePinsVariantsClass
relay_latch (K)single_coil: coil+, coil-, com, no, nc. single_coil_2p: 8 pins. dual_coil: set+, set-, reset+, reset-, com, no, nc. dual_coil_2p: 10 pins.single_coil, single_coil_2p, dual_coil, dual_coil_2papproximate

A single-coil latch sets on a positive coil pulse and resets on a negative one. A dual-coil latch has separate set and reset coils. With no coil current it holds its state, and part way through a move the magnet pulls it to the nearer end. Clicking the part toggles it like the test lever. Placed (Shift+K): 5 V, 125 Ω, 3 ms, 10 ms minimum pulse.

Latching relays
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Nominal coil voltagevcoilV5> 0Default, inspector, part file
Coil resistancercoilΩ125> 0Default, inspector, part file
Set / reset voltagevpickV0.75 x vcoil> 0Default, inspector, part file
Set timet_ops3 ms≥ 0Default, inspector, part fileAlso the reset time.
Minimum pulse widthpulse_mins10 ms≥ 0Default, inspector, part fileA switch on a shorter pulse warns W_LATCH_MARGIN.
Contact resistanceronΩ0.05> 0Default, inspector, part file
Rated contact currentimaxA2> 0Default, inspector, part file
Statestate0 / 10Click it on the canvasSet or reset.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Energising both coils of a dual-coil latch at once doesn’t move it and warns W_LATCH_BOTH.

34.3Solid-state relays

Solid-state relays
TypePinsVariantsClass
ssr (K)in+, in-, out1, out2dc (MOSFET output), ac (triac, zero cross), photomos (AC and DC)approximate, LED exact

An LED input that turns the output on above if_on and off below if_off, after t_on or t_off. The dc output is a MOSFET with a body diode from out2 to out1. The photomos output conducts both ways. The ac output is a triac: it fires only when the output voltage is below vzc and stays on until its current falls below ih, so a DC load never turns it off.

Solid-state relays
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Input operate currentif_onA5 mA> 0Default, inspector, part file
Input release currentif_offA0.4 x if_on> 0, below if_onFile or All parameters
LED forward voltagevfV1.2> 0Default, inspector, part fileAt 10 mA.
Turn-on timet_ons100 µs≥ 0Default, inspector, part file
Turn-off timet_offs100 µs≥ 0Default, inspector, part file
On resistanceronΩ0.1> 0Default, inspector, part file
Off resistanceroffΩ10 MΩ (ac 1 MΩ)> 0File or All parameters
On-state voltagevtmV1.0≥ 0Default, inspector, part fileac only.
Holding currentihA50 mA> 0Default, inspector, part fileac only.
Zero-cross windowvzcV15≥ 0Default, inspector, part fileac only.
Rated load currentimaxA2> 0Default, inspector, part fileWarns when exceeded.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

34.4Switches and buttons

Switches and buttons
TypePinsVariantsClass
sw (SW)spst, push_no, push_nc, reed: com, a. spdt, toggle, slide: com, a, b. dpst: com1, a1, com2, a2. dpdt: com1, a1, b1, com2, a2, b2. tact4: a1, a2, b1, b2. micro: com, nc, no. dip1 … dip10: two pins per switch. rotary: com, p1 … p8.spst, spdt, toggle, slide, dpst, dpdt, push_no, push_nc, tact4, micro, reed, dip1 … dip10, rotaryapproximate

Real switch contacts with resistance, bounce and break-before-make. Click a switch while the circuit runs: a toggle changes position, a push button is pressed while you hold the mouse button, a rotary switch steps to its next position. A tactile switch joins a1 to a2 and b1 to b2 permanently, and a1 to b1 while pressed. A reed switch closes when state is 1 or the applied field reaches b_close, and opens below 60 % of it. A DIP switch's state is a bit mask: bit k closes switch k + 1. Click a DIP switch on the canvas and the one under the pointer flips (the row from its com pin to its a pin that is nearest), so one click on switch 3 and then one on switch 1 gives a mask of 5. The Activity tab records it, for example SW1: switch 3 on. The core switch (key S, Devices: passives) is a simpler two-pin version.

Switches and buttons
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Positionstate00 to 1023, a whole number below the number of positionsClick it on the canvas, part fileLever position, pressed state, DIP bit mask or rotary position.
Contact resistanceronΩ0.02> 0, below roffDefault, inspector, part fileCan change while running.
Open resistanceroffΩ1 GΩ> 0File or All parameters
Bounce timebounces0≥ 0Default, inspector, part fileThree bounces on every closing. 2 ms is realistic for a tactile switch.
Break-before-make gapt_breaks1 ms for changeover types, 0 otherwise≥ 0File or All parameters
Rotary positionspositions82 to 8Default, inspector, part file
Reed closing fieldb_closeT1 mT> 0File or All parameters
Applied fieldb_fieldT0≥ 0Live sliderReed only.
Rated currentimaxA50 mA for buttons and DIP, 3 A otherwise> 0Default, inspector, part fileWarns when exceeded.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Try it
See contact bounce on a button
  1. Place a 5 V source, a 10 kΩ pull-up, a push button (sw, push_no) to ground, and probe the node.
  2. Set the button's bounce to 2m and the timebase to 10 ms per second.
  3. Click and hold the button.

You should seeThe node falls to 0 V with three short bounces back up inside the first 2 ms. A logic input on that node would count several presses.

34.5DC motors

DC motors
TypePinsVariantsClass
dcmotor (M)+, -brushed, fan, vibration, gearapproximate, verified ±0 % at no load

An armature resistance and inductance with a back-EMF ke · ω, and a rotor with inertia, viscous friction and a load torque: J dω/dt = kt · i - b ω - T_load, with kt = ke. All of it comes from datasheet numbers: R = v_rated / i_stall, ke from the no-load speed and current, J from the mechanical time constant. A fan adds an aerodynamic load that rises with speed squared. Reversing the voltage reverses it, and driving it from outside makes it a generator. Readouts: rpm (of the output shaft), torque, mechanical power and efficiency.

The gear variant places a yellow TT gear motor: 6 V, a motor of 10 000 rpm at no load, a 1:48 gear (so about 208 rpm at the output), 1.5 A stall and 0.15 A no load. The two shafts differ: No-load speed belongs to the motor shaft, while the rpm readout and the Load torque belong to the output shaft after the gear.

DC motors
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Rated voltagev_ratedV12> 0Default, inspector, part file
No-load speedrpm_noloadrpm3000> 0Default, inspector, part fileAt v_rated, of the motor shaft, before any gear. The rpm live value is the output shaft: this number divided by the gear ratio.
Stall currenti_stallA1> 0Default, inspector, part fileSets R = v_rated / i_stall.
No-load currenti_noloadA0.05≥ 0, below i_stallDefault, inspector, part file
Armature inductancelH1 mH≥ 0Default, inspector, part file
Mechanical time constanttau_mechs50 ms> 0Default, inspector, part fileStart-up to 63 %.
Load torquet_loadN·m0≥ 0Live slider
Gear ratiogear1> 0Default, inspector, part fileGear variant: output speed = motor speed / gear. The load torque acts on the output shaft.
Commutation rippleripple, segments0, 30 to 0.3, 1 to 64Default, inspector, part fileAdds current ripple at segments x 2 per revolution.
Max currenti_maxA2 x i_stall> 0Default, inspector, part fileWarns when exceeded, and when stalled above 80 % of i_stall for 2 s.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Try it
Load a motor
  1. Place a 12 V source and a DC motor. Probe the motor current.
  2. Run, then drag the motor's load torque slider up.

You should seeThe current starts high, falls to the no-load 50 mA as the motor reaches 3000 rpm, then rises as you add load while the rpm readout falls.

34.6Stepper motors

Stepper motors
TypePinsVariantsClass
stepper (M)bipolar: a+, a-, b+, b-. unipolar6: a1, acom, a2, b1, bcom, b2. unipolar5 (28BYJ-48): com, a1, b1, a2, b2.bipolar, unipolar6, unipolar5approximate, windings exact

Two phases with resistance, inductance and a back-EMF that depends on the rotor angle, a detent torque, inertia and damping. Full, half and micro stepping, resonance, missed steps and the fall of current at speed all come out of the equations. Readouts: shaft angle, rpm and step.

Stepper motors
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Steps per revolutionsteps200> 0Default, inspector, part file
Phase resistancer_phaseΩ2.8> 0Default, inspector, part filePer half winding for unipolar.
Rated phase currenti_ratedA1> 0Default, inspector, part file
Holding torquet_holdN·m0.4> 0Default, inspector, part fileTwo phases at i_rated.
Phase inductancel_phaseH3 mH≥ 0Default, inspector, part file
Rotor inertiajkg·m²5.4 x 10-6> 0Default, inspector, part file
Detent torquet_detentN·m0.02≥ 0Default, inspector, part file
Viscous dampingbN·m·s10-4≥ 0Default, inspector, part file
Load torquet_loadN·m0≥ 0Live slider
Gear ratiogear1> 0Default, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

34.7BLDC motors

BLDC motors
TypePinsVariantsClass
bldc (M)sensorless: u, v, w. hall: u, v, w, ha, hb, hc, hvcc, hgndsensorless, hallapproximate

Three star-connected phases with a trapezoidal (or sine) back-EMF. The Hall variant has three open-drain sensor outputs that need pull-ups.

BLDC motors
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Velocity constantkvrpm/V1000> 0Default, inspector, part file
Phase resistancer_phaseΩ0.1> 0Default, inspector, part file
Magnet polespoles142 to 100Default, inspector, part file
Phase inductancel_phaseH20 µH≥ 0Default, inspector, part file
Rotor inertiajkg·m²2 x 10-6> 0Default, inspector, part file
Load torquet_loadN·m0≥ 0Live slider
Back-EMF shapeemftraptrap, sineDefault, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

34.8Solenoids, servos and encoders

Solenoids, servos and encoders
TypePinsVariantsClass
solenoid (L)+, -pull, push, valve, lock (same physics)approximate, coil exact

A coil whose inductance grows as the plunger moves in, with the plunger's mass, a return spring and end stops, so the current dips at pull-in as on a real solenoid.

Solenoids, servos and encoders
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Rated voltagev_ratedV12> 0Default, inspector, part file
Coil resistancerΩ24> 0Default, inspector, part file
Travelstrokem5 mm> 0Default, inspector, part file
Inductance out / inl_out, l_inH20 mH, 60 mH> 0, l_out < l_inDefault, inspector, part file
Pull-in timet_moves10 ms> 0Default, inspector, part file
Pull-in currenti_pullA0.7 x v_rated / r> 0Default, inspector, part file
Drop-out currenti_releaseA0.3 x v_rated / r≥ 0, below i_pullDefault, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Solenoids, servos and encoders
TypePinsVariantsClass
servo (M)sig, vcc, gndanalog, digital, continuousapproximate

Measures each pulse on sig and moves the horn towards the matching angle at its slew rate, which scales with the supply. Analog and continuous servos stop holding 25 ms after the last pulse, digital servos keep holding. A continuous servo turns at a speed set by the pulse width.

Solenoids, servos and encoders
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Travelrange°180> 0Default, inspector, part file
Slew ratespeed°/s600> 0Default, inspector, part fileAt 5 V.
Pulse at 0° / full rangepw_min, pw_maxs1 ms, 2 ms> 0, pw_min < pw_maxDefault, inspector, part file
Minimum supplyv_minV4≥ 0Default, inspector, part file
Idle / stall currenti_idle, i_stallA6 mA, 0.8 A≥ 0Default, inspector, part file
Initial angleangle°90anyDefault, inspector, part file
Signal thresholdvthV1.5> 0Default, inspector, part file
Deadbanddeadbands4 µs≥ 0Default, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Solenoids, servos and encoders
TypePinsVariantsClass
encoder (SW)3pin: A, C, B. 5pin: plus S1, S2 (push switch)3pin, 5pinapproximate

A mechanical quadrature encoder: contacts A and B close in quadrature as the shaft turns, A leading B for increasing position, both open at a detent. Change pos to turn it one detent per 20 ms, or set rpm to turn it continuously.

Solenoids, servos and encoders
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Pulses per revolutionppr201 to 1000Default, inspector, part file
Detents per revolutiondetents201 to 1000Default, inspector, part file
Shaft positionposdetents0anyLive slider
Continuous speedrpmrpm0±100 000Live slider
Contact resistanceronΩ2> 0Default, inspector, part file
Bouncebounces0≥ 0Live slider
Push switchpush0 / 10Live slider5pin.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

34.9Buzzers and speakers

Buzzers and speakers
TypePinsVariantsClass
buzzer (BZ)+, -magnetic, piezo (passive), active, active_piezo (self-oscillating)approximate

A passive magnetic buzzer is its coil plus a tuned motional network. A passive piezo is a capacitance with a motional branch. An active buzzer draws v_rated / i_rated above v_min with a small ripple at its tone. The spl readout is the relative sound level, 0 to 1.

Buzzers and speakers
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Frequencyf0Hz2700 (piezo 4000)> 0Default, inspector, part file
Rated voltagev_ratedV5> 0Default, inspector, part file
Rated currenti_ratedA30 mA> 0Default, inspector, part file
Coil resistancerΩ16> 0Default, inspector, part fileMagnetic.
Coil inductancelH1.5 mH> 0Default, inspector, part fileMagnetic.
CapacitancecF20 nF> 0Default, inspector, part filePiezo.
Mechanical Qq8> 0Default, inspector, part file
Minimum voltagev_minV3≥ 0Default, inspector, part fileActive.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Buzzers and speakers
TypePinsVariantsClass
speaker (LS)+, -noneapproximate

The Thiele-Small electrical equivalent: voice-coil resistance and inductance, then the motional resonance at fs set by qms and qes. Warns above its rated power.

Buzzers and speakers
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Nominal impedancezΩ8> 0Default, inspector, part fileSets re.
Voice-coil resistancereΩ0.8 x z> 0Default, inspector, part file
Voice-coil inductanceleH0.1 mH≥ 0Default, inspector, part file
Resonance frequencyfsHz150> 0Default, inspector, part file
Mechanical / electrical Qqms, qes3, 0.8> 0Default, inspector, part file
Rated powerp_ratedW1> 0Default, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.