Yoctopuce offers a range of relay modules. At first sight, nothing out of the ordinary, you can find tens of USB relays on Internet. But it so happens that the Yoctopuce relays provide a few rare features for this kind of devices. This week, we review some of these advanced features...
Yoctopuce relays: family picture
To simplify the production process, all Yoctopuce modules are based on the same 16 bit microprocessor. For relays, using such a processor to finally use only one small information bit is clearly an overkill. However, this allows us a number of quirks: it becomes very easy to delegate to the relay processor some of the computations that, normally, should be performed by the control computer. Obviously, we couldn't resist taking advantage of this. Over time and over requests from our customers, we added some very useful features without really advertising them.
All of our relays are based on the same principle, they have two sates: A and B. State A is the idle state. Let's see the different ways to switch from one state to the other.
set_state
It's the basic function, that you know if you have already used a Yoctopuce relay. Here is a command line example which switches a relay into state B.
YRelay any set_state B
The effect of the set_state function
pulse
The pulse function allows you to switch the relay into state B for a given duration before it automatically switches back to state A. This way, you don't have to contact the relay again to switch back into state A.
The effect of the pulse function
There is another more interesting application: failsafe control process. Let's suppose that you want to build an automatic watering system for your garden, based on solenoids and relays. You don't necessarily want to come back from your vacation to find a lake instead of your garden because the control software has crashed leaving the solenoids open. The trick is to use the pulse function periodically with a duration slightly longer than the call frequency. Thus, if the control software crashes, the relay automatically goes back to its idle state, closing the solenoids.
Using the pulse function for process control
Here is a command line example of the pulse function which switches a Yoctopuce relay for a duration of 5 seconds.
YRelay any pulse 5000
delayedPulse
The delayedPulse function is the big sister of the pulse function. It makes the relay wait for a given time, then switch to state B, wait for another given duration, and switch back to state A. It's interesting when you know that you are going to lose control of the relay. For instance, if you need to switch off or disconnect the control computer, and only then to switch the relay. Note that the relay must remain powered, with a USB hub for example.
The effect of the delayedPulse function
Here is an example of the delayedPulse function in command line, requesting the relay to wait for 2 seconds, then to switch to state B for 5 seconds.
YRelay any delayedPulse 2000 5000
set_stateAtPowerOn
With the exception of the Yocto-LatchedRelay, all the Yoctopuce relays switch back to state A when they are not powered anymore. Many customers requested a function to enable them to automatically set the relay to state B when powered on. Thus, if you have an appliance with a USB port, such as a computer, a TV set, a home theater amp, and so on..., you can automatically switch on/off another appliance when powering on/off the first one.
Here is a command line example enabling you to program a relay to automatically switch to state B when powered on. Note the -s that is used to save the parameter in the module flash memory.
YRelay -s any set_stateAtPowerOn B
set_maxTimeOnStateA, set_maxTimeOnStateB
You can program your relay to prevent it from staying more than a given time in one of its states. When the duration has elapsed, the relay automatically switches back into the other state. One of the interesting applications concerns the Yocto-LatchedRelay: it contains an input which enables you to switch it with a simple push button. You can thus easily build a timer, to manage lighting for instance.
Here is a command line example limiting to two seconds the time the relay can stay in state B.
YRelay any set_maxTimeOnStateB 2000 YRelay any set_state B
Another fun application: if you configure maxTimeOnStateA and maxTimeOnStateB, your relay starts to seesaw from one state to the other. A simple and very handy way to make lighting blink.
The effect of the set_maxTimeOnStateA and set_maxTimeOnStateB functions
Now you know all about Yoctopuce USB relays. Have fun with them.