float count = 0;//total count of people who walk by int count2 = 0; //count for a 10 minute period float count3 = 0.01666667;//10 minute periods to the .05 (to the nearest 30 seconds) float avg = 0;//10 minute average int time1 = 0;//10 minute timer unsigned long time2 = 0;//program timer int trigPin = 14; // Trigger const int echoPin = 27; // Echo long duration, cm, inches;//units for measurement bool running = true;//program run time char incomingBytes[10];//# of char read int high = 0;//most people counted in a 10 minute period int low = 100;//least amount of people in a 10 minute period int sensorIn = 0; float second = 0.01666667; //used for avg int total; int top; //used to keep track of 10 minute periods int tenavg[144];//an array to store 10 minute periods int x = 0;//used to help keep track of 10 minute periods void avg2(){ //show data function used in command/enf of program for(int z = 1; z<145;z++){ Serial.print(z); Serial.println(); Serial.print("10 minute count:"); Serial.print(tenavg[z]); Serial.println(); } Serial.print("count: "); Serial.print(count); Serial.print(" 10 Minute Average: "); Serial.print( avg ); Serial.print(" 10 Minute HIGH: "); Serial.print( high ); Serial.print(" 10 Minute LOW: "); Serial.print( low ); //Serial.println(); } void displays(){//10 minute count displayed every 10 minutes Serial.print("Total:"); Serial.print(count); Serial.print("Last 10 Minutes:"); Serial.print(count2); Serial.println(); } void setup() { //set it up //Serial Port begin Serial.begin (230400); //Define inputs and outputs pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { //the main loop //if statement for command if (Serial.available() > 0) { Serial.readBytesUntil('\n', incomingBytes, sizeof(incomingBytes) / sizeof(char) ); avg2();//print the avg Serial.println(); } if(!running)return;//if running is false the program stops time2 = millis();//count the time since program started //time3 = millis(); // The sensor is triggered by a HIGH pulse of 10 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(trigPin, LOW); delayMicroseconds(5); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the signal from the sensor: a HIGH pulse whose // duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); // Convert the time into a distance cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343 inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135 time1 = time1 + 1; if(cm < 100){count = count + 1;//within 100cm then count person count2 = count2 + 1; total = count; Serial.print("count"); Serial.print(count); Serial.println(); } if(count2 < low && time1==600){ //low changing low = count2; } if(count2 > high && time1==600){ //high changing high = count2; } if(time1 == 600){ top = count2; //keep track of 10 minutes displays(); time1 = 0; count2 = 0; x = x + 1; tenavg[x] = top; //logging last 10 minute count } avg = count/count3; //avg counting avg = avg * 10;//10 minutes count3 = count3 + (second);//count3 tracking seconds passed if (time2 >= 86400000){// the program reaches 24 hours avg2();//display the data running = false;//end program } delay(1000); }