/* Eric Chut ENGR 103 Final Assignment */ #define SOUND_SPEED 0.034 const unsigned long interval = 600000; // 10 minutes in milliseconds const unsigned long duration = 86400000; // 24 hours in milliseconds float distanceCm;//distance variable void setup() { pinMode(5, OUTPUT);//output pin pinMode(18, INPUT);//input pin Serial.begin(115200);// baud rate } void loop() { unsigned long startTime = millis();//setting the start time variable to match the millis while (millis() - startTime < duration) {//24 hour timer unsigned long intervalStartTime = millis(); while (millis() - intervalStartTime < interval) {//10 minute timer digitalWrite(5, LOW);//sending out a signal to send a sound wave delayMicroseconds(2); digitalWrite(5, HIGH); delayMicroseconds(10); digitalWrite(5, LOW); unsigned long pulseTime = pulseIn(18, HIGH);//records how long it takes for the signal to be bounced back distanceCm = (pulseTime * SOUND_SPEED)/2;//calculating the distance into centimeters Serial.println(distanceCm); if (distanceCm < 150){//alerting that something passed by the sensor Serial.println("something passed by"); } delay(1000); // 1 second delay between readings } // Record the end of the interval Serial.println("Interval ended"); delay(1000); // 1 second delay before starting the next interval } // The 24-hour period has ended Serial.println("Recording finished"); while (true) { // Do nothing } }