Home > Uncategorized > Temperature Monitoring Device

Temperature Monitoring Device

January 1st, 2012 Leave a comment Go to comments

LM35 Temperature Sensor

The System.

The monitor.

The mixed water line:

The hot water line:

The cold water line:

monitor opened up:

the atmega8 microcontroller

the lcd unit:

theboard:

inside the monitor:

The AVR code.

const int COLD = 0, HOT = 1, MIXED = 2, CALIBRATE = 3;
const int PWMPORT = 5;

float SCALE = 5000.0/1024.0; // 10 bit resolution for ADC
const float LM35SCALE = 10; // 10mV per Centigrade

#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8 );

byte smiley[8] = {
  B00010,
  B00101,
  B00010,
  B00000,
  B00000,
  B00000,
  B00000,
};

float Calibrate( void )
{
  // write 5v to PWM port
  analogWrite(PWMPORT, 255);

  // read the 5v analog value in the calibrate port
  delay(500);
  int val = analogRead(CALIBRATE);

  // read again the 5v analog value in the calibrate port
  delay(100);
  val = analogRead(CALIBRATE);

  // whatever digital value we read is the range of output that we would get for 5v input.
  // so, set the scale appropriately.
  SCALE = 5000.0/(float)val;
  
  return SCALE;
}

void setup()
{
  pinMode(PWMPORT, OUTPUT);
  
  lcd.createChar(0, smiley);
  lcd.begin(16,2);
  
  lcd.setCursor(0,0);
  lcd.print(“Calibrating..”);
  float scale = Calibrate();
  lcd.setCursor(0,1);
  lcd.print(“Scale=”);
  lcd.print(scale);
  delay(1000);
}

int Temp( int inADC )
{
  float lm35volts = (float)inADC * SCALE;
  float temp = lm35volts/LM35SCALE;
  
  return (int)temp;
}

int ReadData( int port )
{
  int data = -1;
  for ( int i = 0; i < 3; ++i )
  {
    data = analogRead( port );
    delay(100);
  }
  
  return data;
}

void loop()
{
  int cold = ReadData( COLD );
  int hot = ReadData( HOT );
  int mixed= ReadData( MIXED );
  
  int cold_temp = Temp(cold);
  int hot_temp = Temp(hot);
  int mixed_temp = Temp(mixed);
  
  lcd.clear();

  lcd.print( “C=” );
  lcd.print( cold_temp );
  lcd.write(0);
  lcd.print(“C”);
  lcd.print( ” H=” );
  lcd.print( hot_temp );
  lcd.write(0);
  lcd.print(“C”);
  
  lcd.setCursor(0,1);
  lcd.print( “Mixed=” );
  lcd.print( mixed_temp );
  lcd.write(0);
  lcd.print(“C”);
  
  delay(1000);
}

Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.