Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
txt
Arduino-controlled crockpot thermostat, aka DIY yogurt maker.
By Chris Reilly
http://www.rainbowlazer.com
This program controls a relay that switches on an electric heating element (eg, crockpot) to control
temperature for fermentation processes.
The relay state is set based on readings from a thermistor which approximate the temperature of the heating
element.
The setup() function controls the stages of temperature for making yogurt.
After adding powdered nonfat milk to liquid milk in glass canning containers, a water bath is set up in the
heater, and the thermistor is placed in the bath.
Stage 1 heats milk to 185F, to sterilize & denature enzymes in the milk.
During this stage it's useful to cover the heating element with insulation such as towels to allow for
faster/more efficient heating.
The temp will hold at 185F for ten minutes, then stage one ends.
At the end of stage one, the buzzer will signal for one minute.
Stage 2 cools the milk to 110F. During this stage it's useful to remove the cover and insulation from the
heating element to allow for faster cooling.
As soon as the temp reaches 110F, the buzzer will signal. The temp will hold at 110F for ten minutes, then
stage two ends.
Yogurt or starter culture is added and containers sealed at the end of stage 2.
Stage 3 incubates the yogurt at 100F for 8 hours. This time can be increased to taste and will result in more
sour yogurt.
After holding, the heating element will be shut off. At the end of stage 3, the alarm will sound for 10 minutes, at
which point the yogurt containers should be refrigerated.
The serial monitor can be used for temperature readouts and feedback on what the program is doing.
*/
#include <EEPROM.h>
#include <math.h>
double Vout = sensorVal * (Vin/1024); //convert the ADC reading from the analog pin into a voltage. We'll
need this to calculate the thermistor's resistance next
R1 = ((R2 * Vin) / (Vout)) - R2; //calculate resistance from the analogread value. See this page for more
info: http://en.wikipedia.org/wiki/Voltage_divider
return temp;
}
Serial.print(":");
//loop the temp checking/relay control function until the target temp is reached, then hold for the amount of
time specified in holdFor
//the while statement will loop forever, until the target temperature is reached
//once that happens, millis are used to count from startTime to startTime plus the length of holdFor
while (millis() * tempReached <= (startTime + holdFor * 1000) * tempReached) {
sensorValue = analogRead(sensorPin); //get the resistance reading from the thermistor
if (thermistor_read(sensorValue) < targetTemp) { //If below target temp, turn the crock pot on
digitalWrite(relayPin, HIGH);
Serial.print("\tRelay is ON");
}
Página 3
ARDUINO YOGUTH.txt
else if (thermistor_read(sensorValue) > targetTemp) { //If above target temp, turn the crock pot off
digitalWrite(relayPin, LOW);
Serial.print("\tRelay is OFF");
}
Serial.println();
}
}
for (long i=0; i < numCycles; i++){ // for the calculated length of time...
if (micros() % (delayValue * 2) < delayValue)
digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
else
digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
}
}
Página 4
ARDUINO YOGUTH.txt
//cycle the tone on and off for a given duration, in seconds.
int buzz(long duration) {
long buzzEnd = millis() + duration * 1000;
int buttonState = digitalRead(buttonPin);
return 0;
}
//Pretty much everything is controlled from setup(), since we don't want the looping that happens in loop()
//
void setup() {
Serial.begin(9600); //open communications over the serial port @ 9600 baud
pinMode(buzzerPin, OUTPUT); // set a pin for buzzer output
pinMode(12, INPUT); // set a pin for pushbutton input
/*
Each one of these if statements below is one stage in the fermentation.
*/
if (go_to_temp(185 /*temp(F)*/, (60 * 10) /*hold(seconds)*/, 0 /*to beep or not to beep during hold time*/) ==
1) {//heat to temp (F) and hold for hold time (seconds)
Serial.println();
Serial.print("Stage 1 (Sterilize) Complete at ");
timestamp(millis());
Serial.println();
Serial.println("Push button to advance.");
Serial.println();
buzz(300); //sometimes we want the alarm to happen after the hold time is complete, like in this case.
}
if (go_to_temp(110 /*temp(F)*/, (60 * 20) /*hold(seconds)*/, 1 /*to beep or not to beep during hold time*/) ==
1) {//heat to temp (F) and hold for hold time (seconds)
Página 5
ARDUINO YOGUTH.txt
Serial.println();
Serial.print("Stage 2 (Cool) Complete at ");
timestamp(millis());
Serial.println();
Serial.println("Add yogurt/culture and seal containers.");
Serial.println();
}
if (go_to_temp(110 /*temp(F)*/, 25200 /*hold(seconds)*/, 0 /*to beep or not to beep during hold time*/) == 1)
{//heat to temp (F) and hold for hold time (seconds)
Serial.println();
Serial.print("Stage 3 (Incubate) Complete at ");
timestamp(millis());
Serial.println();
Serial.println("Push button to stop buzzer.");
Serial.println();
// buzz(600);
}
}
Página 6