home distillation project

Hi Guys,
I am building an Arduino based controller for my home brew alcohol distillation project.
I have no idea of how to wright code, or read it, but I have a fair idea of how all the circuitry and hardware are connected. I have basically finished building my project but just get confused when I look at writing a code for it. I'd imagine the code would be a fairly complex one. I need help adding libraries for all the components and tying it all into one code.
I'll try to explain what hardware I have so far and the functions i want the project to perform. I really need help with this as its starting to do my head in, i've gone round & round with searches & havn't had much luck getting anywhere. I'll need patience & commitment from you as i'm only new at this, & I think it may take a bit of trial & error. At the moment, I have to basically sit with the still to keep an eye on the temperature of the cooling head so that the alcohol condensates at a constant rate, plus perform other operations such as turn on a cooling system when a certain temp. is reached, separate the heads, Body and tailings of the operation, and for it all to shut down at the finish. Please help me, I'll explain more indepth into the procedure, functions and hardware I have, when I know I have people committed to helping me out.
I want other people to be able to use all this as well, I have only found little segments which could help with my project, no one(to my knowledge) has completed a project like this, the only thing I found close was home brew beer manufacture with temperature & flow control. :slight_smile:

Perhaps you can find some local help if you give some idea of where you are.

I'm sure some moderator will move this to "Gigs and Collaboration".

Thanks for your reply John. I think what I need to do is study c++ & learn how to do it myself. At least then I'll be able to say that I completed the whole project. If I get stuck along the way I'll have some code already which would be easier to seek help.

Hi,
as an arduino cannot brew anything the first thing to think about should be: What are the devices, sensors and perhaps displays you want to connect?
Than you should design an algorithm. What should your arduino do? when? and how?

When you get this far the third step is to dive into coding and transform your algorithm into an arduino code. It gets easier to understand, when you split your code into independant sub-programs first, merging them together in a fourth step. When you are able to read a temperature AND you are able to control a heater it is an easy task to control a heater based on the temperature.

Kevin

Thanks KevinT, I had actually thought of doing this but didn't know it was called an algorithm. I was planning on writing up all of the functions as comments ( //...) then filling in the all the code in between after. You have supported an idea which I think is my best plan of attack. Cheers mate.

There's a technique called pseudocode where you put the steps down and then expand on them as you go. Something like

turn on hotplate
check temperature
if boiling (temperature >= bp of alcohol), turn off hotplate

That kind of thing. You'll want to do things like check the temperature to be sure it hasn't risen above the boiling point of alcohol because that will mean you're done. If you're using some kind of reflux device, you may want to monitor the flow rate of the distillate and reduce heat if it gets going to fast. You'll probably want to monitor the liquid level in the main body to be sure it doesn't get to low as a failsafe and maybe the catch bucket (or whatever) to be sure it doesn't run over.

I recommend you do a batch by hand and take notes of EVERYTHING you do and then think about automating it. When you get part of it automated like the temperature control, you can expand your project like KevinT suggested. It's easier to keep adding things once you have something (pretty much anything) working.

From the description of what you're automating I think you'd be better served by just buying a couple off-the-shelf temperature controllers. You can find these on eBay.

For a "Getting started with (Arduino) programming" guide, may I commend my...

It won't immediately tell you how to do the thing you are after... but it will get you going, give you the tools.

Distillation of alcohol should be done with care

FYI: The department of Alcohol Tobacco and Firearms (ATF) will give you a premit to distill up to 10,000 gallons of ethanol per year.

Ethanol can be used do fuel your flex vehical, with a minor adjustment to the engine control calibration.

Maybe this project should be turned toward a more universal problem which is fuel for your car or truck.

This is just an opinion from someone who has been there and done that.

Building a PID controller is your goal. You can purchase them from several sources and re-sellers. Blichman Engineering comes to mind, based in Lafayette Indiana. Just do a web searh for PID controllers and you'll see the various manufacturers.

After you discover the detail that is needed to build a good PID temperature controller you may also discover that you are embarking on a one or two year project. The temperature proble for instance must be able to deliver the accuracy that you need to maintain a constant temperature plus or minus 0.1 degree F. You'll need to write code that builds a closed loop system where you constantly read the temperature and change the heat source to adjust the temp up/down. Like Chagrin said, you should probably buy these.

Then you have to decide whether the heating source should be gas or electric. If you choose gas, then your best path would be to purchase one. The gas burner controls are heavy with safety features that you do not want to learn about the hard way. If you go with electric heat, then you are going to have to build or purchase a high power SSR (Solid State Relay) that you can control with PWM.

Good luck with the project. Take the first year learning how to build any kind of control with the Arduino. That will give you enough experience to know whether you will need an UNO or a Mega2560.

Ok guys, this project is coming along quite nicely. I'm starting to understand how c++ works, but not entirely. I have come to a point where I am a bit stumped and I guess now is the time to seek help. The code i have, has no problems compiling or uploading, but the trouble with it is such that the servo's just keep cycling back & forth. The job servo2 has is basically like a soliniod valve but I have a hobby servo attached to the top of a 90 degree ball valve type tap to control coolant flow according to temperature. It seems like a fairly basic concept which I tried diong with a series of if & else statements. This is the hardware I want to use because of the way i have the cooling system set up. I have already made a coolant resivior with a pump, radiator,fans and said servo tap. I have planned this project for a long time now, so some of my hardware may seem out-dated. I'm using the Alpha 0022 IDE as my libraries were adapted to that. There is nothing wrong with my circuit as it was all tested with small sketches such as servo_sweep e.t.c. The two K-type thermocouples are both working fine,as is the temp readings on the shifted out 16x2 LCD. I'm not sure if the "temperature1" & "temperature2" are getting data from "thermocouple1" & "thermocouple2", which I'm guessing they should be attached with an 'int' or a statement in the void setup. The big series of 'if' & 'else statements to control the servo-valve/tap might look a bit messy but all this is very hard for me to understand as I'm new to this. The only info I could find on temp-controlled servo's would only perform a full open or full shut type procedure, which is no good for this project. If you've taken the time to read this far, please take the time to read my code & help fix it. You'll notice I hav'nt added any comments in there. The reason for this is, I thought that if someone has no idea of how electronics, coding & distillation work, then they probabaly shouldn't be messing with it. Therefore they would have trouble understanding my code.

code:-
#include <Servo.h>
#include <max6675.h>
#include <ShiftLCD.h>

int thermoDO = 7;
int thermoCS = 6;
int thermoCLK = 4;
int thermoDO2 = 8;
int thermoCS2 = 9;
int thermoCLK2 = 10;
int units = 1;
int relay1 = 1;
int relay2 = 2;
int button = A0;
int pos = 0;
float temperature1 = 0.0;
float temperature2 = 0.0;
Servo servo1;
Servo servo2;

MAX6675 thermocouple1(thermoCLK, thermoCS, thermoDO);
MAX6675 thermocouple2(thermoCLK2, thermoCS2, thermoDO2);

ShiftLCD lcd(11, 13, 12);

uint8_t degree[8] = {140,146,146,140,128,128,128,128};

void setup() {
Serial.begin(9600);

lcd.begin(16, 2);
lcd.createChar(0, degree);
servo1.attach(3);
servo2.attach(5);
pinMode(button, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
delay(1000);
}

void loop() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TEMP.1");
lcd.print(" ");
lcd.print(thermocouple1.readCelsius());
lcd.print(0, BYTE);
lcd.print("C ");
lcd.setCursor(0, 1);
lcd.print("TEMP.2");
lcd.print(" ");
lcd.print(thermocouple2.readCelsius());
lcd.print(0, BYTE);
lcd.print("C ");

delay(1000);

if (temperature1 >93)
{
relay1 = (LOW);
}
else
{
relay1 = (HIGH);
}
delay(1000);
if (temperature1 >65)
{
relay2 = (HIGH);
}
else
{
relay2 = (LOW);
}
delay(1000);

if (digitalRead(button) == HIGH)
{
pos = 90;
servo1.write(90);
}
else
{
pos = 120;
servo1.write(120);
}
delay(1000);
if (temperature1 >90)
{
pos = 30;
servo1.write(30);
}
else
{
pos = 90;
servo1.write(90);
}
delay(1000);
//valve starts here
if (temperature2 >15)
{
pos = 180;
servo2.write(180);
}
else
{
pos = 175;
servo2.write(175);
}
delay(1000);
if (temperature2 >18)
{
pos = 175;
servo2.write(175);
}
else
{
pos = 170;
servo2.write(170);
}
delay(1000);
if (temperature2 >21)
{
pos = 170;
servo2.write(170);
}
else
{
pos = 165;
servo2.write(165);
}
delay(1000);
if (temperature2 >24)
{
pos = 165;
servo2.write(165);
}
else
{
pos = 160;
servo2.write(160);
}
delay(1000);
if (temperature2 >27)
{
pos = 160;
servo2.write(160);
}
else
{
pos = 155;
servo2.write(155);
}
delay(1000);
if (temperature2 >30)
{
pos = 155;
servo2.write(155);
}
else
{
pos = 150;
servo2.write(150);
}
delay(1000);
if (temperature2 >33)
{
pos = 150;
servo2.write(150);
}
else
{
pos = 145;
servo2.write(145);
}
delay(1000);
if (temperature2 >36)
{
pos = 145;
servo2.write(145);
}
else
{
pos = 140;
servo2.write(140);
}
delay(1000);
if (temperature2 >39)
{
pos = 140;
servo2.write(140);
}
else
{
pos = 135;
servo2.write(135);
}
delay(1000);
if (temperature2 >42)
{
pos = 135;
servo2.write(135);
}
else
{
pos = 130;
servo2.write(130);
}
delay(1000);
if (temperature2 >45)
{
pos = 130;
servo2.write(130);
}
else
{
pos = 125;
servo2.write(125);
}
delay(1000);
if (temperature2 >48)
{
pos = 125;
servo2.write(125);
}
else
{
pos = 120;
servo2.write(120);
}
delay(1000);
if (temperature2 >51)
{
pos = 120;
servo2.write(120);
}
else
{
pos = 115;
servo2.write(115);
}
delay(1000);
if (temperature2 >54)
{
pos = 115;
servo2.write(115);
}
else
{
pos = 110;
servo2.write(110);
}
delay(1000);
if (temperature2 >57)
{
pos = 110;
servo2.write(110);
}
else
{
pos = 105;
servo2.write(105);
}
delay(1000);
if (temperature2 >60)
{
pos = 105;
servo2.write(105);
}
else
{
pos = 100;
servo2.write(100);
}
delay(1000);
if (temperature2 >63)
{
pos = 100;
servo2.write(100);
}
else
{
pos = 95;
servo2.write(95);
}
delay(1000);
if (temperature2 >66)
{
pos = 95;
servo2.write(95);
}
else
{
pos = 90;
servo2.write(90);
}
delay(1000);

}

Hi folks,

Just chiming in. I see a lot of people have read this. Is there anyone out there willing to help?
Does anyone recommend that I apply the comments so they can understand my code a little better?
I've come to a bit stand still with this project, please help. Once I have this all operating properly I plan
to post up pics of everything so that people can be free to copy it.

Can you clearly explain the purposes of relay1, relay2, servo1, servo2?

Pioneer:
The code i have, has no problems compiling or uploading, but the trouble with it is such that the servo's just keep cycling back & forth.

Trying to match flow rates with temperatures is going to be difficult using large if/else constructs. Because there's a delay between the change of the temperature and the influx of new coolant or wash (is that the right term?) it's quite likely that you'll find the valves and heat control constantly swinging back and forth. To avoid this basic problem, read up on PID control, then take a look at this PID controller library. Study it and try to understand it because it's a fundamental subject then give it a shot with some code and ask for help if you get stumped.

Also, when you post code enclode it in CODE tags so it's readable. It will look like: [COWD]my code[/COWD] except with "COWD" spelled "CODE" :wink:

May I also steer you in a slightly different direction?

Have you checked out the Brewtroller project? It's Arduino IDE-based, has a strong user base, and does exactly what you're trying to do, i.e. control fermentation and so on, with debugged custom-designed hardware, etc.

It's maybe not as fun as discovering all the issues for yourself, but may also get you closer quicker to actually controlling the process in question.

They have well-visited forums with very knowledgable folk in all things brewing, so I'd start there, not here.

I can't tell from your code what your physical set up actually is, so I'm going to make some guesses. You have a heating element that will raise the temperature of a fluid to the boiling point of alcohol and then hold it their until the temperature rises sharply (relatively) to indicate that you have distilled all the alcohol out. For this, you only really need one thermometer in the column that measures the temperature of the distillate. The fluid temperature will rise slowly to the BP of alcohol and then stay there for a while until the alcohol rises out of the fluid and through the condenser. When the alcohol is gone, the temperature will rise sharply, at which point, shut it down and reload the boiling flask.

So, you only need to measure the temperature every second or so and you don't need to control the temperature as carefully as it would seem at first glance. I would set up a timer at one or two second intervals (arduino time and TimeAlarm libraries) and check the temperature to control the power to a heating element.

Measuring temperature is a bit of an art, you usually have to smooth it out to prevent things like drafts or random conduction from causing erratic readings. This is usually accomplished by reading the sensor several time and averaging the readings to get a single reading. So it would be a series of analog reads in a row and then averaging them all into a single number. Additionally, people keep a running average of these reading over time to smooth it even further; look for code that keeps a rolling or moving average over several readings. This will smooth it out and give you a nicer temperature curve.

The timealarm library will help you with the complexity of the code because there will be no delays at all. Set a timer to check, it will fire, you check and set a flag to do something in the loop code. You will have a much simpler loop that will be easier to debug.
Something like:

Setup(){
Set a timer for every two seconds
}

loop(){
if (flag)
do something
else
do nothing
}

whenTimerFires(){
check temperature
if (temperature < BP of alcohol)
set flag for heater
else
set flag for no heater
}

That kind of thing.

Thanks for the replies guys.

I did take a look at the 'brewtroller' ages ago, but I don't think it was really what I wanted. It's designed to control the process of kettle brewing
your own beer. I think I remember it having a temperature controlled flow valve of some sort though, so I will take another look at it.
My set-up is basically an urn with a small heating element which is switched on at the start with relay1 'HIGH'. It continues to heat throughout
the whole process until nearly all the alcohol has boiled out at about 93 degrees C, then relay1 will read 'LOW'. Temperature1 is a stainless steel
k-type probe which sits in the top of the still head to basically read the temperature of the distillate throughout the process. It is read by an Adafriut
max6675 breakout. Servo1 has a funnel attached and sits just under the outlet of the condenser. It pivots between three separate storage receptacles.The first is a 1 litre jug which has a float switch at about half way, when it (button) reads high, then servo1 pivots to the next (a 20 litre bucket) which stores the main body of the run until temperature1 reads 90' C, then servo1 goes to the next bucket to collect the tails end of the run until it shuts down. When temperature1 reads 65' C, relay2 reads 'HIGH' which turns on the cooling system, which consists of a large tub with a lid (about 60 litres), an old air-con condenser with a fan, a submersible aquarium pump and a servo controlled ball valve type tap (servo2). I made this tap out of a plastic garden irrigation tap which cost about $2 and mounted the servo to it. This system works perfectly. Hot coolant comes out of the still at about 60' C and when it has flowed through the radiator it has cooled to about 15' C. I'm proud of that as you couldn't ask for much better. The aquarium pump provides a constant pressure.The servo tap (servo2) controls the flow of the coolant (water, or you could probably use glycol for better cooling). The position of servo2 is determined by temperature2 which is also a k-type probe and max6675 chip. Temperature2 probe is placed on the outside of the condenser at a position where I know that, at a certain temperature, the alcohol is condensing at an optimal rate. Each and every setup would be different for this part of the procedure and will have to be fine tuned, But that could be as simple as just moving the probe position a little. I know that some sort of PID control would be best, but I have read that you cant do it with a servo unless you attach a potentiometer to it, and I don't want to have to do that if I can help it. I only want the servo to move in 5 degree intervals so I'm guessing
that it shouldn't be too jittery. You could also use a bilge pump type setup, but having a pump switching on & off to try & control the temperature I think would be harder to control. Same said for a solenoid tap, probably a little easier though but would require more wiring than my servo tap. As for switching the heating element on & off, I would prefer to avoid this also, as I think my small element would take too long to regain the heat and would slow the whole process down, which just isn't very efficient. Plus I don't like the thought of constantly toggling a high current device. I have a 16x 2 LCD to basically just monitor what is going on with temperature1 & temperature2. I can tell how the system is running from this. The arduino will control everything. I just want to be able to turn it on, then come back later and it's all done. At the moment I have to constantly check that its running ok, and that is a pain (long nights & lost sleep). Once this system is up and running, I have a pair of RF transmitter/receivers and a 'Nano' which I will use to make a small device with a 16x2 LCD, which with a quick button press whilst sitting inside, will tell me what the LCD on the master system is reading. I hope all this is enough to explain my setup so I can get some help with my code. Cheers for the help.

It is quite hard to read the long sequential list of if statements.
Try looking at the "case" statement, and consider nesting your if statements.
The structure of your program should make clear what you are trying to achieve, at the moment it does not. That is probably why people are reading but not responding.

Does anyone know if "Pioneer" was able to get the home distilling project automated with the arduino? I'm working on the same thing.