Hello guys, I have a project to measure walking speed. First, I have two sensors, I manage to get speed from sensors distance divided by time spent by people when walk passing sensor 1 to sensor 2.
I have used millis() in this coding, and I am using one pin (pin 2) to be input on arduino for both sensors. So that I can measure speed from both direction.
The problem is, when in any case, someone walks through sensor 1, so it is gonna be ON, while another sensor is not passed by that person. It causes arduino counts all the way until dunno when another sensor ON (to close amount of time used to divide sensor distance).
What I want to do is, if on any case one of the sensor ON, in certain time (for example 1 minute), timer will give HIGH logic to pin 2 (in order to close amount of time used to divide sensor distance).
Siigitchikudo:
The problem is, when in any case, someone walks through sensor 1, so it is gonna be ON, while another sensor is not passed by that person. It causes arduino counts all the way until dunno when another sensor ON (to close amount of time used to divide sensor distance).
once sensor 1 is triggered start a timer (using millis()) if sensor 2 is not passed with a certain time ignor the sensor 1 trigger
It sounds simple. You presumably already save the value of millis() when sensor 1 is passed. So if sensor 2 is not passed within a reasonable time (whatever you decide that is) then stop looking for sensor 2 to be passed and go back to looking for sensor 1 to be passed.
I have used millis() in this coding, and I am using one pin (pin 2) to be input on arduino for both sensors. So that I can measure speed from both direction.
What are the sensors? how do you detect when they are triggered (level, edge, etc)
any reason for not using seperate pins for the sensors - you can then determine which way people are walking?
It sounds simple. You presumably already save the value of millis() when sensor 1 is passed. So if sensor 2 is not passed within a reasonable time (whatever you decide that is) then stop looking for sensor 2 to be passed and go back to looking for sensor 1 to be passed.
I was trying to make "out of range" on monitor display (dot matrix p10), so that if the amount of time is tooooo long (it means like what I have said earlier), speed will not be displayed on monitor.
horace:
What are the sensors? how do you detect when they are triggered (level, edge, etc)
any reason for not using seperate pins for the sensors - you can then determine which way people are walking?
Photoelectric sensor, diffuse reflective type.
When people walk across that light, it will be ON/HIGH.
Could you give me the way to make arduino timer do something, for example:
if (certain time passed){
digitalWrite(2,HIGH);
}
So, even if sensor 1 ON, it will be CLOSED automatically in certain time without sensor 2 being ON.
Thank You
horace:
does it stay HIGH or go low after the person has passed?
2 is an input pin , what do you expect a digitalWrite() to do? digitalWrite() - Arduino Reference
Sorry, it will be LOW if person passes that light. This code works actually, I made it, but still want to make it better by making input HIGH with timer.
Yes, I get it, pin 2 should get 5 Volt to make it HIGH, because it is an input. What I'm trying to do here is could we make an action so that although pin 2 not HIGH but in certain time, it will be back like before something trigger sensor (like after reset button being pressed).
First you really need to use separate pins for each sensor.
Then save the millis() value when sensor 1 is triggered and set a boolean variable to true. Save the millis() value when sensor 2 is triggered, set the boolean to false and do your speed calculation using the 2 values.
Check the elapsed time between the start time and the current value of millis() each time through loop() when timing is taking place (ie when the boolean is true) you can determine whether the timeout period has been exceeded and start looking for input on sensor 1 again
UKHeliBob:
First you really need to use separate pins for each sensor.
Then save the millis() value when sensor 1 is triggered and set a boolean variable to true. Save the millis() value when sensor 2 is triggered, set the boolean to false and do your speed calculation using the 2 values.
Check the elapsed time between the start time and the current value of millis() each time through loop() when timing is taking place (ie when the boolean is true) you can determine whether the timeout period has been exceeded and start looking for input on sensor 1 again
Could i check elapsed time between start and current if using only one input?
I'm using one pin for both sensors is because it can measure speed from both side (same sequence whether people walk from sensor 1 or sensor 2)
UKHeliBob:
How do you differentiate between sensor 1 being triggered and sensor 2 being triggered ?
What happens if a second person walks past sensor 1 before the first one passes sensor 2 ?
There is no difference between those two..In my project every single sensor could be start or stop. Distance between two sensors is about 3 meters, for your question, if that happens, I make some sort of limitation, just like min max for "abnormal" speed, as I said before, I use "Out of Range". It could happen for two reason, first, sensor reading too fast (as your case) or second, sensor reading too slow (could be happened if person walks through sensor 1 and stop without passing sensor 2). What I want is eliminating second reason with timer as I ask in this thread.
If you are prepared to put up with all the limitations of using a single pin for two sensors, assuming that works at all, then do as I suggested in reply #2
UKHeliBob:
If you are prepared to put up with all the limitations of using a single pin for two sensors, assuming that works at all, then do as I suggested in reply #2
I guess my first question would be "How robust must this timing mechanism be?"
Case A: The sensors are on a random sidewalk with random people passing by in random directions
Case B: This is a school project (or such) where a controlled number of people will be sent between the sensors as a exercise / test.
You might make case B work with a simple set of sensors and a timer as long as there is sufficient control over the number and behavior of the entrants into the timing region.
Case A will be far more complicated and I suspect you'll need more than you've described -- because you'll have to account for people entering the timing region from one direction and then changing directions and exiting through the same sensor, etc.