Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 19 of 19

Thread: ...is the teensy the right choice for me (how to switch high current AC load safely)

  1. #1
    Junior Member
    Join Date
    Mar 2017
    Posts
    8

    ...is the teensy the right choice for me (how to switch high current AC load safely)

    Hello folks,

    new member and first post here, so please be kind

    I'd appreciate your comments and guidance on my project and whether the teensy (v3.6) is the right choice for me and how to solve a particular problem switching on a high current AC load safely.

    To start with, I am a total newbie to DIY electronics, but I know how to code and have a fair level of architectural thinking (owning a degree in engineering, I know a bit of everything, I suppose) but here my knowledge is very limited as are my soldering skills.

    My project is to replace a programmable thermostat for my hot water boiler, as the original just went dark and there is no replacement on the market with the features required.
    This is what I have in mind for my solution ATM:
    • driving 1 or more temperature sensors/probes
      I am looking into 1wire DS18B20 sensors
    • using a convenient input/output method, thus securing the WAF
      I am looking into employing an I2C based, pre-assembled kit with LCD and keypad from here: http://byvac.com/index.php/BV4612
      This will fit / can be mounted on a standard box.
      In that shop, there will be a new product available in a couple of weeks, using a rotary knob for all the input, which is the most convenient way of I/O for my use-case, i think.
    • driving a relais (230V/AC, 10-16A) to remotely switch power to the boilers heating element, which is a small heat pump and this is what makes it more complicated
      Most common relais boards I found are like this: https://www.amazon.com/SunFounder-Ch...relay+board+5v
    • employing a micro-controller that is
      • easy to code, with a plug&play IDE (arduino sketch style or C)
      • upgradable with wifi to integrate into a smart home environment (i.e. using IP based transport with MQTT)
        OK, this will be a real new feature after everything else is up&running
      • can be integrated safely with the relais / remote switch from above
      • has enough headroom for the (fairly) complex program, that needs to self adjust to the heating curve of the HP in order to optimize run-time of the HP and supply the desired water temp at the programmed time of day.


    While I think the teensy has the headroom for the complex programming, I am worried of driving the relais or using one of these cheap relais boards at all.
    First, the teensy 3.6 only supplies 3.3V to its output pins, while the common boards run at 5V or even higher.
    I learned, that one needs to use an extra small transistor/diode setup in order to drive the relais with the appropriate 5V and prevent higher voltage to run back to the controller pins when the relais is active
    Second, all the relais boards I found, are so small that I think these are build electrically incorrect, meaning they don't keep the correct safety distance between the lines, carrying 230V(AC) load and 5V(DC) switching power.
    So i came to the conclusion, that I'd rather not risk a fire in my (wooden) home with one these.

    Nailing the problem down to safely driving the Heat-Pump with the 3.3V output pins from the teensy is what my problem seems to be ATM.
    There are other professional (and safe) switches out there, that can be driven by 8-230V UC (like this: http://www.eltako.com/fileadmin/down...00301-1_gb.pdf) but these need +10VDC control power (and possibly will draw more current than the teensy can supply anyway).

    As said before, any comments on my solution setup in general, with a teensy 3.6 and on how to solve the challenge to switch the high current AC load safely is very much appreciated.

    Many thanks in advance for your time & efforts.

    greetz,
    Hominidae

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,500
    That Sunfouder relay board looks a little suspicious for use with 230V. While it does have both relay and optocouplers, the PCB traces run underneath the optocouplers, close to both sides. Not a good design.

  3. #3
    Junior Member
    Join Date
    Mar 2017
    Posts
    8
    Paul, thanks for the fast reply.

    Yes, that is the one flaw what I found and read across the net.
    Almost all of these boards appear to have the same design, regardless of brand.
    I found the input from here quite informative, although it does not solve my problem in choosing the right relay solution in conjunction with a teensy, http://www.forward.com.au/pfod/HomeA...lay/index.html

    I also found these relay boards, and from the docs they are supplying (they do supply documentation with all their products, not a common behavior these days), it appears they know what the are doing: http://numato.com/products/relay-mod...eatured&page=1

    I'd prefer this one, but don't know if one could be driven with a teensy: http://numato.com/1-channel-relay-breakout-30a

  4. #4
    Senior Member Ben's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    401
    Quote Originally Posted by PaulStoffregen View Post
    That Sunfouder relay board looks a little suspicious for use with 230V. While it does have both relay and optocouplers, the PCB traces run underneath the optocouplers, close to both sides. Not a good design.
    I don't understand why they use optocouplers at all, the relay alone should provide enough isolation in itself

    A solid state relay (SSR) might be the quickest and least error-prone way. The SSR might require a heatsink, depending on the load current, but the advantage is you can control it directly with a teensy pin, they accept control voltages as low as 3V. You could even monitor the relay temperature since you are employing a 1Wire-Bus for the DS18B20 anyway

    https://www.sparkfun.com/products/13015 <-- example that might fit your application

  5. #5
    Senior Member
    Join Date
    Jan 2013
    Posts
    843
    Quote Originally Posted by Ben View Post
    [...]but the advantage is you can control it directly with a teensy pin, they accept control voltages as low as 3V.[...]

    https://www.sparkfun.com/products/13015 <-- example that might fit your application
    Are you sure that the Teensy can drive that directly? 3.3V is not much more than the 3V minimum and they mention 7.5mA / 12V trigger current.

    \\

    Is the heater sufficiently fail-safe? Would bad things happen if there was a bug / hardware failure and it is turned on continuously (e.g. water starts boiling, you get a pressure build-up)?

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,276
    you could use a logic level mosfet to drive a higher voltage, i use tons of them fine, ex you could use the teensy 3.3v to trigger a n-mosfet to drain source GND to the relay while a 5v is wired directly to the relay

  7. #7
    Junior Member
    Join Date
    Mar 2017
    Posts
    8
    Quote Originally Posted by tni View Post
    Is the heater sufficiently fail-safe? Would bad things happen if there was a bug / hardware failure and it is turned on continuously (e.g. water starts boiling, you get a pressure build-up)?
    Yes, it is.
    The "heating element" is a small heat pump, loading a 200litre boiler...during the past 10yrs it did produce 12.000kwh of heat out of 2.000kwh of electricity each and every year, which is pretty good.
    Being a heat-pump, there is no possibility it can overload the boiler to the temp of boiling water.

  8. #8
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    330
    I've used both relay boards and SSRs and I prefer the latter. The teensy can drive it directly.

  9. #9
    Junior Member
    Join Date
    Mar 2017
    Posts
    8
    Quote Originally Posted by Ben View Post
    A solid state relay (SSR) might be the quickest and least error-prone way. The SSR might require a heatsink, depending on the load current, but the advantage is you can control it directly with a teensy pin, they accept control voltages as low as 3V. You could even monitor the relay temperature since you are employing a 1Wire-Bus for the DS18B20 anyway

    https://www.sparkfun.com/products/13015 <-- example that might fit your application
    OK, thanks.
    This is not a bad idea.
    In fact, I believe the HP setup already has something like this in place, as it has same relays - including timer based ones - to make the HP setup failsafe...all it takes is a switch (but i currently do not know if this is AC/DC based and what current it will need to switch).
    I could ask my electrician/engineer to supply me with a set-up where I only need to apply a DC based current to switch on the HP.
    Whether this is by means of an SSR or another device, I'd leave up to the expert

    Quote Originally Posted by tonton81 View Post
    you could use a logic level mosfet to drive a higher voltage, i use tons of them fine, ex you could use the teensy 3.3v to trigger a n-mosfet to drain source GND to the relay while a 5v is wired directly to the relay
    Yes, hmmm...is this something like a step-up power-supply? Will it not drain to much power from the teensy?
    The setup will need to work with the HP "ON" when the pin is on "High"...if the microcontroller fails or is not connected, the HP should be in OFF state.

    Quote Originally Posted by jonr View Post
    I've used both relay boards and SSRs and I prefer the latter. The teensy can drive it directly.
    OK, thanks for the confirmation jonr. I'd gather there is some tolerance with the SSRs and some might not work, even when the setup is within specs of the datasheet.
    Something like tonton81 suggested would allow me to have some headroom and adding to the failsafe bill, wouldn't it?

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,500
    If you go with a SSR, look for one with zero cross switching.

  11. #11
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,276
    Quote Originally Posted by hominidae View Post
    Yes, hmmm...is this something like a step-up power-supply? Will it not drain to much power from the teensy?
    The setup will need to work with the HP "ON" when the pin is on "High"...if the microcontroller fails or is not connected, the HP should be in OFF state.
    if the teensy fails (turns off/loses power) mosfet will release automatically, switching off
    if however, teensy freezes, or something in your code prevents your loop from running while the output is enabled, well, i dont see how you can have a failsafe at that point unless you enable a watchdog timeout for issues like that, ex. a watchdog timeout reboot if there is a lockup will reload all pinstates thus switching the relay back off

    Tony

  12. #12
    Senior Member Ben's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    401
    Quote Originally Posted by tonton81 View Post
    if the teensy fails (turns off/loses power) mosfet will release automatically, switching off
    if however, teensy freezes, or something in your code prevents your loop from running while the output is enabled, well, i dont see how you can have a failsafe at that point unless you enable a watchdog timeout for issues like that, ex. a watchdog timeout reboot if there is a lockup will reload all pinstates thus switching the relay back off

    Tony
    If the Teensy sets the mosfet control pin into high impedance state "by accident", the gate charge can be retained on the mosfet gate for quite some time, it's best to have a resistor from the gate to ground, anything between 10k and 1meg will do.
    But Tony is still right, Teensy could fail in a way that makes the pin stuck in high state. IIRC Teensies do have a watchdog, and it might be an excellent idea to use one in this application, but I don't know how.

  13. #13
    Junior Member
    Join Date
    Mar 2017
    Posts
    8
    Quote Originally Posted by PaulStoffregen View Post
    If you go with a SSR, look for one with zero cross switching.
    OK, understood...will do...the one linked by Ben actually has that characteristic.
    The manufacturers datasheet can be found here: https://cdn.sparkfun.com/datasheets/...al/SSR40DA.pdf
    Page two shows some interesting "application hints", apparently on how to connect when desiring NO or NC connection states, using NPN or PNP transistors.

    Quote Originally Posted by tonton81 View Post
    if the teensy fails (turns off/loses power) mosfet will release automatically, switching off
    if however, teensy freezes, or something in your code prevents your loop from running while the output is enabled, well, i dont see how you can have a failsafe at that point unless you enable a watchdog timeout for issues like that, ex. a watchdog timeout reboot if there is a lockup will reload all pinstates thus switching the relay back off
    Quote Originally Posted by Ben View Post
    If the Teensy sets the mosfet control pin into high impedance state "by accident", the gate charge can be retained on the mosfet gate for quite some time, it's best to have a resistor from the gate to ground, anything between 10k and 1meg will do.
    But Tony is still right, Teensy could fail in a way that makes the pin stuck in high state. IIRC Teensies do have a watchdog, and it might be an excellent idea to use one in this application, but I don't know how.
    OK, I understand that, but this not my highest priority ATM. The HP is failsafe. A fail will either just add to the energy bill by heating the boiler less efficient or not at all (triggering the WAF score to go down rapidly).

    I still do not understand on how to wire that thing.
    As I am still inclined to use more than 3.3V for the switching voltage to the SSR, I need to build that small amplifying circuit with two resitors, NPN transistor or FET.
    As the teensy, the amplifying circuit and the power supply (providing 5V to the amplifying circuit and 3.3V to the teensy) all seem to share the same GND connection, I am wondering if this is safe in terms of preventing to much current to be drawn from the teensy or sending 5V down the pin towards the teensy.
    As said, I have no real stake in electronics
    BTW: this seems to be a popular problem in the world of the RPi (I don't own one, so bare with me), see: https://www.raspberrypi.org/forums/v...ic.php?t=36225

  14. #14
    Senior Member Ben's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    401
    Quote Originally Posted by hominidae View Post
    OK, understood...will do...the one linked by Ben actually has that characteristic.
    The manufacturers datasheet can be found here: https://cdn.sparkfun.com/datasheets/...al/SSR40DA.pdf
    Page two shows some interesting "application hints", apparently on how to connect when desiring NO or NC connection states, using NPN or PNP transistors.
    I still do not understand on how to wire that thing.
    As I am still inclined to use more than 3.3V for the switching voltage to the SSR, I need to build that small amplifying circuit with two resitors, NPN transistor or FET.
    The datasheet "hints" are a good start. Look at the upper left diagram, the one with "Input NPN Output NO". You'll want to use this one. Virtually any npn-transistor will do, as the currents and voltages involved are very low. For example BC337 is common and easy to obtain in Europe. You can see two resistors in the schematic, one at the base of the transistor, with an open connection to the left, and one at the collector, hooked up to V+ (5V in your case). You can use 10kOhm for both. the base resistors floating end is where you connect the teensy pin.

    Quote Originally Posted by hominidae View Post
    As the teensy, the amplifying circuit and the power supply (providing 5V to the amplifying circuit and 3.3V to the teensy) all seem to share the same GND connection, I am wondering if this is safe in terms of preventing to much current to be drawn from the teensy or sending 5V down the pin towards the teensy.
    As said, I have no real stake in electronics
    Yes, this is safe (if wired up correctly)

  15. #15
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,915
    Re your choices Pi would do this job as an all in one, and be easy enough to program - number of more or less dedicated bits of code around but one to look at is 'node red' and see if that suits your mental model.

    Potential problems are that it's relatively power hungry for 24/7 use, and there are a whole bunch of potential failure modes since it is after all a fully fledged computer. Depending on your code background you may find it easy to work with or very annoying.

    Other options are an ESP based wifi chip, which would be harder to program and not something I'd want driving anything mission critical.

    Or you can do what you came here for in the first place and look at a Teensyish solution and add a Pi or ESP wifi solution later. I'd be tempted to go with a bare banes and basic micro for the actual controller and bridge it to your chosen wifi/network solution seperatly. This gets you going faster (reading above I think you have no heating at the moment?) and means loss of wifi just drops the remote control not the whole system (and your core controller can be wired to reset it if network weirdness happens. If I'm understanding your needs the actual control could be pretty much anything, including a classic Uno. All Arduino can do floating point math for PID controller curves at speeds faster than a boiler is going to need. Going the teensy route I'd be suggesting a 3.2, largely because it's got the greatest 'just works' potential if you grab a random library.

    If you have the cash and are short on build time you may find it worth grabing a classic Uno and relay and sensor shields for flavour. Not with the intention of using them in the final build but because they will give you lots of design and coding examples where the Teensy has a bit of a learning bump at the getting your first sensor and relay wired if you haven't breadboarded/soldered much, and gives you a code test bed. Depends if sinking ~$200 on learning seems like good value.

  16. #16
    Junior Member
    Join Date
    Mar 2017
    Posts
    8
    Quote Originally Posted by Ben View Post
    The datasheet "hints" are a good start. Look at the upper left diagram, the one with "Input NPN Output NO". You'll want to use this one. Virtually any npn-transistor will do, as the currents and voltages involved are very low. For example BC337 is common and easy to obtain in Europe. You can see two resistors in the schematic, one at the base of the transistor, with an open connection to the left, and one at the collector, hooked up to V+ (5V in your case). You can use 10kOhm for both. the base resistors floating end is where you connect the teensy pin.


    Yes, this is safe (if wired up correctly)
    ...perfect, thanks Ben!

  17. #17
    Junior Member
    Join Date
    Mar 2017
    Posts
    8
    Quote Originally Posted by GremlinWrangler View Post
    Re your choices Pi would do this job as an all in one, and be easy enough to program - number of more or less dedicated bits of code around but one to look at is 'node red' and see if that suits your mental model.

    Potential problems are that it's relatively power hungry for 24/7 use, and there are a whole bunch of potential failure modes since it is after all a fully fledged computer. Depending on your code background you may find it easy to work with or very annoying.

    Other options are an ESP based wifi chip, which would be harder to program and not something I'd want driving anything mission critical.

    Or you can do what you came here for in the first place and look at a Teensyish solution and add a Pi or ESP wifi solution later.
    The latter is my route, I think.
    I want a fairly simple solution that will not depend on availability of network or anything else, besides power....adding smart home based features with a real computer (with an OS) later.
    I used to program quite complex solutions in different languages (mostly C, TCL, perl, and some uncommon languages, like occam on systems that had up to several thousand processors on different variants, *nix style or even bare metal with no OS) in the (very) past, but have no experience with microcontrollers as such.
    But I will definitely look into the "node red" example you mentioned....I did not use a rpi but have some odroids sitting available atm.

    I'd be tempted to go with a bare banes and basic micro for the actual controller and bridge it to your chosen wifi/network solution seperatly. This gets you going faster (reading above I think you have no heating at the moment?) and means loss of wifi just drops the remote control not the whole system (and your core controller can be wired to reset it if network weirdness happens.
    Yup, that sounds feasible.
    The heating has been fixed but the actual controller deployed as a replacement is too simple, just acting on a simple hysteresis ... this is actually wasting energy and cannot make sure that the water is heated up to the point what the family needs to a specific time.
    The "original" was one that is normally used for floor tile heating, but had the higher temp-range for a fresh water boiler (including temps above 70degC for the anti-legionella bacteria scheme), a larger hysteresis and a self learning ability to turn the HP on in advance, early enough so the temp would have been reached at the desired time.
    This model has gone extinct and new brands and models to not have these abilities.

    If I'm understanding your needs the actual control could be pretty much anything, including a classic Uno. All Arduino can do floating point math for PID controller curves at speeds faster than a boiler is going to need. Going the teensy route I'd be suggesting a 3.2, largely because it's got the greatest 'just works' potential if you grab a random library.
    OK, good point. My first thoughts have gone into that direction as well...but then I thought, that I need to add a display and keypad, including the need to produce code for "usability".
    As I am not that experienced, I thought a teensy, with a lot more resources than an UNO would save me from "low RAM, low FLASH, or else" race conditions if my code would not be made perfect, simple enough and resource savvy.

    If you have the cash and are short on build time you may find it worth grabing a classic Uno and relay and sensor shields for flavour. Not with the intention of using them in the final build but because they will give you lots of design and coding examples where the Teensy has a bit of a learning bump at the getting your first sensor and relay wired if you haven't breadboarded/soldered much, and gives you a code test bed. Depends if sinking ~$200 on learning seems like good value.
    That is actually a very god idea and I was thinking the same thing lately. Thanks for confirming that!

  18. #18
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,915
    Re Uno vs Teensy 3.2 both will run a boiler, a display and a keypad fine but yes the 3.2 will give you a enough elbow room that you shouldn't touch the edges where Uno would most likely trap you at least once with some form of strange resource issue. So plan of 'scratch test uno and deliverable' on Teensy works.

    Be aware that Teensy is 3.3V logic and Uno is 5V, so just connecting Uno hardware to a teensy 3.2* works most of the time, but the cases it doesn't can be head scratchers.

    * teensy 3.2 can handle 5V in, Teensy LC and 3.6 cannot
    Last edited by GremlinWrangler; 03-07-2017 at 08:46 AM.

  19. #19
    Junior Member
    Join Date
    Mar 2017
    Posts
    8
    Thanks @GremlinWrangler for these hints.
    I think I will do my scratch development with a MEGA 2560 (Re elbow room) and focus on the algorithm and core functions first, then move to UserControl.
    The settings for the Boiler once they are set, do not need adjustment every day.
    First extras will be a party switch and second a vacation setting/switch.
    Adjusting the day-to-day programming and target temps is the least important, as these will only need to change when there is a change in the family's schedule.
    Might as well make these configurable/static in the code and edit/deploy a new sketch as intermediate solution if need be.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •