hi people im having a bit of trouble complying my code for the Arduino. i have built two codes for my Peltier one controlling if for hot and one controlling it for the cold. im wondering if the is any way i can combine the two and have a function which will allow me to switch my tow codes rather than me uploading them at different times.
//peltier for hot
float tempC;
int tempPin = 0; // Temp output plugged into analogue 0
int peltier = 9; // PWM Pin 9 connected to the base of the transistor
int fan = 3;// small fan is connected to pin 5
void setup()
{
Serial.begin(9600);
pinMode(peltier, OUTPUT);
pinMode(fan, OUTPUT);
}
// write loop to tell arduino what to do with temp feed back
void loop()
{
Serial.print(" Temperature= ");
tempC = analogRead(tempPin);
// obtaining temp pin reading and setting it equal to temp C varialble
tempC = (5.0*tempC*100)/1024.0;
// it will convert the analog input to a temperature in celcius
Serial.print((byte)tempC);
// will output the converted temperatur to PC.
if (tempC >45)
{
digitalWrite(fan, HIGH);
digitalWrite(peltier, LOW);
{
delay (500);
}
}
else
{
digitalWrite(fan, LOW);
digitalWrite(peltier, HIGH);
{
delay (1000);
}
}
}
Cold code
// Define Variables
float tempC;
int tempPin = 1; // Temp output plugged into analogue 1
int peltier = 9; // PWM Pin 9 connected to the base of the transistor
int fan = 3;//
void setup()
{
Serial.begin(9600);
pinMode(peltier, OUTPUT);
pinMode(fan, OUTPUT);
}
// write loop to tell arduino what to do with temp feed back
void loop()
{
Serial.print(" Temp= ");
tempC = analogRead(tempPin); // obtaining temp pin reading and setting it equal to temp C varialble
tempC = (5.0*tempC*100)/1024.0; // it will convert the analog input to a temperature in celcius
Serial.print((byte)tempC); // will output the converted temperatur to PC.
if (tempC <25)
{
digitalWrite(fan, LOW);
digitalWrite(peltier, LOW);
}
else
{
digitalWrite(fan, HIGH);
digitalWrite(peltier, HIGH);
}
{
delay (500);
}
}