Tuesday, April 24, 2018

Basement-Engineered Home Brewing Stirplate


Although my outdated, neglected, who-gives-a-shit blog rarely gets posted to anymore, I have adopted a soft spot in occasionally 'giving back' and sharing to a focused community of DIY folks, especially in the home brewing world.  This happens to be one of those moments.

I've been a very in-tune and serious-to-the-hobby home brewer for just over 3.5 years now.  Much like anyone starting out, there is a metric ton of learning and process fine-tuning involved at a serious level, well beyond just making a remotely drinkable extract home brew.  On top of that, it's a fucking money pit like any other hobby, but it also is the most collaborative and knowledge-sharing thing I've ever been a part of.  From the just-starting-out brewer up to a seasoned Brewmaster at a brewery, anyone will talk 'shop' with you, give you pointers, and help you along the way.  

For me, when cost-meets-process come into play, some will gladly pay for their home brewing solutions, while others try to DIY and/or re-invent the fuck out of the 'wheel of everything'.  I feel like I'm right on the fence and just depends on my mood, ambition and if I feel like exerting my talent and time vs. making my checkbook a bit lighter out of pure convenience.

So what the fuck is this all about?  It's about yeast cell generation and using a stirplate to perfect it.

I've always made 'shake when you walk by' non-stirplate yeast starters for years, and although many of the online tools for cell growth and propagation are slightly better-than-ballpark accurate, I felt like it was one of those core pieces of the brewing process I needed to improve to make/create a better fermented and consumable product, if not for any other reason, than for my own self preservation... and my kegerator.

In regards to stirplate topics as a whole, seems like most of us toying with this piece of equipment either have something already they aren't happy with, are in the market for one or simply not using one at all.  Let's take the upper and lower extremes of these camps:
  • Purchasing a $120+ Maelstrom stirplate from NB.  Some of us have disposable income to waste.  I don't know a single person in our home brewing community who owns that thing except for one person a friend of mine knows.  
  • 12v PC fan with a random potentiometer hack off a voltage regular.  Mechanically and from an engineering point-of-view (I don't care how pretentious I come across as) --- not a real solution.  Not to mention, it's shitty internet sheep plagiarism.
  • Legit, used lab-grade stirplate off an auction website.  This falls into the buy-it-the-fuck-already club.  If there's anything I would respect and trust the most, it's this.  But depending on the 'used' factor of this, it's not entirely out of the realm of getting a dud.
  • Buy a Stirplate kit.  There is but 1 or 2 real-deal engineered solder-yourself solutions I stumbled upon.  One of which was archived and you couldn't buy it, the others were PC fan knock offs. However, it's just the kit --- you need to find the proper enclosure and rest of that jazz.
  • Stirplate is you.  As mentioned above and how I was doing all of this.  I know friends who still do nothing more than agitate their still yeast starter over a period of 1-2 days when they walk by it and make way better beers than me.  Absolutely legit.
But whatever avenue you go with, it's the same problems:
  • They throw stir bars and often.
  • Linear variation in speed control is way more powerful than they need to be to make a vortex to draw in oxygen into wort solution while keeping yeast in suspension, but all the while, you still need that balanced power when considering, for instance, very large starters in 5000ml flasks.
  • The variable sweep of the speed you can dial for stirring (if that option exists) is not smooth and linear; it's pretty much on, slightly spinning or straight to 80,000,000,000 mph in a clockwise range of 6 to 3.
  • Some stirplates are under powered in the current department (if ran by batteries) so good luck making the minimum ~24h to double yeast cell rates because the draw off the DC motor will murder your battery in no time and you'll walk by a stirplate that isn't stirring anymore.
  • In regards to the stirplate being all about you, is that you get tired of babysitting that thing, forget to shake it, etc.
I like difficult problems and after pealing this back, and believe it or not:  This wasn't the easiest problem to solve, let alone, solve correctly.

Now let's say you settled on making one yourself like I did.  One thing I can attest to up front:  for pure reference material, there is but maybe 2 or 3 legitimate pieces of content that even talk about electrical engineered home built stirplates on the ENTIRE internet.  I've looked.  And looked.  And looked.  I can't even find a good boilerplate schematic or circuit to work off of or get an idea going from.  And anything I did find, I knew after 5 seconds of looking at it, there was no way that was working at all.

I think the biggest hurdle is turning all that Earth science and physics into a real electrical engineered solution.  Even though this is NOT my wheelhouse what-so-ever, and I'm a mere hack EE hobbyist, I'm not naive to any of these things below that really mattered WAY more than engineering the right circuit design and parts IMHO:
  • Magnetic field strength over distance to the non-competing polar magnetic source (e.g. stir bar) matters.  
  • Increasing magnetic field strength with lower to super strong magnets and stacking and finding the right balance that balances well with gravity, water mass, the magnets in your stir-bar, while not adding too much torque stress on your motor.
  • The diminished effectiveness of magnetic pull between different layered materials such as pyrex, plastics, glass, whatever.
  • Centrifugal force in relation to the stacking, mounting and centering of the magnets over the shaft of the motor unit doing the spinning.
  • Calculating the proper duty cycle for the DC motor involved in the design so it receives the correct amount of 'kicks' (pulses) over a variable range that's seemingly very focused and linear.
  • Housing material for the stirplate itself can't compete or interfere with the magnets to be durable, waterproof, hold a flask of 2000ml or larger, and clearly, house the design footprint as well.
  • Gravity and mass of different volume levels of water and it's effect on stir bar (e.g. holding it down in relation to weight of the water and gravity over it), the increased torque on the motor that is needed to overcome and 'spin through it'.
  • Not lose sight of the fact that this thing needs to do what it was made for:  agitate a solution with some spinning object, make a small vortex in liquid to pull in oxygen and do that task over and over for a long time.  Basically:  solve the problem without over-engineering the shit out of it.
I'm sure there's much more to say, and better eloquently put, too.  But you get the point I'm trying to get across:  there's a lot to consider and work through if you want to solve those problems above.

Without further ado, after almost 3 solid months of basement R&D, ripping shit off breadboards and starting completely over countless times, re-education in all that wonderful high-school level foundations in physics and Earth science that we all forgot eons ago, I bring you:  a legit, working stirplate.


The Schematic


Best part about this (to me) is it's a complete hardware PWM solution, 100% portable and reproducible.  I'm very comfortable and skilled with AVR microcontroller development, but implementing a timer based PWM solution to create a duty cycle I can calculate already with some math on a 555 timer is a way easier re-build for anyone else who wants to create this.

In the schematic, you'll see the use of an AVR, but it's just to use ADC to read the linear analog pot sweep that speeds/slow the duty cycle to the motor via the H-bridge IC and light up the LEDs in a seemingly eye-candy sort of way; it's totally optional and does nothing more than provide a visual reference of 'speed' beyond the potentiometer knob. Everything to the right of the dotted line "you need" to make this work. Everything to the left (e.g. AVR + LEDs), you don't.



The Parts List


Some quick notes on the parts list. I had a hard time generating + exporting one with KiCad , so it's easier to just jot down some specifics of some of the parts that maybe need some explanation.  ALSO, get the parts where you want.  I'm listing where I got it, but I order from Amazon, Sparkfun, Adafruit, Jameco, Solar Robotics, and a handful of other places.


  • Sparkfun Hobby motor:  I bought a handful of these for a solar-powered motorized steampunk garden robotic project I was working on and had them lying around.  The design lesson is:  Don't go beyond the 3v boundary to drive these for a stirplate.  Even though Sparkfun says "up to 12v", don't.  From a current perspective, thing seems to need to sync about 450-500ma just to get going @ 3v.
  • SN754410 H-bridge:  I initially went down the path of trying to procure a L293D, but this was cheaper and was like-for-like on pinout.  But it's output current is 1A.  Yes, there are 'other' H-bridge ICs out there, but remember you need at least 500ma for that motor to start.  That's why it was chosen.
  • 5v VCC source:  I have a ton of old flip and pre-smart cell phone chargers around from my every-year-free-phone upgrades of the old days.  Just pick something that's 5 volt DC and at least 850ma or higher.  1A preferable if you're going to use LEDs and microcontroller.
  • LD1117V33 voltage regulator:  Absolutely essential for driving the motor voltage source on the SN754410.  Running the motor at 5v is too much; the more voltage, the higher the RPMs. However, you still need source 5v for the VCC power requirement of the 555 timer and the SN754410.  I reference this, but I happened to have the older LD33V around that I used, but same thing.
  • 555 timer:  As opposed to doing any PWM and duty cycle calculations with the AVR (which you can), I wanted to keep the stirplate as 'hardware' as possible.  But see diode notes below this; the 50% duty cycle was just too much and I had to figure out a way to get lower than that.
  • 1N4148 diode:  This was the crucial component.  With a 555 timer, at best you can get 50% duty cycle with R1/R2 resistors.  You can get lower if you put a diode across the pins.  Since you're powering it with 5v, use the 1N4148.  This calculator was invaluable as well in enlightening me towards that path.
  • 1k Linear Pot:  I used linear because I wanted it as smooth as possible.  Unfortunately, I bought a super cheap Chinese potentiometer to save project costs and the sweep rate sucks on it.  If you wanted to spend more money on a higher quality trimmer pot with more precise turn counts, do it.  It'll only make it better, smoother and dial in speeds better.  Don't do logrithmic --- you won't be happy and the growth ratios of speed up will NOT be what you want; you'll go from 0 to 80,000,000,000 mph as mentioned above.
  • 5"x5"x4" enclosure:  I am glad that I happen to stumble upon this on Amazon.  This worked out great and sized well with the array of Erlenmeyer flasks my friend let me borrow for testing.  It's got a gasket on it for water-proofing, it's light but the plastic is super durable.  Plus, the lid depth is not flush with the top of the enclosure, so it was easy to 'build up' magnets and the motor mount bracket to get just right.
  • Ceramic Magnets:  I used a combination of low-power and high-power magnets as explained above. I got mine at Lowes, but I'm sure whatever home improvement or hardware store has something similar.  I used them as my base magnets because they had a bit more height than just using a rare earth or high-power magnet out of a spinning disk hard drive.  There is a picture of this.
  • Hard Drive (neodymium) Magnet:  You totally need this, too, but just one of the two that you usually get when you tear open an old hard drive to get one.  Just go find an old hard drive from a half-rate PC repair place in your city/town or if you have 8,000 sitting around like I do. And if you're really clueless, watch a Youtube video how to get it out vs. brute forcing it like a cave man.
  • Stirplate Bar for Magnets:  This is just a 3" zinc mending plate I bought at a Menards or Lowes.  I drilled into the center and just wedged it onto the motor shaft.  Don't remember the drill bit diameter, but whatever the shaft was, I just got it 'right' so it snugged right on.  Then the ceramic magnets were stacked correctly and epoxied on.  The weight of this in combination with the magnets is 'about' right for the physics side of keeping the spinning smooth in check.
  • Motor mount:  That's just a 1/2" electrical conduit shaft thing I found in some junk pile in our datacenter at work that was being thrown out.  The hobby motor perfectly fit in there.  Then I just bought an "L" bracket and screwed it on and epoxied it as 90 degrees and straight as possible for extra stability.  The motor can come out though --- remember if it burns out, I just want to replace the motor, not remake that whole thing again.
The optional parts (for the LED eye-candy):

  • ATMega168:  AVRs are my microcontroller of choice.  I don't even use the Ardunio frameworks; just straight avr-gcc as my compiler.  I could have used an ATtiny or something, but I want to ditch the LEDs and put on a 16x2 character display instead.  So if I need to add it, I've already got the microcontroller with ample GPIO port pins to handle it, and it's a batter of just cutting out the display space on the enclosure and soldering it in.  But whatever AVR you pick:  you need at least 6 free GPIO pins for LEDs and it has to do ADC conversion to read the analog pot value and convert it to digital.
  • LEDs:  Some grab-bag shit I have around.  I just picked colors of blue, the middle was yellow/green and the last one was red.  I just put in nominal resistor values for blue and red because they were a touch brighter than my yellow/green ones, even though the voltage drop on those tells you otherwise. Don't read too much into that --- I just wanted the brightness to be visually 'even' between LEDs.
  • IC DIP sockets:  For the love of all things engineering, please solder in IC sockets in case you kill an IC or whatever, you pop it out vs. soldering it directly to your thru-hole board.  We're talking mere pocket change here.  I can remove the 555-timer, H-bridge or AVR (or upgrade them), especially the AVR; you'll be able to take it out, put it on your development board, write your new sketch, and pop it back in.  

AVR Code/sketch for ADC + LEDs


Honestly, there isn't much to this.  I spent way too much time monkeying around with ADC converted values from my pot, trying to create a fill-value map range just so it gave you a nice, visual "cute and smooth" light up pattern.

Going back to my crappy Chinese potentiometer, a lot had to do with it's cheapness.  I ended up taking up to 150 samples triggered off ADC interrupt, totalling and finding the mean, then creating a smaller linear map number value range.

Here's what my ADC Interrupt routine looks like:

ISR (ADC_vect)
 {
   trigger++;

   if ( trigger < 150 ) {
      ADCvalue += ADCH;
   } else {
      uint16_t mean;

      mean = ADCValue / (trigger - 1);

      sweep = map(mean, 0, 195, 4, 58);

      ADCvalue = ADCH;
      trigger = 1;
   }
 }
Then in the main() loop, I just check the volatile global value of the ADC sample average of that window and have the LEDs turn on as the potentiometer value increases:
while (1)
 {
    if ( sweet >= 67 ) {
       // turn on all LEDs, adding final RED
    } else if ( sweep >= 45 ) {
       // Add in final Green/Yellow LED
    } else if ( sweep >= 26 ) {
       // Add in middle Green/Yellow LED
    } else if ( sweep >= 14 ) {
       // Add in first Green/Yellow LED
    } else if ( sweep >= 12 ) {
       // Add Green-only LED
    } else if ( sweep >= 10 ) {
       // Just Blue LED
    } else if ( sweep >= 9 ) {
       // Just Blue LED
    } else {
       // NO LEDs
    }

    _delay_ms(200);
 }
If you were to graph those values, they aren't exactly 'linear' either and look more exponential, but do notice how the values sit low then suddenly, it changes, and I'll chalk that naively (again) to using a cheaper grade potentiometer.  My sweep really looked like this:




So even my map() function to convert on linear range to another smaller linear range wasn't evenly divisible at all, in terms of using the 'clock face' analogy that if your mapped range is 0 -60, dial is at 6 o'clock that 0, noon/12 o'clock should be 30 and almost back to 5/6 o'clock again would be 60; that's not the case.  So I just played with the numbers until I felt it looked right when moving the knob from 'off' to 'full throttle':


long map(long x, long in_min, long in_max, long out_min, long out_max)
 {
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
 }


All that hard-coded nonsense I did was to just-get-it-done because it got to be a bit of an ass ache to do it differently so I opted for a short cut.  I wouldn't use my numbers; that's going to depend a lot on the potentiometer you use. You'll just have to test your potentiometer, dump the values over USART (RS232) or write them to a character display, see what the base-10 value is, and make your own range.

The Pictures


What kind of person would I be if I didn't put a metric done of pictures for you to scroll through and convince you to do it as well!

Unfortunately, a lot of my video shots were iOS 'live photo' shots and found trying to use iOS Photo app to convert them didn't work at all out of the box. So I used Lively to convert them to animated GIFs quickly. They are absolutely amateur-hour and not great, but you get the point.












































































That turned out way longer of a blog post than I wanted, but hopefully it's useful.  Enjoy!