/*
Insutrctions:
Temp control+monitoring
System function set by PB
PB HIGH = yellow LED 200ms flash - Step 1
PB LOW = LED off.
1x Fan PWM input - Step 2
1x FAN digital input - Step 3
+10deg = Alarm = red LED Step 4
*/
//TEMP SET
/* Fan 1 / Fan 2 / Red alarm
<-5: 10% OFF
>/-5 and <0 30% OFF
0 50% OFF
>0 and <5 70% ON
>/5 and <8 80% ON
>/8 and <10 100% ON
>10 100% ON ON
*/
//int ledPin []= {6,9,10,11}
//int [] = {5,A0,A1}
/*
//Define outputs
#define bit1LEDpin 6 //Fan 1 status
#define bit2LEDpin 9 //Fan 2 status
#define bit3LEDpin 10 //System function
#define bit4LEDpin 13 //Over Temp
//Define inputs
const int upButtonPin = 2;
const int downButtonPin = 3;
//Set span to 16
int upButtonState;
int downButtonState;
int counter = 0;
int minValue = 0;
int maxValue = 15;
void setup() {
Serial.begin(9600);
pinMode(bit1LEDpin, OUTPUT);
pinMode(bit2LEDpin, OUTPUT);
pinMode(bit3LEDpin, OUTPUT);
pinMode(bit4LEDpin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Read the analog value
int sensorValue = analogRead(A0);
//Print sensor value
Serial.println(sensorValue);
delay(1); //delay inbetween for stability
int a = (<-5);
analogWrite(A0 = 10%);
int b = (>-5;<-1);
analogWrite (A0 = 30%);
int c = (0);
analogWrite (A0 = 50%);
int d = (>1;<5);
analogWrite(A0 = 70%);
int e = (>5;<8);
analogWrite (A0 = 80%);
int f = (>8;<9);
analogWrite(A0 = 100%);
int g = (10);
analogWrite (A0 = 100%)
digitalWrite(ledPin[6] = HIGH);
digitalWrite(ledPin[22] = HIGH);
}*/
/*// Define pin numbers
const int buttonPin = 5; // Push-button switch
const int yellowLedPin = 10; // Yellow LED
const int fan1Pin = 6; // PWM input for Fan 1
const int fan2Pin = 9; // Digital input for Fan 2
const int redAlarmPin = 11; // Red alarm light
// Define delay values
const int delayOn = 200; // LED on time in milliseconds
const int delayOff = 200; // LED off time in milliseconds
// Define setpoint and temperature tolerance
const int setpoint = 25; // Setpoint temperature in degrees Celsius
const int tolerance = 10; // Temperature tolerance above setpoint
// Variable to store the measured temperature
int temperature = 0;
// Function to simulate temperature reading
int getTemperature() {
// Replace this with your actual temperature sensor reading code
return random(setpoint - 5, setpoint + 15);
}
void setup() {
// Set button pin as input
pinMode(buttonPin, INPUT);
// Set LED pin as output
pinMode(yellowLedPin, OUTPUT);
// Set fan pins as output
pinMode(fan1Pin, OUTPUT);
pinMode(fan2Pin, OUTPUT);
// Set alarm light pin as output
pinMode(redAlarmPin, OUTPUT);
}
void loop() {
// Read button state
int buttonState = digitalRead(buttonPin);
// System Idle (Button HIGH)
if (buttonState == HIGH) {
// Flash yellow LED
digitalWrite(yellowLedPin, HIGH);
delay(delayOn);
digitalWrite(yellowLedPin, LOW);
delay(delayOff);
// Fans and alarm off
analogWrite(fan1Pin, 0); // Turn off Fan 1
digitalWrite(fan2Pin, LOW); // Turn off Fan 2
digitalWrite(redAlarmPin, LOW); // Turn off alarm
} else {
// System Active (Button LOW)
digitalWrite(yellowLedPin, LOW); // Turn off yellow LED
// Read temperature
temperature = getTemperature();
// Temperature Control
if (temperature > setpoint + tolerance) {
// Alarm Condition
digitalWrite(redAlarmPin, HIGH); // Turn on red alarm
// Fan Control
analogWrite(fan1Pin, 255); // Full speed Fan 1
digitalWrite(fan2Pin, HIGH); // Turn on Fan 2
} else if (temperature > setpoint) {
// Fan Control
analogWrite(fan1Pin, 127); // Half speed Fan 1
digitalWrite(fan2Pin, HIGH); // Turn on Fan 2
} else {
// Fan Control
analogWrite(fan1Pin, 0); // Turn off Fan 1
digitalWrite(fan2Pin, LOW); // Turn off Fan 2
digitalWrite(redAlarmPin, LOW); // Turn off alarm
}
}
// Short delay for smoother operation
delay(10);
}*/
/*// Define pins
const int pushButtonPin = 5;
const int fan1Pin = 9;
const int fan2Pin = 6;
const int idleLEDPin = 10;
const int redLEDPin = 11;
// Define analog inputs
const int setPointTempPin = A0;
const int measuredTempPin = A1;
// Define variables
int setPointTemp;
int measuredTemp;
int tempDifference;
bool idleLEDState = false; // Initial state of the idle LED
unsigned long previousMillis = 0;
const long interval = 200; // Flash interval in milliseconds
void setup() {
// Set pin modes
pinMode(pushButtonPin, INPUT);
pinMode(fan1Pin, OUTPUT);
pinMode(fan2Pin, OUTPUT);
pinMode(idleLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
}
void loop() {
// Read the set point and measured temperatures
setPointTemp = analogRead(setPointTempPin);
measuredTemp = analogRead(measuredTempPin);
// Calculate the temperature difference
tempDifference = measuredTemp - setPointTemp;
// Check if the push button is pressed
if (digitalRead(pushButtonPin) == HIGH) {
// Flash yellow LED
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
idleLEDState = !idleLEDState;
digitalWrite(idleLEDPin, idleLEDState);
}
} else {
// Stop flashing and turn off yellow LED
digitalWrite(idleLEDPin, LOW);
idleLEDState = false;
}
// Control fans and red LED based on temperature difference
switch (tempDifference) {
case -5: // Difference less than -5
analogWrite(fan1Pin, 10); // Fan 1 on at 10%
digitalWrite(fan2Pin, LOW); // Fan 2 off
digitalWrite(redLEDPin, LOW); // Red LED off
break;
case -4 ... -1: // Difference greater than -5 and less than 0
analogWrite(fan1Pin, 30); // Fan 1 on at 30%
digitalWrite(fan2Pin, LOW); // Fan 2 off
digitalWrite(redLEDPin, LOW); // Red LED off
break;
case 0: // Difference 0
analogWrite(fan1Pin, 50); // Fan 1 on at 50%
digitalWrite(fan2Pin, LOW); // Fan 2 off
digitalWrite(redLEDPin, LOW); // Red LED off
break;
case 1 ... 4: // Difference greater than 0 and less than 5
analogWrite(fan1Pin, 70); // Fan 1 on at 70%
digitalWrite(fan2Pin, HIGH); // Fan 2 on
digitalWrite(redLEDPin, LOW); // Red LED off
break;
case 5 ... 7: // Difference greater than 5 and less than 8
analogWrite(fan1Pin, 80); // Fan 1 on at 80%
digitalWrite(fan2Pin, HIGH); // Fan 2 on
digitalWrite(redLEDPin, LOW); // Red LED off
break;
case 8 ... 9: // Difference greater than 8 and less than 10
analogWrite(fan1Pin, 100); // Fan 1 on at 100%
digitalWrite(fan2Pin, HIGH); // Fan 2 on
digitalWrite(redLEDPin, LOW); // Red LED off
break;
default: // Difference greater than 10
analogWrite(fan1Pin, 100); // Fan 1 on at 100%
digitalWrite(fan2Pin, HIGH); // Fan 2 on
digitalWrite(redLEDPin, HIGH); // Red LED on
break;
}
delay(10); // Small delay to allow for analog reading stability
}*/
/*
const int pushButtonPin = 5;
const int fan2Pin = 6;
const int fan1Pin = 9;
const int idleLEDPin = 10;
const int redLEDPin = 11;
const int setPointTempPin = A0;
const int measuredTempPin = A1;
bool isIdle = false;
void setup() {
pinMode(pushButtonPin, INPUT);
pinMode(fan2Pin, OUTPUT);
pinMode(fan1Pin, OUTPUT);
pinMode(idleLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
digitalWrite(fan2Pin, LOW);
analogWrite(fan1Pin, 0);
digitalWrite(idleLEDPin, LOW);
digitalWrite(redLEDPin, LOW);
Serial.begin(9600);
}
void loop() {
int pushButtonState = digitalRead(pushButtonPin);
if (pushButtonState == HIGH) {
isIdle = true;
digitalWrite(fan2Pin, LOW);
analogWrite(fan1Pin, 0);
digitalWrite(redLEDPin, LOW);
unsigned long currentMillis = millis();
static unsigned long previousMillis = 0;
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
digitalWrite(idleLEDPin, !digitalRead(idleLEDPin));
}
} else {
isIdle = false;
digitalWrite(idleLEDPin, LOW);
int setPointTemperature = analogRead(setPointTempPin);
int measuredTemperature = analogRead(measuredTempPin);
int difference = measuredTemperature - setPointTemperature;
Serial.print("Set Point Temp: ");
Serial.print(setPointTemperature);
Serial.print(" Measured Temp: ");
Serial.print(measuredTemperature);
Serial.print(" Difference: ");
Serial.println(difference);
if (difference < -5) {
analogWrite(fan1Pin, 26); // 10% duty cycle
digitalWrite(fan2Pin, LOW);
digitalWrite(redLEDPin, LOW);
} else if (difference >= -5 && difference < 0) {
analogWrite(fan1Pin, 77); // 30% duty cycle
digitalWrite(fan2Pin, LOW);
digitalWrite(redLEDPin, LOW);
} else if (difference == 0) {
analogWrite(fan1Pin, 128); // 50% duty cycle
digitalWrite(fan2Pin, LOW);
digitalWrite(redLEDPin, LOW);
} else if (difference > 0 && difference < 5) {
analogWrite(fan1Pin, 179); // 70% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, LOW);
} else if (difference >= 5 && difference < 8) {
analogWrite(fan1Pin, 204); // 80% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, LOW);
} else if (difference >= 8 && difference < 10) {
analogWrite(fan1Pin, 255); // 100% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, LOW);
} else if (difference >= 10) {
analogWrite(fan1Pin, 255); // 100% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, HIGH);
}
}
}*/
const int pushButtonPin = 5;
const int fan2Pin = 6;
const int fan1Pin = 9;
const int idleLEDPin = 10;
const int redLEDPin = 11;
const int setPointTempPin = A0;
const int measuredTempPin = A1;
bool isIdle = false;
void setup() {
pinMode(pushButtonPin, INPUT);
pinMode(fan2Pin, OUTPUT);
pinMode(fan1Pin, OUTPUT);
pinMode(idleLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
digitalWrite(fan2Pin, LOW);
analogWrite(fan1Pin, 0);
digitalWrite(idleLEDPin, LOW);
digitalWrite(redLEDPin, LOW);
Serial.begin(9600);
}
void loop() {
int pushButtonState = digitalRead(pushButtonPin);
if (pushButtonState == HIGH) {
isIdle = true;
digitalWrite(fan2Pin, LOW);
analogWrite(fan1Pin, 0);
digitalWrite(redLEDPin, LOW);
unsigned long currentMillis = millis();
static unsigned long previousMillis = 0;
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
digitalWrite(idleLEDPin, !digitalRead(idleLEDPin));
}
} else {
isIdle = false;
digitalWrite(idleLEDPin, LOW);
int rawSetPointTemperature = analogRead(setPointTempPin);
int rawMeasuredTemperature = analogRead(measuredTempPin);
int setPointTemperature = map(rawSetPointTemperature, 0, 1023, 20, 40);
int measuredTemperature = map(rawMeasuredTemperature, 0, 1023, 20, 40);
int difference = measuredTemperature - setPointTemperature;
Serial.print("Set Point Temp: ");
Serial.print(setPointTemperature);
Serial.print(" Measured Temp: ");
Serial.print(measuredTemperature);
Serial.print(" Difference: ");
Serial.println(difference);
if (difference < -5) {
analogWrite(fan1Pin, 26); // 10% duty cycle
digitalWrite(fan2Pin, LOW);
digitalWrite(redLEDPin, LOW);
} else if (difference >= -5 && difference < 0) {
analogWrite(fan1Pin, 77); // 30% duty cycle
digitalWrite(fan2Pin, LOW);
digitalWrite(redLEDPin, LOW);
} else if (difference == 0) {
analogWrite(fan1Pin, 128); // 50% duty cycle
digitalWrite(fan2Pin, LOW);
digitalWrite(redLEDPin, LOW);
} else if (difference > 0 && difference < 5) {
analogWrite(fan1Pin, 179); // 70% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, LOW);
} else if (difference >= 5 && difference < 8) {
analogWrite(fan1Pin, 204); // 80% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, LOW);
} else if (difference >= 8 && difference < 10) {
analogWrite(fan1Pin, 255); // 100% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, LOW);
} else if (difference >= 10) {
analogWrite(fan1Pin, 255); // 100% duty cycle
digitalWrite(fan2Pin, HIGH);
digitalWrite(redLEDPin, HIGH);
}
}
}