RGB LED turns red after use [SOLVED]

I am not sure if this is a hardware issue or a coding issue at the moment.
Basically, my code is supposed to take a temperature each time I press a button and the RGB LED is supposed to change color depending on the temperature recorded.
The program works fine, however after the 3 second delay, instead of all pins returning to low, the red pin will go to high for three seconds, then return to low.
I am currently using an Arduino UNO with a breadboard. I have pin 9 assigned to the red pin, pin 10 assigned to the green pin, and pin 11 assigned to the blue pin. Pin 2 is associated with my button and my temperature probe is assigned to analog pin 0. The whole thing is grounded and powered with 5V.
My program is included below.
Is this a hardware or software issue?

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;
int DISPLAY_TIME = 3000;

const int temperaturePin = 0;
const int button1Pin = 2; 
void setup()
{
 pinMode(RED_PIN, OUTPUT);
 pinMode(GREEN_PIN, OUTPUT);
 pinMode(BLUE_PIN, OUTPUT);
}


void loop()
{
  colorCode();
  pinMode(button1Pin, INPUT);
  Serial.begin(9600);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void colorCode()
{
 int button1State;
  button1State = digitalRead(button1Pin);

if(button1State == HIGH)
 return (analogRead(temperaturePin) * 0.004882814);
  
  float voltage, degreesC, degreesF, degreesK;
  voltage = (analogRead(temperaturePin) * 0.004882814);
  degreesC = (voltage - 0.5) * 100.0;
  degreesF = degreesC * (9.0/5.0) + 32.0;
  degreesK = degreesC + 273.15;
  
  Serial.print("volt: ");
  Serial.print(voltage);
  Serial.print("  deg C: ");
  Serial.print(degreesC);
  Serial.print("  deg F: ");
  Serial.print(degreesF);
  Serial.print(" deg K: ");
  Serial.println(degreesK);
  
if(degreesF <= 70 & degreesF >= 60 )
{ 
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
}
else if(degreesF > 70 & degreesF <= 73)
  {
     digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW); 
  }
else if(degreesF > 73 & degreesF <= 76)
  {
   digitalWrite(RED_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  }
else if(degreesF > 76 & degreesF <= 79);
{
    digitalWrite(RED_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
}
}

Both the schematic and the Fritzing are now attached.

Solution:
The issue was that the code was defaulting the final ‘else if’ function as a default. Adding a default ‘else’ program solved the problem.

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

const int temperaturePin = 0;
const int button1Pin = 2; 
void setup()
{
 pinMode(RED_PIN, OUTPUT);
 pinMode(GREEN_PIN, OUTPUT);
 pinMode(BLUE_PIN, OUTPUT);
   pinMode(button1Pin, INPUT);
  Serial.begin(9600);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void loop()
{
  colorCode();
}

void colorCode()
{
 int button1State;
  button1State = digitalRead(button1Pin);

if(button1State == HIGH)
 (analogRead(temperaturePin) * 0.004882814);
  
  float voltage, degreesC, degreesF, degreesK;
  voltage = (analogRead(temperaturePin) * 0.004882814);
  degreesC = (voltage - 0.5) * 100.0;
  degreesF = degreesC * (9.0/5.0) + 32.0;
  degreesK = degreesC + 273.15;
  
  Serial.print("volt: ");
  Serial.print(voltage);
  Serial.print("  deg C: ");
  Serial.print(degreesC);
  Serial.print("  deg F: ");
  Serial.print(degreesF);
  Serial.print(" deg K: ");
  Serial.println(degreesK);
  
if(degreesF <= 70 & degreesF >= 60 )
{ 
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
}
else if(degreesF > 70 & degreesF <= 73)
  {
     digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW); 
  }
else if(degreesF > 73 & degreesF <= 76)
  {
   digitalWrite(RED_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  }
else if(degreesF > 76 & degreesF <= 79)
  {
    digitalWrite(RED_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  }
else
{
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
}
}

veronica.hayes:
The program works fine

Are you sure? That code you just posted, or did you modify it later. I can't see how that code lights any leds at all.

Please post a schematic. Hand-drawn is OK.

Here is the schematic

Please don't use Fritzing to show your circuit.

Just post a hand drawn diagram.

 pinMode(button1Pin, INPUT);
  Serial.begin(9600);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);

This belongs in setup, not in loop. Once you set pinModes and start serial once, you don't have to keep doing it over and over again.

void colorCode()
{
 int button1State;
  button1State = digitalRead(button1Pin);

if(button1State == HIGH)
 return (analogRead(temperaturePin) * 0.004882814);

return means end the function. So if your button is HIGH, then this will end the function and none of the rest of that code will run. A good C++ tutorial on functions would be good for you to take some time with.

Furthermore, you can't return something from a function with a return type of void. That should have thrown a compiler error or at least a warning.

If not a return, what do you recommend I use? I copied and pasted that part from a sample circuit that came with my board actually....
I moved the other thing into setup, but it is giving me the same red light after its coded light.

Since you obviously misunderstand what return does, I don't know what you intended that line to do. So I can't recommend something different.

I thought the return was needed to output a line into the Serial Monitor because it was within an if statement, despite the fact that it was in a loop.
Basically, I am using that line to tell the program what to output on the serial monitor when I hit a button.
That has always worked. The issue comes with the following if....else if function, where given an output on the serial monitor, being temperature in degrees Fahrenheit, it should output a color given the temperature. This part works.(A switch case would in theory work here too, but this is my third code ever so I didn't want to try that quite yet.)
The issue is that when I run the function, it outputs the correct color before the delay but after the delay, instead of turning off immediately, the RGB turns red before turning off.

Now I guess what could be happening is one of two things;

  1. the last portion of my else if function calls for red. Typically, the else if function will stop when it hits a true statement. Is something in my code preventing this from occurring, or am I just using this function wrong.
  2. maybe it is doing a slow voltage switch because the red is a lower voltage compared to the other two? Not too sure on this one but my point is, is it an issue with my RGB pin itself?

To output to serial monitor use Serial.print

Delta_G:
To output to serial monitor use Serial.print

But if I do that, won't it take temperatures every few seconds as a continuous loop? I just want one read per button press....

Anyways, while doing a continuous read of the temperature (which is fairly consistent in the range yielding purple) the issue is still appearing. During the scan time, the purple light will correctly appear for 3 seconds, but before the next scan is taken, the light turns red for three seconds.
Maybe I just need to change the delay.

It will print when you tell it to print. You can write your code to call print whenever you want.

I think you need some basic C++ tutorials.

Delta_G:
I think you need some basic C++ tutorials.

I know I do actually–this was me extending the tutorial I was doing.
Anyways, I solved it by adding an additional ‘else’ function.
No idea why it was happening.

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

const int temperaturePin = 0;
const int button1Pin = 2; 
void setup()
{
 pinMode(RED_PIN, OUTPUT);
 pinMode(GREEN_PIN, OUTPUT);
 pinMode(BLUE_PIN, OUTPUT);
   pinMode(button1Pin, INPUT);
  Serial.begin(9600);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void loop()
{
  colorCode();
}

void colorCode()
{
 int button1State;
  button1State = digitalRead(button1Pin);

if(button1State == HIGH)
 (analogRead(temperaturePin) * 0.004882814);
  
  float voltage, degreesC, degreesF, degreesK;
  voltage = (analogRead(temperaturePin) * 0.004882814);
  degreesC = (voltage - 0.5) * 100.0;
  degreesF = degreesC * (9.0/5.0) + 32.0;
  degreesK = degreesC + 273.15;
  
  Serial.print("volt: ");
  Serial.print(voltage);
  Serial.print("  deg C: ");
  Serial.print(degreesC);
  Serial.print("  deg F: ");
  Serial.print(degreesF);
  Serial.print(" deg K: ");
  Serial.println(degreesK);
  
if(degreesF <= 70 & degreesF >= 60 )
{ 
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
}
else if(degreesF > 70 & degreesF <= 73)
  {
     digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW); 
  }
else if(degreesF > 73 & degreesF <= 76)
  {
   digitalWrite(RED_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  }
else if(degreesF > 76 & degreesF <= 79)
  {
    digitalWrite(RED_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  delay(3000);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  }
else
{
  digitalWrite(RED_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
}
}

Just because it didn't trip one of the if statements to turn it on it's not going to assume you want it off. You have to explicitly tell it somewhere to turn that LED off.