/****************************************** Pellet stove tank level alert www.magicmanu.com ******************************************/ #define echoPin 7 // Echo Pin #define trigPin 8 // Trigger Pin int maximumRange = 200; // Maximum range needed int minimumRange = 0; // Minimum range needed long duration, distance; // Duration used to calculate distance #define buzzer 2 //the pin of the active buzzer #define push 1 #define led 3 long TimeRef = 0; int Cycle = 600000; int cms = 0; void setup() { //Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results. pinMode (trigPin, OUTPUT); pinMode (echoPin, INPUT); pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output pinMode(led,OUTPUT);//led pinMode(push,INPUT_PULLUP);// poussoir BipBip(); } void loop() { bool StatePush = digitalRead(push); if (StatePush == LOW) TimeRef = 0; Cycle = millis() - TimeRef; if (Cycle > 600000){ digitalWrite(led,HIGH); delay(200);//wait for 2ms digitalWrite(led,LOW); // Read the distance digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); //Calculate the distance (in cm) based on the speed of sound. cms = duration/58.2; if (cms > 45 and cms < 70) BipBip(); TimeRef = millis(); } } void BipBip() { digitalWrite(buzzer,HIGH); delay(100);//wait for 1ms digitalWrite(buzzer,LOW); delay(100);//wait for 1ms digitalWrite(buzzer,HIGH); delay(100);//wait for 1ms digitalWrite(buzzer,LOW); }