Need Help With LED Output

This is my first time using an Arduino and I have everything working except that instead of one LED going on, I have both. I’ll paste my code in below so that anyone can maybe see where my problem is.
I want the yellow LED to go on if the Fahrenheit Temperature is below 70, otherwise the red LED should come on.

The problem I am getting is that they are both coming on and I don’t know why. It’s my first semester in college, so I’m sure it’s something stupid that I’ve done.

//Input

int tempPin = A0;
int temp = 0;
int tempC = 0;
int tempF = 0;
int redLed = 13, yellowLed = 12;

void setup() {
Serial.begin(9600);
pinMode (redLed, OUTPUT); // Red LED for tempF >= 70
pinMode (yellowLed, OUTPUT); // Yellow LED for tempF < 70
}

void loop() {
temp = analogRead(tempPin);
tempC = ((5.0 * temp * 100.0)/1024.0);
tempF = (9.0 * tempC / 5.0 + 32.0);
Serial.print (“Celsius temperature: “);
Serial.print (tempC);
Serial.println (” degrees”);
Serial.print (“Fahrenheit temperature: “);
Serial.print (tempF);
Serial.println (” degress”);
digitalWrite(yellowLed, LOW);
digitalWrite(redLed, LOW);
delay(3000);

if (tempF < 70)
{
digitalWrite(yellowLed, HIGH);
delay(1000);
}
else
{
digitalWrite(redLed, HIGH);
delay(1000);
}
}

Hi, please use code tags rather than quote tags when posting a sketch.

Are both leds on immediately after you reset the Arduino? Can you post a schematic showing how you wired them up.

Paul

johnnyM: The problem I am getting is that they are both coming on and I don't know why.

The "D" in LED stands for "diode", so it does matther how you connect it.

A LED can light up with this connections:

  1. Possibility (normal) Arduino-Output ==> LED-Anode Arduino-GND ==> LED-Cathode LED will be on if output is HIGH

  2. Possibility (not normal, but possible) Arduino-Output ==> LED-Cathode Arduino-5V ==> LED-Anode LED will be on if output is LOW

Please check LED cabling and that each LED has a current limiting resistor!

Thank you jurs. That was my problem. I simply used the first example you gave and it worked. My issue was I was trying to figure out how to put together and LED-only example and a Temperature Sensor-only example and I didn't too too good of a job.

I didn't fully understand the way the connections are made and once I looked at what you wrote and adjusted my connections, it worked! I'm glad I understand the basics now. I'm sure my next project will come much easier.

Thank you very much.

You did put a resistor in line with each LED didn't you, otherwise it will appear to work but damage your arduino.