so I need a little help, I want to count the people going in and out of the room, I wanted to do that buy 2 ping sensor. I am able to detect the distance from the 2 ping using this code that I have found here but edited it a little bit

I monitor the values through the serial port and I notice when it changes from 7 but the problem as stated is when ping(1) changes the j-- isn't executed but when ping(2) changes j++ is executedThank you

It should be doing what you want, but since it isn't I am thinking the value of ping(2) is not equal to 7 when ping(1) changes. I would suggest trying the following code to give you more insight into what is happening. Also, this code reads the sensor once then compares the output, your code was reading it twice (once per comparison) which could also be what is throwing off your expectations and reading the sensors once and comparing the output twice will be faster than reading it twice...

Note: don't forget to add declarations for distanceA and distanceB to the top of your sketch. ie:

I knew where the problem is ... the problem was that I should recall the ping method from index 0 ... thats mean ping(0) and ping(1)but I figured that the ultrasonic isn't accurate, it didn't return the exact right result ... sometimes it increments the j index and sometimes not ... i donno why :S