Temperature controlled device

Hi,

I’m trying to create an automated fishtank for my senior project and my partner and I have ran into a coding problem. We have the below code done, but keep getting error messages that we aren’t able to troubleshoot. What we are trying to do is to get a temperature sensor to be read by the arduino and when it gets below or above a set temperature it will either turn on or off a heater. But we get the following errors

sketch_mar23a:88: error: expected `;’ before 'heater’

#include <OneWire.h>

// DS18S20 Temperature chip i/o

OneWire ds(10); // on pin 10
int heater = 0;

float c2f(float cel) {
return (cel * (9.0/5.0)) + (float)3200;
}

void setup(void) {
// initialize inputs/outputs
// start serial port
Serial.begin(9600);
}

void loop(void){
byte i;
byte present = 0;
byte data[12];
byte addr[8];
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;

if ( !ds.search(addr)) {
// Serial.print(“No more addresses.\n”);
ds.reset_search();
return;
}

// Serial.print(“R=”);
for( i = 0; i < 8; i++) {
// Serial.print(addr*, HEX);*
// Serial.print(" ");

  • }*
  • if ( OneWire::crc8( addr, 7) != addr[7]) {*
  • Serial.print(“CRC is not valid!\n”);*
  • return;*
  • }*
  • if ( addr[0] != 0x28) {*
  • Serial.print(“Device is not a DS18S20 family device.\n”);*
  • return;*
  • }*
  • ds.reset();*
  • ds.select(addr);*
  • ds.write(0x44,1); // start conversion, with parasite power on at the end*
  • delay(1000); // maybe 750ms is enough, maybe not*
  • // we might do a ds.depower() here, but the reset will take care of it.*
  • present = ds.reset();*
  • ds.select(addr); *
  • ds.write(0xBE); // Read Scratchpad*
    // Serial.print(“P=”);
    // Serial.print(present,HEX);
    // Serial.print(" ");
  • for ( i = 0; i < 9; i++) { // we need 9 bytes*
    _ data = ds.read();_
    // Serial.print(data*, HEX);*
    // Serial.print(" ");
    * }*
    // Serial.print(" CRC=");
    // Serial.print( OneWire::crc8( data, 8), HEX);
    // Serial.println();
    * LowByte = data[0];*
    * HighByte = data[1];*
    * TReading = (HighByte << 8) + LowByte;*
    * SignBit = TReading & 0x8000; // test most sig bit*
    * if (SignBit) // negative*
    * {*
    * TReading = (TReading ^ 0xffff) + 1; // 2’s comp*
    * }*
    Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
    // Serial.print("Temp C Raw = ");
    // Serial.print(Tc_100);
    // Serial.print("\n");
    * Tc_100 = c2f(Tc_100);
    _ if(Whole < 76)
    {heater = 1;}
    else (Whole > 79)
    heater = 0; This is where we get the error
    }
    // Serial.print(“Temp F Raw = “);_
    // Serial.print(Tc_100);
    _// Serial.print(”\n”);
    Serial.print("Temp = ");*_

* Whole = (Tc_100 / 100); // separate off the whole and fractional portions*
* Fract = (Tc_100 % 100);
_ if (SignBit) // If its negative*
* {
Serial.print("-");
}
Serial.print(Whole);
Serial.print(".");
if (Fract < 10)
{
Serial.print(“0”);
}
Serial.print(Fract);
Serial.print("\n");*_

}

if(Whole < 76)

{heater = 1;}
  else (Whole > 79)
  heater = 0;        This is where we get the error

you can’t put anything in front of else. To fix it, you must do this:

if(Whole < 76)
  {heater = 1;}
  else
  heater = 0;

but what you want is:

if(Whole <76) 
   {
   heater = 1;
   }
if (Whole > 79)
   {
   heater = 0;
   }
else (Whole > 79)
  heater = 0;

else if

if(Whole < 76)
  {heater = 1;}
  else (Whole > 79)
  heater = 0;         This is where we get the error

Else what?
if(Whole < 76)
{
heater = 1;
}
else if(Whole > 79)
{
heater = 0;
}

Thanks, can't believe I missed that. Now if we wanted that value (either 1/on or 0/off) for the heater to control a pin on the arduino, what would be the best way to do that?

digitalWrite, probably

another update, when we run the code it gives us a temperature reading of 36.6 and that doesn't agree with anything we know of. The ambient temperature is 20C. Any idea what could cause this? We had to switch the temp sensor to a DS18B20 from a DS18S20, but we changed the serial number in the code I posted.