Introduction: Mr. Compost: How to Make an In-kitchen Compost Turbocharger!
Mr. Compost is an appliance which heats and agitates food scraps collected in your kitchen. This accelerates decomposition before you put the compost outside (in a worm bin or compost pile) to finish breaking down.
My own goal was to build something that would break things down enough that once transferred to my worm bin, the compost won't draw flies. This will allow me to move the worms inside during the winter without an entourage of flying insects.
Agitation helps add oxygen to the mix and mechanically break things down while allowing moisture to escape, and high temperatures (we'll be shooting for 140F) are ideal for the voracious thermophilic bacteria which take over naturally when outdoor compost piles build up enough internal heat on their own. As a bonus, flies stay away from things at that temperature.
Doesn't this waste energy? It does use some electricity, but if you're a city dweller who can use this and a worm bin instead of curbside yard waste collection, then disposing of kitchen scraps this way saves energy! I'm still working on getting 1.21 gigawatts back out of it though....
Sound complicated? We're just replacing the computerized controller in another appliance that holds, heats, and agitates things: a bread maker!
First Prize in the
Get in the Garden Contest
Step 1: What You'll Need
- a bread maker ($5-$25). I used a Zojirushi BBCC-V20 that I found at a thrift store; I'd highly recommend this brand because of the way it's clearly designed and labeled internally, as you'll see later.
- a microcontroller ($0-$30) with at minimum several digital I/O lines. At least one analog-to-digital input and one PWM output is preferable. I used a Basic Stamp II (only digital I/O), but I highly recommend using something newer and easier to program such as an Arduino USB Board ($30 at SparkFun)
- (optional) an LCD ($0-$20), 2x16 character or so, so that Mr. Compost can tell you what he's doing
- miscellaneous resistors and connecting wire
-a coat hanger for upgrading the bread machine's stirrer/kneader into more of an auger that will thoroughly turn the compost
My total cost: $25 for a bread maker; everything else was laying around. If you have to buy everything, you should still be able to do this for under $50.
For a fun comparison, the NatureMill Plus Edition is $299 - but keep in mind that Mr. Compost doesn't replicate all the same functionality.
- a soldering iron and solder
- wire strippers/cutters and pliers
- screw drivers
- a logic probe or voltmeter (preferred)
- vinyl (electric) tape and a sharpie
- a breadboard is very helpful for assembling intermediate test circuits
- a computer for developing the programming for your microcontroller
- a drill or dremel tool and small drill bit to make holes for coat hanger wire (5/64" worked for me)
- a beer bottle to help shape the coat hanger
- comfortable going beyond "Warranty Void If Broken" stickers
- solid understanding of circuits & some experience reverse-engineering circuit boards
- comfortable working around live circuits with potentially lethal voltages
- experience soldering, especially in tight places
- basic understanding of PID feedback control using Pulse-Width Modulation (PWM)
- whatever programming language is required by your microcontroller
This is a fairly technical project. I've focused on covering all the high-level aspects that are important while also selectively including details that will save you time, hopefully without being too long-winded.
Step 2: Dissecting the Bread Maker
Getting Under the Hood
The first step is to observe your bread maker in operation, and to do so while monitoring what's going on under the hood so you can figure out how to control it yourself. Specifically, we need to find the following logic signals which the existing computer uses to interact with the rest of the machine:
- the lid switch state (makes the bread maker stop what it's doing if the lid is open)
- the control signal for the heating element
- the control signal for the agitator motor
- the control signal for the piezo speaker (optional, if you want Mr. Compost to be able to beep)
- the analog signal from the temperature sensor, which in my case is a thermistor circuit
You'll need to partially take apart the bread maker so that you have access to the circuit boards while the machine is operating. Note that this is DANGEROUS as you'll be working very close to uninsulated AC mains voltage - always use only one hand and be extremely careful. You should be 99% confident that you're not probing what could be a live AC wire before you poke at something on the circuit board, and use a tool that won't be damaged if you do touch AC mains voltage if possible.
Reverse Engineering the Circuit Boards
As you can see from the pictures, the BBCC-V20 machine that I used has a clear separation of the circuit boards which respectively hold the computerized controller with the user interface and the power and high-current switching relays. Furthermore, the silkscreen on the circuit boards has extensive labeling of components and signals on both sides (this is fairly unusual in consumer appliances; it makes it easier to repair which sadly is often not what the manufacturer wants).
Before hunting down the logic signals, much of the complexity of the power/switching circuit board can be reduced by following the power from the wall and figuring out which traces are AC power and (converted) DC power. In this case the DC power lines are labeled with Vdd (positive) and Vss (negative). Power traces are usually fairly wide, and the ground trace even occupies large swathes of the board. In contrast, the signal traces we want to identify are the very skinny traces starting at the ribbon cable which connects to the computer circuit board.
I was able to identify most of the signals with high confidence before actually probing them by following wires connected to the heating element, motor, etc. back through the relays (large black boxy components) and switching transistors (smaller black components with 3 leads) to the ribbon cable connector. The chain of transistors and relays connecting the controller signals to the thick wires leading to the motor etc. work like a small switch that turns on a motor which in turn opens a sluice gate or large valve: they allow a very small signal to be amplified into controlling a large amount of energy. The lid switch and thermistor circuits have more direct connections to the ribbon cable.
Take notes as you go, and once you have a good idea of what a signal is, probe it at the ribbon cable (or as close to the controller as possible, to avoid probing high current/voltage) while the machine is operating.
Once you think you know enough to drive the control signals using your own circuits, it's time for the next step. Here's what I came up with for the BBCC-V20:
Ribbon cable pin functions:
1) Vdd (+5 VDC power supply for controller)
2) Vss (Ground for controller power supply)
3) Thermistor circuit (temperature sensor)
4) Lid switch state (+5V when lid closed, 0V when open)
5) Resistor connected to lid switch state. Connect this to +5V as a 'pull-up'
6) Motor control triac. +5V = motor off, 0V = motor on
7) Heater control. +5V = heater off, 0V = heater on
8) Motor control relay with unknown function. Leave at +5V.
9) Piezo speaker. A square wave to this pin results in a tone from the speaker.
10) AC sense - this signal swings between 0V and 5V at 60Hz, in sync with the AC power supply
Step 3: Integrating Your Microcontroller
Time for a leap of faith: we're going to cut the ribbon cable connecting the power/switching board to the controller board and attempt to manually control the different functions of the bread maker.
(Note that I did investigate reprogramming the existing controller. While its program is stored on a very commonly-used EEPROM chip, the controller itself has a proprietary label and I'd need more specialized tools to observe the controller loading its program from the EEPROM in order to hack it. It seemed more efficient to just replace it with a known controller.)
Testing With a Breadboard
I first connected the ribbon cable to a breadboard so that I could manually set the different logic signals high or low or easily observe their states, without committing to anything by soldering things together. In this way I could confirm the way the heating element and agitator motor are controlled, and how the lid switch works, before hard-wiring any circuit to my own controller. I found that I needed to connect one of the signals in the lid switch circuit to a DC voltage in order for it to work correctly. When I was ready to hook up my microcontroller, I first tried just powering it from the bread maker's DC voltage supply and running a test program before hooking up the signal wires. Note that the bread maker's DC supply should be connected to the unregulated DC input on your microcontroller because we can't assume the DC supply is exactly the right voltage and noise-free.
Soldering in the Microcontroller
When you're ready, connect the logic signals on the ribbon cable to your microcontroller digital I/O lines appropriately (for me this meant directly in almost all cases). Connect the thermistor circuit to an A/D input; in my case I had no A/D so had to fake it with a digital I/O and a trick involving measuring the discharge time of a special circuit. (The Arduino Duemilanove has 6 A/D inputs)
Programming Tips & Tricks
As you start programming your microcontroller to run the bread maker, there are a few tricks to help keep things safe and productive:
- pay careful attention to the default power-up state of your controller's digital I/O lines. You don't want the heater and motor to get switched on immediately; your first line of code may need to set the state of these controls
- start by writing a loop that checks the lid switch and turns everything off if the lid is opened.
- Keep the bread maker plugged into a power strip with its own circuit breaker that is not what your development computer is also plugged into. This adds a level of safety and allows you to quickly switch off the bread maker without yanking any plugs or losing unsaved changes.
- As soon as you have a piece of 'safe' code that will run without turning anything on at all, save it separately and keep it open and ready to load in your development program. The reason for this is that if you make a change to your working copy of the program and it does something stupid and/or dangerous, like continually resets itself while switching the heating element on and off, simply cutting off power to the maker does not solve your problem: that program is still going to load when your microcontroller boots, and you're going to need some time to sort out the bug in your program. So instead of cutting the power when your program behaves poorly, you can quickly load your 'safe' program and proceed with debugging your working program without interruption.
If you're using an LCD, I recommend waiting to add that until you have the above basic functions working. While it may seem like a convenient way to debug by displaying what's going on, I found that the debugging tools provided with my controller were more useful and getting things to display properly on the LCD was a hassle requiring its own debugging. When/if you do add the LCD, use a PWM output on your controller, if available, to drive the backlight. You may need a small transistor, such as a 3904, to boost the current from your controller PWM output if that function isn't provided by the LCD.
By now, you have probably realized that maintaining a specific temperature in the oven chamber when the heating element can only be off or fully on is not going to be trivial. The next step is dedicated to addressing this.
Step 4: Implementing Temperature Feedback Control
Rough Temperature Sensor Calibration
First, let's talk about using the temperature sensor. You should be getting some number back from the thermistor circuit when you check the A/D input assigned to it, which of course is not degrees F. So we need to calibrate the sensor circuit. A quick and dirty way to do this is to fill the baking pan with hot water at about 160 deg F, put a thermometer in it, and let it sit in the bread machine with the lid closed until the thermometer reaches about 140. You'll have to use the window or guess and check, but try to only check once or twice. When the thermometer reads about 140, use your program to read the A/D input and temporarily consider this number to correspond to 140 deg. It will actually be more like 120-130 deg, but we'll fix this later. In addition to this, you need to confirm whether the A/D value gets larger or smaller as the temperature increases. These two pieces of information are enough to start doing temperature feedback control.
Feedback Control Options
There are two ways of implementing temperature feedback control that I considered: thermostatic and proportional-integral (PI).
Thermostatic control solves the problem much the way an old thermostat for a home furnace does: it turns on the heat full blast until the desired temperature is reached, and then it shuts off until the temperature drops a certain amount below the desired point. In this way it cycles between these two temperatures, and the rate at which it cycles depends on how fast the heating element adds heat, and how much delay there is between heat being added and the temperature sensor sensing it.
I found that thermostatic control works, but there is enough delay between the heating element and the temperature sensor that the oven will overshoot quite a bit (probably close to 200 deg F) when it initially switches on and must rise to 140F from room temperature. This creates a marginally unsafe situation if someone opens the lid a few minutes after the unit is first powered on. It's also going to smell worse if any organic matter accidentally falls on the heating element.
Proportional-Integral (PI) control is a little more complicated, but works better. We'll need to use it in conjunction with PWM - and I'll first explain PWM briefly because the Wikipedia article is confusing and starts off with ugly math.
Pulse-Width Modulation: Averaging ON and OFF into something in between
The basic idea of PWM is that when we are only allowed to turn something all the way on or all the way off, we can achieve an effect equivalent to part-way on by rapidly switching it on and off and regulating the ratio of on-time to off-time. This works only when the thing we're controlling naturally averages out the pulses at the speed with which we're switching. For example, you can repeatedly poke the 'pulse' button on a blender or the gas pedal in a car almost fast enough to get a consistent average speed. But if you tried to flick a light switch on and off fast enough to get averaged dim lighting, you're out of luck - yet a fluorescent bulb blinks on and off 120 times per second with the AC supply and is averaged out by our eyes. For bigger things with more inertia, the pulses can come slower and still be averaged out. In our case, what we care about is the temperature of the contents of the baking pan, which won't heat and cool nearly as fast as the surrounding air in the oven (or the temperature sensor in the wall of the oven). So, if the oven air swings by a few degrees every few minutes, this is acceptable and the baking pan contents will stay at about the average temperature.
With this in mind, I chose 5 minutes as the cycle time for the PWM control of the heating element: every 5 minutes, the heating element will be turned on for between 0 and about 45 seconds, depending on what the PI controller wants. The reason for not turning the heater on and off more often is that switching it involves switching a relay on the power circuit board, which makes an audible click each time and would wear out much faster if it were switched frequently.
Implementing a PI Controller
Okay, now for the PI controller. An explanation of PI control would take up a bit too much space here, so I'll refer you to the reasonably well-written Wikipedia entry on PID control. The reason I leave off a derivative term (PI instead of PID) is that I know my sensed temperature is going to oscillate a bit anyway because the PWM cycle time is so long, and the oscillations I'll get without a derivative term are no bigger.
Since we're controlling the average temperature, we need to make sure we measure the average temperature for performing feedback control - so at the beginning of every PWM cycle, the controller should average out the temperature over the last cycle to decide how long to leave the heater on for in the new cycle.
Results and Fine Tuning
Testing a feedback controller that takes 5 minutes to do anything interesting can be a real hassle. One way to make life easier is to automatically record and plot what the controller is doing. Your programming tool for the microcontroller no doubt provides a debugging console which you can send text to from your program. Take advantage of this by sending a comma-separated list of useful variables each time your controller updates itself. Then, you can just save all these numbers into a text file, import them into Excel or another spreadsheet program, and quickly plot all the variables at once. Excel's scatter plot function will automatically plot each column against the first column, so if you make sure the first variable sent is the time, things will plot nicely with the default settings.
After some experimentation, I was able to get the performance shown below from my PI controller. Now I'm ready to do a more accurate temperature calibration: I can set the feedback controller to a specific setpoint based on the thermistor A/D value, fill the baking pan partway with water and suspend a thermometer in it, and wait until the controller reaches steady state (zero error for at least 2 cycles). Now I know that this particular thermistor value corresponds to a particular temperature. If I do this twice or better yet three times, I can plot them and draw a line which gives me my conversion equation! Keep in mind that your thermistor won't be terribly linear over a broad range of temperatures, so focus on making sure that your curve fit matches your data exactly at the desired setpoint. Some errors at other temperatures are fine, the feedback controller will still work.
Step 5: Turning the Stirrer Into an Auger
I found that material on the bottom became pulverized and wet while things on top remained chunky and were dried out, so I decided to upgrade the stirrers into proper augers. Here's how:
1) Bend a section of your coat hanger into a spiral. This worked best for me if I held the beer bottle by the neck in my left hand, pinning down the starting end of the coat hanger with my thumb, and wrapped the wire around the bottle with my right hand. The beer bottle should be a bit smaller than the desired diameter of the spiral.
2) Drill holes in your stirrer: 1 near the outside edge, from which the spiral will start, and 1 near the top inside edge, which will be used to anchor the coat hanger.
3) Work the end of the spiral through the outer hole. Then make 2 90 degree bends, so that the wire makes a J shape that lets the free end line up with the inner hole.
4) It doesn't have to line up perfectly: start sliding the J back through the first hole so the tip approaches the inside hole. Start the tip into the inside hole, and use pliers to bend out the bottom of the J to adjust for the misaligment.
5) Once you've forced the the J back through the holes so the bottom is up against the stirrer, bend the free end straight down as hard as you can to lock things in place, and cut it off so it won't scrape the bottom of the bread pan.
At this point the 2 holes in the stirrer and the tip of the hanger wire should form the biggest triangle that will fit on the side of the stirrer, providing the greatest stability in anchoring the spiral.
Finally, bend over the top tip of the wire spiral so you don't have a dangerous poky thing hiding in your compost. After replacing the stirrer in the bread pan and testing, you may find that you want to shorten the spiral so it can't chuck things over the side of the pan.
Step 6: Finishing Touches, Care and Feeding
As a finishing touch, put some creative signage on the side of your machine and/or the LCD so people know what they're looking at and how to use it. (Although, it can be fun to watch the look on your co-habitants' faces when they open the lid for the first time expecting to see some form of bread.) Specifically, it's very helpful to make sure added material is cut to no larger than about 2" in length for efficient composting and to avoid spillovers when the augers run. You also want to avoid unusually woody or stiff materials, but that shouldn't come up too often in the kitchen.
You'll have to experiment, but Mr. Compost should be able to handle more things than normal vermicomposting or composting, such as meat (no bones), dairy, and citrus.
When should you empty Mr. Compost? When it gets full (silly), or when the contents look fairly decomposed and are getting dried out.
The last picture below shows the results of adding stuff for about a week, with the temperature closer to 120 F and the original stirrers. You can see that the stuff from the bottom is much more broken down.
We have a be nice policy.
Please be positive and constructive.