www.evocationcoffee.com: artisan roaster with passion for great coffee

DIY PID-Controller with microcontroller

Need help with equipment usage or want to share your latest discovery?

Link to "DIY PID-Controller with microcontroller"by emc on Sat May 16, 2009 1:11 pm

I'd like to present my latest DIY project: a microcontroller-based process control unit intended (among other things) for PID control of espresso machines:

Image
More pictures on web site...

It is the successor to my first attempt at using an Atmel CPU for that purpose - the original but unreleased coffeeboard.

Currently, the project is in a "designed for geeks" state, ie. for those who have the ability to build and install such a thing and who want to write an OS for their espresso machine. At a later stage, I hope to to be able to offer a PID/brain box software package for it.

What it can do - with the correct kind of software:
* it can read ten (or more) different sensors simultaneously and let them affect the control loop - e.g. fresh water temperature, boiler temperature, brew presssure, flow rate etc. Such readings permit to add a feed-forward element to the control loop (equals faster response).
* it can drive five relays, solenoid or solid state, making it possible to control more components than just the heating elements as is done in a classic PID setup. For example, it could control pump, solenoid relay and the heating elements of multiple boilers.
* the module contains a zero crossing circuit for phase angle control; this could be used to vary the power supplied to a vibratory pump - and ultimately the brew pressure.
* for user feedback, the module can drive 14 LED (e.g. a bargraph), an LCD display and a piezo buffer. The backlight of the display is controlled by software.
* a battery-buffered clock chip could be used to warm-up the machine at programmed times.
* data can be sent to a connected computer via USB cable, permitting use of the module as measuring instrument to record multiple process values at the same time (record the presure-flowrate diagram of a pump etc).
* You probably have more ideas. Let me know.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by mhoy on Sat May 16, 2009 2:25 pm

A nice looking board you have there.

What kind of temperature sensors do you have in mind?
Having at least one thermocouple input would be useful.

Mark
User avatar
mhoy
 
Posts: 950
Joined: Jan 09, 2008
Location: Sunnyvale, CA

Link to "DIY PID-Controller with microcontroller"by emc on Sat May 16, 2009 3:26 pm

It supports two thermocouples type K. Thermocouples resolve temperatures to 0.125°C and exhibit thermocouple accuracy of ±2°C. Accuracy can be improved by calibrating the thermocouple with a calibrated digital sensor. Thin thermocouples are the best way to pick up quick changes, so those would be used to measure in/after the portafilter. The module also supports KTY sensors - analog silicon sensors which due to their small size have a fairly good thermal time constant and are dirt cheap - but are uncalibrated and offer only 0.3°C resolution at the ATMega's ADC. Last but not least, all sorts of calibrated digital sensors can be connected: 1-Wire sensors such as the DS18B20 (0.5°C accuracy, resolution better than 0.1 degree, but poor thermal time constant), I2C sensors (I believe those are not available in a suitable package for our purposes) and the super-precise TSic ZACWire sensors from ZMD (e.g. TSic306WTB, 0.3°C accuracy, 0.1°C ressolution)
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by Vad on Sat May 16, 2009 3:38 pm

Very interesting project with a huge potential. I'll watch it. If you need any help from a graphics designer, let me know. :)
Vad
 
Posts: 164
Joined: May 08, 2009
Location: Czech Republic

Link to "DIY PID-Controller with microcontroller"by rsinger on Mon May 18, 2009 10:26 pm

EMC:

A very cool project.... I've done an Arduino based mod of my Silvia (based on the work of Tim Hirzl). I have a built in PID algorithm that controls both brew and steam temp with in +/_ 0.5 deg F. All of the PID parameters can be set by using a 2x16 LCD and a 4-button interface that I developed in place of the Wii nunchuck used by Tim. I have the ability to set two wake up times and corresponding sleep times, so that Silvia will turn herself on and warm up in advance of brewing (morning and afternoon currently used, but can be set to any real time hour and minutes). I have also included a "forced sleep" function, so that I can put Silvia to sleep w/o having to wait for the sleep timer to act. Additionally, I have a shot shot timer that begins when the brew button is pressed, and can be reset to zero at any time. When not brewing, the LCD displays the current day, date, time. When brewing the actual (current) and target temps are displayed.

I have also programed a low water alarm (displays "Add H20"), where I have an external probe on the water tank based upon a capacitive proximity sensor.

Needless to say, with the limited internal memory of Arduino, the programing was a challenge... but it is a cool project and a lot of fun!

Check out my blog for more info... All the hardware and software can be found there:

http://espressoproject.blogspot.com/2008_10_01_archive.html

Rick
rsinger
 
Posts: 9
Joined: Feb 01, 2009
Location: Boca Raton, Florida 33433, USA

Link to "DIY PID-Controller with microcontroller"by emc on Tue May 19, 2009 3:34 am

@Rick:
That's a great project! I can not imagine how you have managed to fit the code into an Arduino. That's 16KB?
a low water alarm (displays "Add H20"), where I have an external probe on the water tank based upon a capacitive proximity sensor

I suppose "on the tank" means outside the tank? I tried the capacitive approach, too, to avoid putting probes into the tank and to get a fill level instead of an alarm. I used metal plates near the plastic tank of a Gaggia (= capacitor). This capacitor was attached to a voltage-controlled osciallator. I worked outside the machine but was unreliable: Tiny variations in distance to the tank would have a big effect on the frequency. I never even tried it with the tank in the machine, ie. near all the metal. I have since then decided to either go with a magnetic swimmer + hall sensor (a rising tube must be built for it inside the tank) or just rely on the flowmeter. The latter solution would give a water-out alarm and not warn in time to refill.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by HB on Tue May 19, 2009 8:55 am

Reminder to Dietmar: Many of our members frequent multiple coffee sites. Please avoid cross-posting your question, or mention the other site(s) with referral link(s) to avoid repetitive responses. For those following this thread, see his cross-post on CoffeeGeek here.
Dan Kehn
User avatar
HB
 
Posts: 9881
Joined: Apr 29, 2005
Location: Cary, NC

Link to "DIY PID-Controller with microcontroller"by rsinger on Tue May 19, 2009 11:09 pm

EMC:

Yep... programing was quite a challenge... I actually got a lot of help from a good friend (Arnold) with a great compiler and a lot of experience!

The water level sensor that I made can be seen pretty clearly on my blog.. it's based upon a Qprox QT113-DG capacitive proximity sensor. It took a little work to find the correct reference capacitors, so that circuit just sensed the water level in the tank in a reproducible way, and not just me walking into the room! (just kidding!). And yes, the sensor electrode is external to and attached to the tank... no probe in the water.

The whole project was a great learning experience on a lot of levels, and I got great espresso to show for it!

Keep up the awesome work!

Rick

My blog: http://espressoproject.blogspot.com/2008_10_01_archive.html
rsinger
 
Posts: 9
Joined: Feb 01, 2009
Location: Boca Raton, Florida 33433, USA

Link to "DIY PID-Controller with microcontroller"by emc on Sun May 24, 2009 2:08 pm

It seems there is a lot more free space in a Gaggia Coffee by comparison with the Silvia pictures in your blog. Could have installed a netbook in it :? Module at the backside in these pictures: Image
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by rsinger on Sun May 24, 2009 8:21 pm

EMC-

Yeah, looks like you have a bit more room than I do, but don't forget, I've got 4 optoisolators in there so that Arduino can "sense" the status of all of the face panel buttons, and still allow all of the indicator lights to work as in the unmodified virgin mode. That way, the PID algorithm will automatically control the Brew temp in the power on state, and the shot timer starts when the brew switch is turned on, stops when it is turned off, and the PID algorithm automatically toggles up to the preset steam temp when the steam button is pressed, reverts back to brew temp when steaming is finished.

They took up a fair amount of space because I got first generation Opto22 optoisolators for really cheap on eBay, whereas 2nd and 3rd generation were out of my price range (reality strikes again!)

None the less... still looks like you have more room than me... that's only a good thing (but then again, I got used to working in a really small space ... 16k!)

Rick
http://espressoproject.blogspot.com/2008/10/parts-list-for-intrepid.html
rsinger
 
Posts: 9
Joined: Feb 01, 2009
Location: Boca Raton, Florida 33433, USA

Link to "DIY PID-Controller with microcontroller"by emc on Mon May 25, 2009 5:26 am

The Gaggia has separate lights and not lights in buttons - those can easily be replaced by bright, white LEDs driven by the module (Silvia's lights in buttons could probably be replaced by LEDs, too?). 14 LED outputs are available. With this solution, the software decides when the lights go on.

As far as steaming is concerned, I intend to let the original thermostat handle that for safety reasons, ie. the steam thermostat will remain in the machine and break the circuit at its rated temperature. The steam switch will just bypass the PID. In steam mode, the module will see the temperature rise above setpoint but that doesn't matter.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by emc on Wed May 27, 2009 11:01 am

First tests with simple PID control code (that's a source code example from the CD-ROM) - after connecting the module to a PC to get plots. The upper picture is for comparison with the original thermostat. PID parameters not yet accurately tuned but almost randomly chosen:
Image
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by emc on Wed May 27, 2009 2:55 pm

And as video (the PC-side software can export Quicktime):

http://emc.awardspace.com/videos/pcu644-18.mov

To make it more interesting than a flat line, this is a step response to a new setpoint with badly tuned PID parameters.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by karl_a_hall on Wed May 27, 2009 4:06 pm

So I really really really want one of these... are you gonna make kits, sell partially assembled kits, etc? Good good work my friend.
User avatar
karl_a_hall
 
Posts: 47
Joined: Oct 01, 2008
Location: North Suburbs of Chi-town

Link to "DIY PID-Controller with microcontroller"by emc on Wed May 27, 2009 7:49 pm

This is a DIY project - only the PCB is available from me right now. I might make an attempt at a more user-friendly solution later (pre-soldered?), when a real brain box software is finished and not just a toy PID. But I won't be able to offer kits since my own espresso machine is way below the standards of the users here and I just don't know the insides of their machines. Btw, there is a FAQ section on my web site.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe
www.orphanespresso.com: lever espresso machine parts, manual grinders
www.orphanespresso.com: lever espresso machine parts, manual grinders

Link to "DIY PID-Controller with microcontroller"by rsinger on Wed May 27, 2009 9:57 pm

EMC:

Just for your reference here is a time / temp response from my Arduino based PID modified Silvia:


Image

P= 51
I= 0.15
D= 300

Have fun with it!

Rick

My blog: http://espressoproject.blogspot.com/2008_10_01_archive.html
rsinger
 
Posts: 9
Joined: Feb 01, 2009
Location: Boca Raton, Florida 33433, USA

Link to "DIY PID-Controller with microcontroller"by emc on Thu May 28, 2009 1:17 pm

Another interface that could be run on the PC to interface with the module (this early version can only display temperatures):
Image
http://emc.awardspace.com/videos/pid-sim.mov
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by emc on Sun Jun 07, 2009 6:52 am

The most interesting feature of the module probably is the ability to control power of small appliances (some hundred watt) by phase angle control. If this feature is used for the vibratory pump of an espresso machine, the working point of the pump - i.e. pressure and flow rate - can be adjusted within limits (*). To examine this, I've built Mr Pressure:

Image

This is a calibrated pressure sensor next to a simple ball valve. The valve is needed because the Gaggia Coffee can not release pressure with a 3-way-valve at the end of a measurement. The valve can be used to set a certain flow rate, too (the nonlinear characteristics make it difficult - a small knob rotation is the difference between "open" and "closed" - but it's better than nothing)

What can be done with electronic pump control? Possibly...
  • configurable preinfusion profiles
  • different pressure settings for Espresso and Americano
  • setting optimal pressure for ESE pads, so that adjustments can be made for the given grind
---
(*) Not stepless from 0% to 100% (as a lamp could be dimmed) because a vibratory pump needs a certain amount of power to start swinging synchronously with mains power.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by emc on Sun Jun 07, 2009 7:02 am

The first diagram shows the pressure development if the "grind" is adjusted to produce ~9.8bar (*). The pump is not electronically controlled and is started in second 10, as in all following diagrams:

Image
Animation with higher details: http://emc.awardspace.com/videos/forum_9bar.mov

(animations, due to an unusual frame rate, do not play correctly in some players; I recommend Apple's Quicktime player http://www.apple.com/quicktime/player/).

Empty portafilter and measuring system form a huge cavity. Normally the portafilter is filled with espresso. For comparison, I've excuted the measurement with water in the measuring system. With espresso instead of water, the pressure rise would be delayed somewhat.

The next diagram shows the pressure curve if the pump is electronically controlled to produce 4.5bar:

Image
Animation: http://emc.awardspace.com/videos/forum_4bar.mov

The final pressure is lower and the rise is slower: the more pump power is reduced, the lower the flow rate and the slower the pressure rise (opposite to pumps' pressure vs. flow rate diagrams - in those diagrams, flow rate is higher if pressure is lower).

--- edit 12/June : This was a wrong conclusion. I've in the meantime - after flowmeter measurements - found out that the slow pressure rise is caused by the Gaggia Coffee's ball valve on top of the boiler which does not close well if the pressure is low, leaking a lot of pressure and water to the tank and delaying pressure build-up (at low pressure, it can leak >100ml/min, at 14bar, it still leaks 40ml/min). Electronic control has surprisingly little effect on flow rate. Much less than on presssure ---

For the final measurement, the pump was electronically controlled to produce ~8.5bar. The measurement was made with an empty portafilter and an empty measurement system, ie. a lot of water had to flow to fill this cavity. As a result, the pressue rise is delayed and there is a noticable temperature decline (PID parameters not yet optimized to compensate for that):

Image
Animation: http://emc.awardspace.com/videos/forum_ ... filter.mov

---
(*) The Gaggia Coffee has no overpressure valve (with a diverging water route) which could put a ceiling to the presssure. Instead, it uses a spring-loaded brew group valve. This type of valve subtracts a certain amount of pressure from pump/boiler pressure but does not procuce a specific pressure level. Since pump pressure is a function of the flow rate, the pressure in the portafilter depends on the grind - simulated by the ball valve.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Link to "DIY PID-Controller with microcontroller"by emc on Sun Jun 07, 2009 2:31 pm

The next diagram shows how pressure is electronically limited to 2bar for pre-infusion on a Gaggia machine without brew group valve (valve of Gaggia Coffee removed - makes it more similar to a Gaggia Classic):

Image

Without brew group valve, the machine doesn't have to build up so much pressure in the boiler before the valve opens - hence pressure in the portafilter rises more quicky. The rise rate could be limited by software.
emc
 
Posts: 36
Joined: Nov 24, 2007
Location: Europe

Next

Return to Espresso Machines