confused about power

Posted on
of 2
/ 2
  • I'm a purely software guy, I fart around w/hardware but this is the most complex thing I've ever done

    I have built a pico controlled power strip - I opened up a USB wall-wart and stuck it in the powerstrip and ran 5v up to the Pico - then I ran 3v back down to the power strip to toggle the relays (using a shift register chip.) The intermediate box uses an old 5v LCD I had from my Arduino days. The relays are powered via 5v and triggered w/3v. The final box is just a connector for switches. I figured out how to stack diodes so that I can handle 7 switches from 4 wires.

    problem #1 -- we call this thing the ouija-switch because turning other lights and/or tv's on/off in the room can make this thing turn outlets on/off, it's particularly bizzare to me because the LCD readout says that the relay has toggled. And of course it's getting driven by the Pico, so how can EMI (which it has to be) get up through the Pico out into the 3v world and make the software think I hit a switch?

    answer #1 -- a guy at work with an EE background says that I'm getting power fluctuations causing harmonics which are screwing up the works, and that they can run rampant all over the place. He gave me 5-6 solutions using terms I had no idea (shunts, capacitors, inductors, etc.) until the 7th -- power the Pico from a battery, if all your problems go away then you can think about cleaning the power to the Pico. (and have I read notes from people on other projects involving relays say things like: use a decoupling capacitor and liberally sprinkle capacitors around your circuit. Liberally Sprinkle ?? I have no idea what-all he was talking about)

    The Big Question -- if I throw a 9v battery into the middle box and connect that to the Pico then I will have 9v & 3v sharing the same ground, I used to have the 5v and 3v sharing the same ground. Is it alright to share the ground between 9v & 3v? Was the shared ground between 5v and 3v the source of my problems anyway? What should I do? I would rather not add a battery but rather fix whatever the original problem is that is causing the ouija-switch behaviors.

  • pretty pictures

    2 Attachments

    • PowerOne-Innards.png
    • PowerOne.png
  • You need to be a bit more specific about your hardware building blocks to answer your questions. For example: Pico drives a driver that drives the relays... but what is in between the Pico and the relays boards with 4 relays each?

    Decoupling capacitors are a good idea... but often it is not good enough... decoupling or actually have 'separate' power supplies for the different (types of building blocks) is a good idea. For example, want to have a very stable and clean power supply for your control electronics, such as the pico - and the chip sitting on the breadboard in the power strip. I assume it is a shift register or port expander to drive the 8 relays (it cannot be a ULD2003 driver, because this driver has only 7 outputs... leads me to the question: how many relays do you control? Last but least your cat cable from Pico to this 'mysterious' chip has only 8 leads, which allows you to control directly - or parallel - only 7 things, because one of these 8 MUST be the shared ground. This is a good segue way to talk about shared Ground: shared ground is the only way if you do not use opto coupling to have galvanic/electrically separate circuits. Shared Ground is a good starting point, no so good is shared power or insufficiently decoupled power supply. Next would be to look how you get the power from the black box to the strip for the 'mysterious' chip and the relays boards. If it is the cat as well, then you can drive 6 relays only... on the other hand, you may have extra leads for getting the power to the 'mysterious' chip and the relays boards.

    On a different note: Each relays consumes about 30mA... and that can bother your 'power world' too...

    Using batteries is a good test stepping stone to figuring out the problems... but the batteries do not last long... except you make them rechargeable and somehow recharge them. In that case, the act like large decoupling capacitors and smoothen out the power as well as buffer it for the peaks when you need more than the power supply can stably provide.

    First you start of with one relays and strip unpowered to test functionality. Assuming this works, you add the rest of relays and do some testing. With a Multimeter you can measure the relays contacts (if the relays boards do not have LED(s) on the board to show on or off status.

    For the power supply, you have to be sure that your power supply pushes enough power for all your devices... I see some additional 'things' in your 'black box'. If your power supply delivers 5 volts and is strong enough to run all things, you can create a decoupling: use a diode (Anode, not-ring side) from plus to (Cathode, ring-side) to PICO Bat and and a large capacitor of 1000uF from diode Cathode/Pico Bat to Ground, that stabilizes PICO board input power pretty well. You do even more and add a capacitor between Pico 3.3V and Ground. You can also have the latter capacitor... but it is a bit a stress on power up for the regulator if the capacitor is big. Both is for sure better.
    What the diode does is preventing back flow of power from circuit power buffered with capacitor from pico (if you put only the second capacitor - 3.3V to ground), the regulator works about the same way as the diode... but the 'farther away' from the actual MC you have stabilization, the better. Until you say what your 'mysterious' chip is, I cannot tell anything about how to power it... 3.3V from pico? 5V direct form power supply?...

    The relays board can usually have their own supply because they haven an open-collector kind of driver on them, which means, as soon as you put TTL-High minimum - 2 Volts - on the input, the switch this alternate power to the relays coil and do the on switch, the a bit more than 2V is better, but not more than power supply voltage of the driver). Btw, TTL-LOW is max 0.8 Volts. The minimum of 1.2 Volts difference is to prevent noise from switching... Some drivers need less to switch on but are then also more susceptive to noise. To all that sharded ground applies.

    Take my comments with pinches of salt... I spent the majority of my time in software as well... btw, would be interested to see some of your control software published here...

  • To drive relay coils, most circuits use a diode across (in parallel with) the coil pointed so that current doesn't flow when power is applied to the relay coil. When the power is removed from the relay coil the diode suppresses the inductive kick from the coil. Some example diagrams:­trl.htm

  • Hi, that looks like a really nicely built project!

    From what I can see, you're using relay modules which have all the drive electronics inside. The only gotcha I've found with those is that often they have pullup resistors that pull the inputs up to whatever voltage you're powering them from (in this case 5v). But because you're using a shift register (which I guess is also running off 5v) you should be fine.

    How is the Pico being controlled? Is it from the switches in the final box? It might be that the long wire to the end box is actually picking up noise caused by the spark from the relays (I've had this happen).

    There are some things that might help:

    • Try a much shorter black cable to the white box. You could also try finding/making a cable that has a ferrite in it (that chunky bit of plastic a few inches from the end).
    • If you have pullup resistors in the final white box, lower their values. Something like 1k is probably beefy enough. You could also put small capacitors across the wires in the box with the Pico.
    • To properly isolate the Pico from the mains, you could add an opto-isolator chip inside the adaptor. Since you won't have many wires to the shift register, it should be pretty easy to do - and then you don't have to share GND at all.
    • Other thing is to find blocks of 'solid state relays' - they're available in a similar form to the relay modules you have, but because they are semiconductors you don't get the spark when they open and close, which means less noise.

    But yes: Sharing GND between different voltages should be fine - I'm not sure you'll notice much of a difference when powering from a battery though.

  • Gordon: I have lots of old USB cables with ferrites on them, if I clip one of those onto the black cable which end should it go near ?

    AllObjects: I powered the shift register with 3v -- should I switch that to 5v ?

    AllObjects: I am interested in the 'decoupling' could you please re-state it more concretely ?

    Here are more pictures, a better description, a parts inventory, and the code I used


    12 Attachments

  • I'd stick the ferrite on the end nearest the Pico. I can't promise anything but it's worth a try...

    I have a really similar setup for my bathroom lights (4 relays of that type, and then a 1M long wire that goes to the light pull) and I was amazed at the amount of noise it received when using the internal 40kOhm pullup resistors - I had to move to much lower values to get it to work reliably and not turn on and off all the time :)

    I'd definitely power the shift register from 5v - that should help a lot too. The way the relays usually are (pull down to turn on) it means that if you power them from 5v but feed them with a 3.3v signal, the drivers are 'half on' all the time, because 3.3v is still less than the 5v they're expecting to be turned off.

  • Ok, everything is 5v now and I rewrote the switches.js to behave a little better when I hook up multiple switches in the future -- thanks!

    I'm still interested this talk of decoupling and capacitors -- but I don't really know where to put them exactly, or what strength to use...

    And I found a ferrite tube and some ferrite rings, so I can thread the cable thru the tube and re-crimp the end -- but I can also thread individual wires inside the control box. Suggestions?

    I'll report back as to any reduction (or otherwise) in ouija activity

    (update) I found some clamp on ferrites in my pile of servo stuff !! So I've clamped both the cables after they come into the pico Box -- I have two more of these as well as the rings, what else should I apply them to?

    The wires that go to the relays are too thick for these, but I could pass them thru a few rings (not long enough to twine around rings unless I replace.)

    Oh, and I took the pico off the board and tipped it up so you can see the female header on the pico and the male header on the board -- make sit easy to swap in a pico with updated code.

    And, I love having female header on the pico so that I can just use it as it's own mini breadboard for testing code. (A big THANKS goes out to allObjects for that idea !!­276831/ )

    2 Attachments

  • Thanks for the details.

    As @Gordon says, shift register (74164) be powered with 5V, as well as the relays board. Just feed it from there. Pico output to the shift register inputs is well in specs with MC 3.3V output. Just cap the 3.3V power from pico to shift register and connect it to power from the relays board.

    Looks like the USB charger that you use as power supply / source is strong enough to run all your equipment. 'Amazon/vendor says': 1500mA... which most likely is what they say.

    To decouple and stabilize the power for Pico, do not directly connect the 5V from power supply to Batt: put a diode in between and then put a capacitor between Batt and GND.

    I took a look at the SW. What I like is the modularization.

    Looking at the individual components, I see some challenges in the dynamics and stability / predictability in the cooperation with the hardware. Surprise to me is that no debounce works the best and that the spi write is in a timeout, which means that control continues immediately.

    Could you elaborate a bit more on the implementation of your 'keyboard'/switches schema?

    1 Attachment

    • poweringPowerStripControl.png
  • That looks great! I'd say that's all you need with the ferrites - I wouldn't worry about the mains wires, it's more to try and combat interference caused by sparks in the relays themselves.

    Hope it works better now!

  • No real improvement in ouija action... More reaction to relays I think...

    I want to do the decoupling thing now, I can figure out where to put the cap & diode thanks to aO's diagram -- and I have these caps but don't know which ones to use­alue-Capacitor-Pack/dp/B00CQOM1IC

    aO: the switches code has been rewritten to be much clearer about it's intent. It's working a lot better now. I've attached the latest copy, I meant to upload it last night with the update to the control.js file (see reply #8)

    1 Attachment

  • Ok, so now everything is 5v (except for the clock/data lines to the shift register) -- I have a 100uF cap - will that do? I'm ordering a set with 1000's in it. How do you know how big to use? What's a good ref for a total newbie (who's bad at math) for this kind of stuff? if I wanted to order optoisolators what kind would I order?

  • Hold your breath buying more hardware. If switching the power for the shift register from 3.3V to 5V (and the decoupling with diode and a 100uF (or a few in parallel)) do not calm down the relays from jittering, the problem (dog) lays (buried) somewhere else.

    When I asked about the switches, I was thinking of the schema, how the diodes and switches are matrix wired. With three lines you are able to catch 8 states, where as the state 0 is the 'unusable all-off' state, leaving seven (7) different watch-detectable states. There may be some 'trickery; to work with less then the twelve (12) diodes I would need to reliably do it (with momentary-on SPST - Single Pole Single Throw - switches in mind vs momentary-on SPDT - Single Pole Double Throw - switches; with the latter ones you may get away with less diodes by using both on states... but Espruino is so fast that it detects the none-on when the switch switches, and with the diode setup it may trigger erroneously on top of the multi triggers by the multiple watches....).

    Furthermore, on all three input lines you have a watch... depending your circuitry and the expected switch value more than one fire and may create your jitter... Multiple get serialized and then are processed one after the other in JS 'tasks' (callbacks). Therefore, after one triggered, you clear all watches, 'wait' some time and ignore any others that do trigger, then read the lines, do the work, set the watches for the going off, do the same finicky things for the off as you did for the on, and then set the watches for 'on's again for the next cycle...

    Attached 'my' schema I was thinking of to check for seven (7) switches.

    And here the (partially tested) code:

    var switches =
    { callback: function(v){}
    , enabled: true
    , repeat: true
    , _pins: []
    , _watches: []
    , _rdy: false
    , setup: function( // setup with pins, callback w/ binary value by default and enabled
            pins       // array of pins [msb..lsb] (weight ...,4,2,1)
          , callback   // callback(value) - value binary value or bit list
          , asValue    // optional - true(default): callback w/ binary value, false: w/ bit list
          , enabled    // optional - true(default), false: disabled
          , repeat     // optional - true(default), false: disables switches on switch on event
          , debounce   // optional - undefined(default): 50ms
          ) {
        this._rdy = this.enabled = false;
        var _debounce = ((typeof debounce !== "undefined") && (debounce >= 0)) ? debounce : 50;
        this.repeat = (repeat !== false);
        this.enabled = (enabled !== false);
        this.asValue = (asValue !== false);
        this.callback = callback;
        this._pins = pins;
        this._rdy = this.enabled;
    , _hold: function() {
        if (this._rdy) {
          this._rdy = false;
          setTimeout(this._callback.bind(this), 10);
      } } 
    , _callback: function() {
        var val =;
        if (val) { // something detected
           setTimeout(this.callback, 10, val);
           this.enabled = (this.repeat) ? this.enabled : false;
        this._rdy = this.enabled;
    , prep: function() {
        while (this._watches.length > 0) { clearWatch(this._watches.pop()); }
        this._pins.forEach(function(p) {
                , { repeat: true, edge: "raising", debounce: _debounce }));
          }, this);
    , read: function() { // can be used anytime to read switches
        var val = 0; 
        this._pins.forEach(function(p) { val = (val << 1) + dititalRead(p); });
        if (val) { val = (this.asValue) ? val : 1 << (val - 1); }
        return val;
    , enable: function(enabled) { 
        this.enabled = (enabled !== false);
        this._rdy = this.enabled;
    switches.setup([B15,B14,B14],function(va­l){ console.log("switch " + val); });
    The ```watches[]``` holds on the the ```watch_ids``` returned by ```setWatch()``` in order to be able to clear them with ```clearWatch()``` for repeatable use of ```set()``` in one run session. For a nested 'UI', the callback can be changed with ```switches.callback = function(value) {....``` to cater to different menu-levels/contexts. When considering this it is advised to use ```rapeat``` option set to ```false``` to avoid 'logic jitters'.

    asValueoption allows you to control the value in the callback as well as with theread(_function.asValuewithtruegives you the values1..7, where as withfalsethe values are1,2,4,8,16, 32, 64, alternatively represented as0b00000001,0b00000010, 0b00000100,... 0b01000000```, which represent a bit lis, andtis the format you need for the shift register...

    Since you may need the value as an index for all kinds of things - especially with the display - use the default value and build the bit list just when you need to send the value to the shift register. The conversion is really easy: 1 << (value - 1) creates the bit list from the value.

    There are other solutions, but with three (3) lines you get only six (6) switches, and with four (4) lines you get twelve (12) switches (needs only six (6) diodes). If you can spare six (6) lines, you can detect nine (9) switches without any diode.

    1 Attachment

    • switches7w4.png
  • All of this is to set up some switches for my mom who is bedridden and has little use of only her left hand -- the coiled wire runs from the wall to the rolling beside table (keeping itself off the floor) so I am limited to 4 wires. Your diagram perfectly explains my diode arrangement.

    I've not done the decoupling and diode yet - I was waiting to see if I had to have a 1000uf as you had first suggested. I'll try with the 100uf.

    The problem is not so much jittering (not staying put once set) but rather that outside power use affects the system. She has an electric hospital bed and when we run it down, that can cause the circuit to switch off the light -- it seems to me that it's not just affecting the shift register or the relays at that point, because the lcd says the switch is off.

    Will it be all right to decouple the circuit more than once? I'd like to decouple it for the shift register as well as at the pico.

    thanks for that extra code, I'll let you know how it works if I try it.

  • I'd suggest that you put 3x 0.1uF capacitors (anywhere near that) between PV1/2/4 and GND in the box with the Pico, and that you use very low value pull-down resistors (300 Ohm-ish).

    What are you using as pull-down resistors currently? I don't see anything in your circuit?

    If you're not using any, that would almost certainly be your problem :)

  • As @Gordon points out, the pull-down has to be strong enough to keep noise in check. The Espruino built in pull-downs are pretty weak - only 30..40k. The limitation to 4 wires is not an issue, because the additional pull-down resistors are anyway best placed close to the watched input pins.

    Since you run everything outlet powered anyway, you can have an interval triggered update of your peripherals. Having the controlling Espruino power decoupled / stabilized is good enough. Using the same (simple) decoupling technique for the shift register does not really work, because the shift register requires 4.75V minimum according to datasheet, and a regular Si diode has typically a 0.7V drop leaving only about 4.3V to the shift register. Some Ge diodes have a lesser drop - about 0.2V - but it is not a typical application. You can use a MOSFET which gives you better results (same concept as Espruino uses on the board when powered by battery: see PICO Reference, POWER, AND THE FET/B0 JUMPER).

    Before going there, work on making the switching robust. The extra pull-down will for sure increase the noise resistance. You may start with just one diode and one pin and one switch and a pot in series with the current limiting fixed resistor and find optimal working point.

  • On a different notice: measure the resistance across bothth jack connectors and spiral phone cable... may be there is something fishy... or went somehow wrong when working / crimping on it.

    Sometimes it is a simple electro-mechanical issue... like forgetting to put the plug into the wall outlet... ;-)

  • ok, most of that has left me in the dust...

    I have and can do: 100uf & diode decoupling for pico, 330Ohm resistors on the switch pins. I have .1uf caps, but I don't know if gordon means 3x per line?

    I should have time this weekend to solder on this

    thanks guys!

  • Also - what is FET ? Is that MOSFET ?

    I need something that will let me turn on conductivity between two wires -- these look ideal but I can't find the one they say is good (3v version) for sale anywhere


  • 100nF caps go parallel with 330R resistors (see updated schema; updated also previous posts).

    Btw, since Espruino PICO's inputs are 5V tolerant, you can also feed the switches box with 5V - which increases noise immunity.

    Feeding 5V gives you an option for a nice UX touch: put an LED into the switch line for each switch: it will light up when the related switch is pressed!

  • Well I'm glad your diagram showed the resistors going to ground, I was going to put them inline

    I had to substitute 0.1uF polarized for your unpolarized 100nF (I love google)

    --- Do you have a suggestion for something that I can use to create continuity between two wires, without introducing any current into them ---

    1 Attachment

    • Screen Shot 2016-06-04 at 6.00.14 PM.png
  • The other caps arrived without the 1000uF's (with 2200, 3300 & 4700uF's)

    Is it a problem that my wires from the switch boxes are "closer" to the pico than the Caps & R's ?

    It's getting time to completely redo this board...

  • What you've done with the caps + resistors looks perfect. I have to say with 330 ohm pull-downs it should be really solid... I'd be amazed if it accidentally triggered.

  • At this point - 48hrs in - the only ouija activity has been internal to the powerstrip. Twice so far I've heard relays click with nothing but EMI to cause it. I'll be decoupling the 5v power next - then re-doing the boards && then publishing it in the projects section.

    I am looking for some way to induce conductivity between two wires - FET/MOSFET look good but I can't find the 3.3v ones mentioned in the tut.

  • The MOSFETs mentioned in the tutorial ( IRF3708PBF ) are available from digikey and mouser, and probably any similar electronics supplier. Not available from "hobby vendors" and ebay.

    If you're able to do SMD work, there are hundreds of amazing transistors with specs that boggle the mind. Through-hole options are extremely limited if you need gate voltage of less than 4.5v, unfortunately.

    To address this shortage of through-hole MOSFETs that work with low gate voltages, I sell low-voltage logic level MOSFETs mounted on breakout boards to make SMD MOSFETs usable to people who prefer not to work with SMD parts - (4-channel ones big and bigger, and SOT-23 ones for ligher duty by the six-pack - prices start at $3/6pk for the SOT-23, and $12/14 for the 4-channel ones) . Some models are available with several different types of FETs mounted on them, at different prices (see product page)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

confused about power

Posted by Avatar for user58511 @user58511