Breadman Incubator Arduino Code

The following arduino code is for my Modified Bread Machine Incubator project. The display code was not written by me, but was the only example code i was able to cobble together with my working thermistor and relay code that actually worked. I understand a little of it, but not all of it. If someone knows a better way to transmit the temperature from the thermistor to the 7 segment display, then i welcome improvements. Otherwise enjoy. ūüôā

//* Working Code for modified bread machine incubator w/ safety code
//By Andrew Barney
//Loveland, Colorado, USA
//#DIYBIO
//Test code for Display and thermistor
//seems to work...

#include <math.h>
double Temp;
int RelayHOT = 9; //Caution: Heater on Pin 9!
int led = 13; //Led on pin 13

//display code starts here
#define TXDATA  8       // Pin used to transmit data.
#define POT     0       // pin used to read the analog value.
//int potVal=0;
int potVal=Temp;
#define BITTIME 93      // adjusted to obtain 104 milliseconds delay (9600bauds).
//display code ends here

double Thermistor(int RawADC) {
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;            // Convert Kelvin to Celsius
return Temp;
}

void setup() {
Serial.begin(9600); // begin the serial monitor
pinMode(RelayHOT, OUTPUT); //set pin 9 (known as relayHOT - to an output)
pinMode(led, OUTPUT); //Led on pin 13 to correlate when relayHOT is ON!

//display code continued here
 pinMode(TXDATA, OUTPUT);   // initialize the TXDATA pin as an output.
 digitalWrite(TXDATA,HIGH); // TXDATA = 5V when is resting.
 //delay(10);                 //Wait for Serial Display startup.
 sendChar('v');             //Reset the display 0x76.
//display code ends here 
 
 delay(500);  // Delay a bit… (both for display and safe start-up)
}

//display code
void sendChar(char c){
  delayMicroseconds(BITTIME*2);          // wait 2 Stop bits before sending the char
  digitalWrite(TXDATA,LOW);              // low the line
  delayMicroseconds(BITTIME);            // wait Start bit
  for (int i=0; i<8;i++){
    digitalWrite(TXDATA,bitRead(c, i));  // bit out.
    delayMicroseconds(BITTIME);          // wait bit
  }
   digitalWrite(TXDATA,HIGH);            //Return TXDATA pin to "1".
}

//-------------------------------------------------------------------------
void show(String s){
  for(int i=0;i<4;i++){
    sendChar(s[i]);
  }
}
//display code ends

void loop() {
//delay(500); // Delay a bit…
int(Thermistor(analogRead(0)));
//Serial.println(analogRead(A0)); // print the raw analog values (diagnostic purposes only)
//Serial.println(int(Thermistor(analogRead(0))));  // print Celsius temp reading in serial monitor
Serial.println(Temp);
delay(1000);  // wait 1 seconds before sampling temperature again

if (Temp < 37)
{digitalWrite(RelayHOT, HIGH);  //if the temperature is less than 37C, turn on the relay
digitalWrite(led, HIGH);}       //LED indicator

else if (Temp > 37)
{digitalWrite(RelayHOT, LOW);  //if the temperature is greater than 37C, turn the Heater off because it is too hot!
digitalWrite(led, LOW);}

//else if (Temp == 0)
//{digitalWrite(RelayHOT, LOW);  //turn the Heater off!
//digitalWrite(led, LOW);}

//else if (Temp == NAN)
//{digitalWrite(RelayHOT, LOW);  //turn the Heater off!
//digitalWrite(led, LOW);}

else if (analogRead(0) == LOW)  //check if thermistor is plugged in
{digitalWrite(RelayHOT, LOW);  //if it isn't turn the Heater off!
digitalWrite(led, LOW);}

//display code
//potVal= analogRead(0);
//potVal = Thermistor(analogRead(0));
potVal = Temp;
  String strPot = String (potVal);
  while(strPot.length()<4)strPot= " " + strPot;   //format to 4 characters.
  show(strPot);
  //delay(100);  
//display code ends

}

Advertisements

One thought on “Breadman Incubator Arduino Code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s