//My project is a temperature-based, variable-speed fan with two LEDs, controlled by an Arduino Uno. We were given partial code, and now we must declare an integer, which I did, and now I need to light up the diodes. Fan on is the green LED, fan off is the blue LED. I have to make them light up respectively, but I must be missing those lines of code. A little help please?
// C++ code
//
//Pin Variables
int tempPin = 1;
int tempVal = 0;
int enable = 6;
int dirA = 5;
int dirB = 3;
int motorSpeed = 128;
int fanOnLED = 13;
int fanOffLED = 11;
void setup() {
pinMode(enable, OUTPUT);
pinMode(dirA, OUTPUT);
pinMode(dirB, OUTPUT);
digitalWrite(enable, LOW);
digitalWrite(dirA, LOW);
digitalWrite(dirB, LOW);
digitalWrite(fanOnLED, LOW);
digitalWrite(fanOffLED, LOW);
Serial.begin(9600);
delay(500);
}
void loop() {
// Read the value of the temperature sensor
tempVal = analogRead(tempPin);
// Calculate the sensor reading into millivolts
float mV = (5000.0 * tempVal)/1024;
// Calculate the temperature in Centigrade
float tempC = (mV - 500)/10;
// Print the temperature to the serial monitor
Serial.print("Temperature in C: ");
Serial.print(tempC);
Serial.println();
delay(100);
// If the temperature goes above 25 degrees C, start the fan
if (tempC > 25.0) {
spinMotor(motorSpeed);
}
// If the temperature drops below 25 degrees C, stop the fan
else {
spinMotor(0);
}
}
void spinMotor(int motorSpeed) {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
// Spin the motor forward
analogWrite(enable,abs(motorSpeed));
digitalWrite(dirA, HIGH);
digitalWrite(dirB, LOW);
}
// Can someone help?