On line 27 if I uncomment it the program will loop once or sometimes twice and thats it. As soon as I comment it out the programm loops with just the 1 second delay while the hall effect sensor is timing pulses.
I've moved it up into the main void loop, moved it to the top, moved it to the bottom. I cant figure out why it kills the program? No matter where I put in the additional delay it dies. But I have many other sketches that have multiple delays with no problem.
Any Processing gurus have an idea?
//Dry Remote Arduino Dingle Dongle for GroPI5000 (CO2, Temp, Humidity, Flood Alert)
int AirtemperaturePin = 3; //Air temp connected to analog 3
int airtempsensorvalue = 0; //Air Temp Sensor Value
int airtemperature = 0; //Air Temp
int CO2Pin = 4; //CO2 Sensor Pin
int CO2SensorValue = 0; //CO2 Sensor Value
int CO2LevelValue = 0; //CO2 Level Value
int FloodValue = 0; //Flood Sensor value
int FloodPin = 5; //Flood Sensor Pin
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2; //The pin location of the sensor
void rpm () //This is the function that the interupt calls
{
NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}
void setup() // run once, when the sketch starts
{
Serial.begin(9600); //This is the setup function where the serial port is initialised,
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
void loop() { // run over and over again
doDryDingleDongle();
//delay (5000); //Wait 5 seconds --- THIS DOESNT WORK
}
void doDryDingleDongle()
{
///////// Water Flow Meter
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line
// Air Temp
airtempsensorvalue=analogRead(AirtemperaturePin);//Connect LM35 on Analog 3
airtemperature=(500*airtempsensorvalue)>>10;
airtemperature = (airtemperature * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Serial.print("Air Temp:");
Serial.print(airtemperature); //printing the result
Serial.print(" / ");
Serial.print("Pin Reading:");
Serial.println(airtempsensorvalue);
/////////////////////////////////// // CO2
CO2SensorValue = analogRead(CO2Pin);
CO2LevelValue = map(CO2SensorValue, 0, 1023, 0, 2000); ;
Serial.print("CO2:");
Serial.print(CO2LevelValue); //printing the result
Serial.print(" / ");
Serial.print("Pin Reading:");
Serial.println(CO2SensorValue);
Serial.println("---------------------------------");
}