Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Data wire is plugged into port 2 on the Arduino
- #define SHORT_TEMP_FIRST_SENSOR 0
- #define SHORT_TEMP_SECOND_SENSOR 1
- #define LONG_TEMP_SENSOR 2
- #define OUTSIDE_TEMP_SENSOR 3
- int shortFirstSensorInput;
- int shortSensorInput;
- int longSensorInput;
- int outsideSensorInput;
- double tempFirstShot;
- double tempShort;
- double tempLong;
- double tempOutside;
- double tempFirstShotResult;
- double tempShortResult;
- double tempLongResult;
- double tempOutsideResult;
- int cycleCounter;
- int outCounter;
- /*
- * The setup function. We only start the sensors here
- */
- void setup(void)
- {
- // start serial port
- Serial.begin(9600);
- }
- /*
- * Main function, get and show the temperature
- */
- void loop(void)
- {
- shortFirstSensorInput = analogRead(SHORT_TEMP_FIRST_SENSOR);
- shortSensorInput = analogRead(SHORT_TEMP_SECOND_SENSOR);
- longSensorInput = analogRead(LONG_TEMP_SENSOR);
- outsideSensorInput = analogRead(OUTSIDE_TEMP_SENSOR);
- tempFirstShot = (double)shortFirstSensorInput / 1024; //find percentage of input reading
- tempFirstShot = tempFirstShot * 5; //multiply by 5V to get voltage
- tempFirstShot = tempFirstShot - 0.5; //Subtract the offset
- tempFirstShot = tempFirstShot * 100; //Convert to degrees
- tempShort = (double)shortSensorInput / 1024; //find percentage of input reading
- tempShort = tempShort * 5; //multiply by 5V to get voltage
- tempShort = tempShort - 0.5; //Subtract the offset
- tempShort = tempShort * 100; //Convert to degrees
- tempLong = (double)longSensorInput / 1024; //find percentage of input reading
- tempLong = tempLong * 5; //multiply by 5V to get voltage
- tempLong = tempLong - 0.5; //Subtract the offset
- tempLong = tempLong * 100;
- tempOutside = (double)outsideSensorInput / 1024; //find percentage of input reading
- tempOutside = tempOutside * 5; //multiply by 5V to get voltage
- tempOutside = tempOutside - 0.5; //Subtract the offset
- tempOutside = tempOutside * 100;
- tempFirstShotResult+= tempFirstShot;
- tempShortResult+= tempShort;
- tempLongResult+= tempLong;
- tempOutsideResult+= tempOutside;
- cycleCounter++;
- if (cycleCounter == 30)
- {
- outCounter++;
- Serial.print(outCounter);
- Serial.print(" ");
- //Serial.print("OBR_TEMP = ");
- Serial.print(tempFirstShotResult / 30);
- Serial.print(" ");
- //Serial.print("POD_TEMP = ");
- Serial.print(tempShortResult / 30);
- Serial.print(" ");
- //Serial.print("HSE_TEMP = ");
- Serial.print(tempLongResult / 30);
- Serial.print(" ");
- //Serial.print("OUT_TEMP = ");
- Serial.println(tempOutsideResult / 30);
- cycleCounter = 0;
- tempFirstShotResult = 0;
- tempShortResult = 0;
- tempLongResult = 0;
- tempOutsideResult = 0;
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement