Updated high voltage output stage for my Es(pi)resso Machine (muhahaha…)

Here are the latest plans for the high voltage side of my Es(pi)resso machine controller. Obligatory warning: working with mains voltages as shown in this circuit is potentially very dangerous – use this circuit at your own risk.

Click to embiggen (to promulgate a neologism):


This diagram is a slight refinement of the circuit currently inside my machine. Basically, I’ve added a TC426 to drive the IGBT for improved switching times (replacing the BC556 used previously), and replaced the opto-couplers with the 4 pin HCPL-817 for reduced board area and pin count. This also leaves one spare TC426 output for future expansion, which I plan to expose on a 0.1″ header. Otherwise the circuit is exactly the same as the current working version in my Gaggia Classic.

The OC1 coupler enables the Pi to detect when the pump is powered on. As soon as mains power is applied to the pump, this open-collector output goes low. This makes it easy for the software to know when a shot is being pulled, and to count shots etc.

There are two SSRs in the circuit: K4 is used to switch the boiler elements, and K3 is used to switch power to the pump. The pump can still be manually controlled with the brew switch. When the pump SSR K3 is on, this also powers up the pump modulation circuit. The PUMP_PWM input is a 3V3 logic level PWM input for the pump. This goes through opto-coupler OC2 and the TC426 via 1K gate resistor to switch the IGBT Q3. It’s arranged so that a logic high on PUMP_PWM will switch on the pump. Therefore, PUMP_OUT and PUMP_PWM together can be used to automatically power the pump on/off, and to modulate the pump pressure via PWM (I’m currently working with 1kHz PWM frequency).

Today I carried out a low voltage test of a subset of this amended design (the HCPL-817, TC426 and IGBT), and it performs well. The next stage is to test this at mains voltage with the pump, and then I’m planning to design a custom PCB to replace the current strip-board used inside the machine.


45 thoughts on “Updated high voltage output stage for my Es(pi)resso Machine (muhahaha…)”

    1. I think the ‘scope was connected to the IGBT gate when I took that photo. The IGBT switches a little slower, but still quite respectable. It may be at the limit of measurement for the little DSO Nano, but I’ll see if I can get a decent trace from the IGBT collector on my bigger ‘scope.

    1. Hi Philippe

      Yes, certainly: D7 is to avoid the risk of Q3 being damaged by current flowing in reverse through Q3 and D6 on the negative AC cycle. This is because we’ve added the snubber diode D6 (which would create a reverse path for the AC through Q3). On the positive half of the AC waveform, current flows from LIVE through PUMP1 then D7 then Q3 back to NEUTRAL. On the negative half of the AC waveform, current is blocked by D7. Without it, current could flow from NEUTRAL through Q3 and D6 back to LIVE. I guess Q3 would explode and release the magic smoke (I once destroyed an SSR in a similar way).

      Hope this helps? Happy to discuss further, and help if I can. I’m still looking to improve the snubber circuit to improve the solenoid switching times (currently this is a simple diode D6).

      Best regards

      1. Your detailed response is much appreciated πŸ™‚ It contributes to my learning experience.

        I’ve used your work (electronics and code) as my template up to this point I got:
        – flow-meter
        – PID temperature control
        – brew control via SSR

        I’ve run successful test circuits (breadboard) of your IGBT based pressure control, which I will solder together into my board as a next step. I’m still waiting on some cheap Ebay datasheet-less Chinese analog pressure sensors to arrive, so I’ll do the pressure profiling before I get the pressure meter in.

        I’m honestly a bit worried about the AC/DC interface on your IGBT circuit, and I am not quite sure I understand what the implications are of having AC N and DC GND connected together, but hey…

        As an additional note, I’m using an MBED LPC1768. It has a slightly easier to use web-based IDE and has analog inputs with internal pullup/pulldown resistors and hw based PWM, so makes for less circuitry. As an example, I was able to connect the flow meter directly into a digital input pin with a pullup and it worked fine.

        1. Great! It sounds like you’ve made really good progress so far. I would be interested to know how the pressure sensor performs.

          The LPC1768 sounds a good choice. I’ve used the LPC2378 for another project (albeit with raw C rather than MBED) and those are really nice, very capable chips with tons of peripherals and I/O.

          With the IGBT circuit, note that the DC GND is completely isolated from the CPU (and more importantly, from you!) by the opto-isolators. If you look at the diagram, note that there is no GND connection between the IGBT circuit and the CPU side (very important). The DC supply 5V_RN from RG1 is only used to drive the opto-isolator LEDs, IC1 and Q3. You could equally use a capacitive dropper or similar to replace RG1.

      2. About your snubber circuit, my plan was to add a resistor in series to D6, which should in theory “snub” the current faster (unless the properties of the pump make it so that the loop is only really being run through once).

        1. I’ve also experimented with a resistor in series with D6 (around 200R). This works (better in fact), although be aware that the resistor will dissipate a lot of heat (you need a high power wire wound resistor) and the IGBT will also run hotter.

          1. Yes I was thinking of a low resistance/ high power resistor, but didn’t consider the fact that this would increase the voltage at the IGBT. It bothers my OCD a bit even though it’s inconsequential specially considering how much heat is generated by the boiler and the fact that the pump only runs for short amounts of time… Nonetheless I’ll do a bit of research on stubbers and see what comes up.

          2. My initial research seems to be pointing to either TVS diodes [1] or reverse-biased rectifier diode in series with a Zener diode as good options as well. I think all options will cause heat dissipation at the snubber, I will look for the ones that are fast and cause the least strain on the IGBT. I might even try several options and compare for fun.


          3. I’ve done a little experimentation with TVS diodes, series resistors etc. but need to do further research & testing to find an optimal solution.
            What I found was that with a single diode, the pump solenoid is slow to switch off, which effectively reduces the power because the pump isn’t oscillating effectively. If you add a series resistor, Zener or TVS diode, that helps a lot because there’s a larger voltage drop so the solenoid current decays more quickly. However, the catch is that this results in a higher voltage at the IGBT also, so you must be careful not to exceed the maximum ratings of the IGBT.
            I have a spare pump now, so I might do some more experimentation myself (without disrupting my morning Espresso routine, ha ha!)

          4. Thanks Philippe
            Coincidentally, I read the same forum posts (that’s probably the best practical discussion of solenoid snubbers I’ve seen). Well this weekend it looks like I might finally have a little free time to experiment, so perhaps we could continue the discussion by e-mail and share our results? I’ll drop you an e-mail so you have my direct contact.
            Kind regards

  1. Hi, I noticed your heating elements are in series instead of parallel. This reduces your power by a factor of 4. Why did you choose to do this? The original parallel configuration is very optimal for putting as much wall power into the boiler as is possible. Do you have different heating elements than the original 22.4 ohm parts?

    1. Hi Tyler
      As standard, the elements are normally wired in series for 240V mains (UK, Europe etc) and wired in parallel for 120V mains (US etc). This part is the same as stock factory wiring, and I assume is a simple cost saving trick for the manufacturer (i.e. so they can use the same boiler worldwide, with different wiring).
      For 240V we have I=240/(2*22.4)=5.36A therefore P=240*5.36=1.29kW approx.
      For 120V we have I=120/(22.4/2)=10.71A therefore P=120*10.71=1.29kW approx.
      Comparing 120V to 240V, at 120V there is half the voltage, double the current, but the same power of about 1.3kW.
      Now we could obviously wire them in parallel on 240V and get 2.6kW, but that’s more than the original rated power as it came from the factory. It would probably be OK for short duty cycles though.

  2. James,

    I finally got some time to play around with my project – I’ve soldered together an IGBT based AC chopper as per your design. It worked fine when testing it on my workbench with low voltages (power supply, oscilloscopes, a sinusoidal function generator and a pwm function generator). But when I plugged everything into my machine, it seems like the IGBT wasn’t switching anymore when in a high voltage environment. I’ve done some measures on the DC/low voltage side of things and everything looks good, but my multimeter is clearly showing an off IGBT at all times no mater what goes into it.

    Any idea where to start debugging this issue? My circuit can be found here: https://imagebin.ca/v/3hDkdIQsYE8n

    1. Hi Philippe
      What you have looks reasonable to me at first glance. What type of IGBT and gate driver are you using? The first things I would check are the obvious (which I’m sure you have already): power supply, input to gate driver, output of gate driver.
      I assume you’ve already tried simple and slow on/off switching with the IGBT (i.e. get that working first, before graduating to PWM).

  3. James,

    My IGBT is this one:


    So I’ve tested the power supply by simply replacing it with my workbench power supply, no change

    I’ve checked both input and outputs of gate drivers and they seem to be doing the right thing.

    The only caveat is that while trying to measure the DC side of the circuit, there seems to be a baseline, 60hz sinusoidal distortion of all my signals (so my output signal from the power supply for example is not straight 5V). I am assuming this is simply due to the AC GND. I will replug things and get some screenshots.

    As for simple on/off switching, I tried with 100% PWM so basically a DC going in, but no cigar.

    1. Well, it looks like you are using the same IGBT as me, and in a very similar setup. Strange!
      It’s difficult to take measurements with a ‘scope in situ, because the scope will be grounded to earth, so you will see 60Hz AC superimposed on everything. I used a battery powered ‘scope to avoid this.
      At the moment I don’t have any immediate ideas of what the problem might be, but I’ll give it some more thought.

        1. In case anyone is following this thread – my circuit works and the problem ended getting solved by reversing the connectors on the pump (the internal pump diode was in the wrong direction!).

  4. Can you share your Eagle file/schematic for this project? Also would it be possible to use the extra opto-coupler (OC3) and the extra TC426 (IC1G$2) to control the heater? I had issues with controlling my SSR-40A relay with my 3.3V arduino and thought I may have to use a 5V to get it to work but his seems like a better option as I am not a big fan of the 5V arduinos.

    Last question, is it possible to also power an arduino with AC/DC converter and not have have a shared ground with main?


    1. Hi William
      Yes, I can certainly share the Eagle schematics (bear with me, and I’ll look them out and e-mail you).
      I’m surprised the Arduino 3.3V output can’t drive the SSR directly. You could add a transistor as a level converter to drive the SSR.
      It would be possible to use the spare optocoupler to drive the SSR, but I think the transistor would be a better option. The shared ground with mains is unfortunately necessary for the TC426 to drive the IGBT. Because the ground of that circuit is referenced to mains Neutral, it’s not safe to use the AC/DC converter to power any circuitry that you are likely to touch. It’s designed to be a self contained module, connected to the microcontroller only via the opto isolators. I would recommend using a separate 5V or 3.3V power supply for your Arduino, as it’s much safer, and they are so cheap these days anyway πŸ™‚

  5. I am experimenting with this by building the following approaches and testing them:
    1- IGBT with high frequency PWM
    2- IGBT with phase control (zero cross detector circuit + micro-controller phase control)
    3- random-fire SSR (zero-cross detector circuit + micro-controller phase control). This requires the least circuitry.

    I’ve finished 2 and will soon be finishing 1 and 3.

    Here are some quick/initial results:


    As you can see, I am able to get very precise pump control using a phase control circuit and the following equation to calculate the required phase delay for linear control:
    1000000 usec / 120 * (acos(2*x/100 – 1) / pi)

    The IGBT/flyback resistor still get hot but significantly less than I get on solution 1 since I am only having a sudden voltage change at the pump once per cycle. I am able to use a normal resistor instead of a high power wire-bound resistor (as long as I don’t run the pump for too long! so this should still be built with a high power resistor).

    I will post more details and code when I get some time to compare the 3 approaches.

  6. Hi Philippe,
    I’m not sure how do you made your measurements – with IGBT or triac in phase mode? With or without flyback circuit?
    With triac and without flyback diode I got some flow instabilities by lowest values – pump starts to work at about 30% of setting – then it’s possible to go down to about 20%. If I start from 20% pump doesn’t flow the water.
    Another point is that what we adjust is flow – pressure (on blind portafilter basket) goes almost immediatelly to 16 bar.

      1. Hi Philippe,
        thanks for your link. It’s very interesting. The problem I mantioned is not that below 30% pump doesn’t work. The problem is a hysteresis I have observed – if you go from the bottom side pumps starts abruptly to work at 30%, at 25% only humms. After the pump starts to work I can go down to 25% and everything is OK.

    1. Sounds curious as I’m using very similar to yours triac SSR solution (MOC3023 optotriac and BT 131-600 triac instead of AQH3223 1,2A optotriac) and Arduino controlled phase control – and in this configuration I notice hysteresis.

  7. MOC3023 is random fire as well. I do not have the diagram but if you want I can draw and post it. It’s same like AQH3223 but made with discrete parts.
    In the meantime I realised that both Tom and me we use 230V 50Hz and you use 127V 60Hz.

        1. Hello Piotr & Philippe
          Excuse my radio silence, I’ve been really busy with work – but I enjoyed reading these as a spectator πŸ˜‰

  8. Hey James. Ive just recently bumped into your blog and i find i very interesting. I am huge coffee enthusiast and modifing my Rancilio silvia mechanically vise was one of the first thing to do when i got it. I have my old Gaggia classic laying around that i would give it a go and use it as test machine for doing your modicifaction.

    I am have some basic electrotechnical knowledge and will try to learn on the go. Do you think i could adapt your method to arduino without much changes? I just got arduino uno starter kit and after i go through some basic diagrams from project book i will jump on to gaggia modification.


    1. Hi Uros
      If you have two machines, that’s an ideal scenario, as you can carry out modifications without having to worry about the risks of losing your daily espresso πŸ™‚
      The Arduino would be a good choice for PID temperature control. Obviously the software would be completely different (you wouldn’t be able to reuse any of my software directly, although you might find some useful inspiration by looking at my source code, which could help you write the equivalent code for Arduino).
      The Arduino is much simpler (and less capable) than the Raspberry Pi, but it does have some potential advantages over the Raspberry Pi for this application, because it starts up immediately (i.e. no need for Linux to boot up), and it has onboard ADC analogue inputs (which the Raspberry Pi lacks). However, if you want to interface LCD displays, or put the system on your wireless network, the Raspberry Pi would be the better choice. There are pros and cons of both approaches of course.

  9. Hi James,

    That project is inspiring.
    I am trying it myself now with just the pump modulation section for now but there a few missing pieces.

    Could you elaborate on what are the 0.1uF and 100Ohm capacitor and resistor in parallels to the pump?
    They weren’t there on your first design and they aren’t marked with a number so I’m not sure if it’s something original from the Gaggia.

    I did try to build a the circuit and power it with 220v without load, and the D6 Diode busted. So I was wondering if it had something to do with the pump missing.

    Also, I’d be really happy if you could contact me via email for a bit of help with electrical debugging πŸ™‚

  10. Hi,
    Why haven’t you use mosfet instead of igbt. It looks like it would work in the same circuit and us much cheaper.

    Best Marek

    1. Hi Marek
      IGBT are usually preferred to MOSFET for higher voltage applications and have low on-state resistance. As I understand it (!), this makes them well suited for driving inductive loads which may have very high back EMF voltages. Also, I am in the UK and our mains voltage is ~240V AC, which has peaks of ~330V. The back EMF spikes from the pump are likely much higher than that (although this is speculation, and I haven’t actually measured them). At the time, those were my criteria for selecting it.
      That said, I’m sure you probably could use a suitable MOSFET in this application also, if you can find one with suitable ratings.
      Regarding price, that wasn’t a major consideration at the time. I can’t remember what I paid for the IGBT, but I don’t think it was very expensive back in 2015. Of course, this particular part (IRGB14C40) is now obsolete and no longer manufactured, and we are also in the middle of an international shortage of semiconductors, so those two things probably contribute to the very high prices for remaining stock of this part.
      So, the IRGB14C40 would definitely not be a good choice in 2022, and there is almost certainly a better/cheaper option available now.
      Hope this helps?
      Kind regards

Leave a Reply to Tyler Troyer Cancel reply

Your email address will not be published. Required fields are marked *