Step 15Code
int ledPin = 13; // LED is connected to digital pin 13
int sensorPin0 = 0; // temperature sensor is connected to analog pin 0
int sensorValue0; // variable to store the value coming from sensor a0
int sensorPin1 = 1; // temperature sensor is connected to analog pin 1
int sensorValue1; // variable to store the value coming from sensor a1
int sensorPin2 = 2; // temperature sensor is connected to analog pin a2
int sensorValue2; // variable to store the value coming from sensor a2
int sensorPin3 = 3; // temperature sensor is connected to analog pin 3
int sensorValue3; // variable to store the value coming from sensor a3
int sensorPin4 = 4; // temperature sensor is connected to analog pin 4
int sensorValue4; // variable to store the value coming from sensor a4
int sensorPin5 = 5; // temperature sensor is connected to analog pin 5
int sensorValue5; // variable to store the value coming from sensor a5
int fanRelay = 7; // fan relay is connected to digital pin 7
int heatRelay = 3; // heating coil relay is connected to digital pin 6
// Output
int greenPin = 9; // Green LED, connected to digital pin 10
int bluePin = 10; // Blue LED, connected to digital pin 11
int redPin = 11; // Red LED, connected to digital pin 9
// Program variables
int redVal = 255; // Variables to store the values to send to the pins
int greenVal = 0; // Initial values are Red full, Green and Blue off
int blueVal = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
Serial.begin(9600); // initialize the serial port
digitalWrite(ledPin, HIGH); // turn the LED on
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(fanRelay, OUTPUT);
pinMode(heatRelay, OUTPUT);
digitalWrite(fanRelay, LOW); // sets fan relay to off
digitalWrite(heatRelay, LOW); // sets heat coil relay to off
}
void loop() // run over and over again
{
Serial.println("Sensor Values:");
sensorValue0 = analogRead(sensorPin0); // read the value from the sensor
Serial.println(sensorValue0); // send that value to the computer
sensorValue1 = analogRead(sensorPin1); // read the value from the sensor
Serial.println(sensorValue1); // send that value to the computer
sensorValue2 = analogRead(sensorPin2); // read the value from the sensor
Serial.println(sensorValue2); // send that value to the computer
sensorValue3 = analogRead(sensorPin3); // read the value from the sensor
Serial.println(sensorValue3); // send that value to the computer
sensorValue4 = analogRead(sensorPin4); // read the value from the sensor
Serial.println(sensorValue4); // send that value to the computer
sensorValue5 = analogRead(sensorPin5); // read the value from the sensor
Serial.println(sensorValue5); // send that value to the computer
int sensorAverage = (sensorValue0+sensorValue1+sensorValue2+sensorValue3+sensorValue4+sensorValue5)/6; // average the sensor values
if (sensorValue0 < 215) // cold phase of fades
{
if (redVal < 255) redVal +=15; // Red down
if (blueVal > 0) blueVal -=15; // Blue up
}
else if (sensorValue0 > 215) // warm phase of fades
{
if (redVal > 0) redVal -=15; // Red up
if (blueVal < 255) blueVal +=15; // Blue down
}
if (sensorValue0 < 215) // active cold phase
{
digitalWrite(heatRelay, HIGH); // activate heat
digitalWrite(fanRelay, LOW); // deactivate fans
delay(2000); // wait
}
if (sensorValue0 > 215) // active warm phase
{
digitalWrite(heatRelay, LOW); // deactivate heat
digitalWrite(fanRelay, HIGH); // activate cold
delay(2000); // wait
}
//Debug
Serial.println("Sensor Average:"); // send that value to the computer
Serial.println(sensorAverage); // send that value to the computer
Serial.println("Check Color Value:");
Serial.println(redVal);
Serial.println(blueVal);
analogWrite(redPin, redVal); // Write current values to LED pins
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
}
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|


























































