Hi, I want to add blinking to my led, without using delay that will interrupt the overall system. The main loop has delay 3s, which will read temperature from sensor every 3s. I had try using example of "led blinking without delay", it was able to blink, but the blinking interval is not correct, it follows main loop delay, which not what I want.
I want the led to blink every 100ms in the 3s delay main loop. Any ideas?
//declare variables
int buzzer = 5;
int yellow1 = 3; //warning temp
int red1 = 4; // overtemp
int red = 2; // 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("02"); //xbee 2
voltage = analogRead(flamePin);
voltage = (5.0*voltage)/1023.0;
Serial.print("0");
Serial.print((byte)voltage);
Serial.println("04"); //flame sensor from xbee2
////////////////////////////////////////////////////////////
if (tempC>34) //overtemp
{
if (voltage <= 3) //there is flame and temp >40, give fire alert!
{
digitalWrite (red1, HIGH); //overtemp
digitalWrite (yellow1, LOW); //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 (yellow1, LOW); //overtemp
digitalWrite (red1, HIGH); //high temp alert
digitalWrite (buzzer, LOW); //no alert
}
}
//////////////////////////////////////////////////////////////
else if ((tempC > 30) && (tempC <= 34)) //warning temp range
{
if (voltage <= 3) //there is flame and temp n warning range
{
digitalWrite (yellow1, HIGH); //overtemp
digitalWrite (red1, LOW); //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 (red1, LOW); //overtemp
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 (red1, LOW); //overtemp
digitalWrite (buzzer, LOW); //no alert
}
delay(3000);
}