Hi, I am using a sensor to detect temperature, and I'm using a (Red-Yellow) led. I want to display if over temperature it show RED, and warning range temperature, it shows YELLOW. When overtemp change to warning, instead of RED to YELLOW, what I get in return is ORANGE. The led is 3 pin: Red, Ground, Yellow). Anyone try using this led before with arduino? I'm connecting 30ohm to each of the led pin. I'm using LM35 and flame sensor. Below is my coding. It it somewhere wrong in the coding? Thank you very much..
//declare variables
int buzzer = 8;
int yellow1 = 9; //warning temp
int red1 = 7; // overtemp
int red = 6; // red led indicate flame
float tempC;
float voltage;
int tempPin =0; // Temp sensor plugged analog pin 0
int flamePin= 1;
// write setup function
void setup()
{
Serial.begin(9600);// open serial port to communicate with the temp sensor
pinMode(red1, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode (red, OUTPUT);
pinMode (buzzer, OUTPUT);
}
//write loop that will control what we want the arduino to do with the sensor readout
void loop()
{
tempC = analogRead(tempPin); // taking the temp pin reading and setting it equal to tempC variable
tempC = (5.0*tempC*100.0)/1024.0; // will convert the analog input to a temperature in celcius
Serial.print((byte)tempC); //will output the converted temperature to pc
Serial.println("01"); //xbee 2
voltage = analogRead(flamePin);
voltage = (5.0*voltage)/1023.0;
Serial.print("0");
Serial.print((byte)voltage);
Serial.println("03"); //flame sensor from xbee2
//////////////////////////////////////////////////////////////
if ((tempC > 30) && (tempC <= 40)) //warning temp range
{
if (voltage <= 3) //there is flame and temp n warning range
{
digitalWrite (yellow1, HIGH); //overtemp
digitalWrite (red, HIGH); //flame detected
digitalWrite (buzzer, HIGH); //give alert
}
else //warning temp, but no flame, possibility of false alarm
{
digitalWrite(red, LOW); //RED led, no flame alert
digitalWrite (yellow1, HIGH); //high temp alert
digitalWrite (buzzer, LOW); //no alert
}
}
else //not in warning range and no flame
{
digitalWrite(red, LOW); //RED led, no flame alert
digitalWrite (yellow1, LOW); //YELLOW led, no high temp alert
digitalWrite (buzzer, LOW); //no alert
}
////////////////////////////////////////////////////////////
if (tempC>40) //overtemp
{
if (voltage <= 3) //there is flame and temp >40, give fire alert!
{
digitalWrite (red1, HIGH); //overtemp
digitalWrite (red, HIGH); //flame detected
digitalWrite (buzzer, HIGH); //give alert
}
else //temp>40, but no flame, possibility of false alarm
{
digitalWrite(red, LOW); //RED led, no flame alert
digitalWrite (red1, HIGH); //high temp alert
digitalWrite (buzzer, HIGH); //no alert
}
}
delay(3000);
}