Ping)))

Have you tried here?

AWOL:
Have you tried here?

Why?

The language barrier might be a good deal lower there.

yes i understand that but theres almost no activity on that topic!

Where is the code that you are using to get any data from the sensor?

PaulS:
Where is the code that you are using to get any data from the sensor?

Thats the problem! I don't have that.

If you want answers, it is best not to lock the thread.

I'm sorry i was just trying something.

http://playground.arduino.cc//Main/InterfacingWithHardware#DistanceSensing
has code to deal with a wide variety of distance measuring sensors.

Tanks,

But is it possible to add 1 to the totalcount when the distance is to short.

Caryl

Yes.

Why don't you try some examples and see if it'll do waht you want?

But is it possible to add 1 to the totalcount when the distance is to short.

Of course. The question is whether you want to increment the counter repeatedly if the distance goes below some value, or only once each time the distance goes below some value?

If this is for a elementary school, you can be sure that someone will just play games until the count goes high enough.

PaulS:

But is it possible to add 1 to the totalcount when the distance is to short.

Of course. The question is whether you want to increment the counter repeatedly if the distance goes below some value, or only once each time the distance goes below some value?

If this is for a elementary school, you can be sure that someone will just play games until the count goes high enough.

When a clot goes along the Ping))), the ping))) wil activate a scanner and a light but this is impossible, we thought we better just count clots of they pass the ping)))

Btw its for a dutch school and I'm 12 years old.

When a clot goes along the Ping))), the ping))) wil activate a scanner and a light but this is impossible, we thought we better just count clots of they pass the ping)))

It's not impossible. But, you need to understand that the ping sensor is an analog sensor (something is x distance away), not a digital sensor (something is close).

So, your sensor is going to return values like 200, 200, 198, 190, 170, 150, 140, 130, 120, 100, 90, 80, 70, 60, 50, 40, 30, 20, 15, 15, 15, 15, 15, 18, 20, 30, 40, 50, 60...

If you decide that any value less than 50 means that something is being thrown away, then 40, 30, 20, 15, 15, 15, 15, 15, 18, 20, 30, and 40 will all mean that something is being thrown away.

If you increment the counter each time you get a reading less than 50, then you would increment the counter 12 times with the sample data I showed.

If you compare the current reading (40, for instance) with the previous reading (50), and increment the counter only when the current reading is less when 50 and the previous reading is not, then with the sample data I showed, the counter would only be incremented once.

If you can increment a counter, then you can do any other action, too, such as starting the scanner and light.

Perhaps now that you see how your sensor works, you can see when you could turn the scanner and light off, too. (The current reading is above the threshold and the previous reading is not.

I'm very happy to see you learning about computer programming at such an early age, if you really are only 12. Computers are not going away, and computer programmers will always be needed.

Look around on the playground, and find code to read your sensor. Start with doing nothing but printing the distance to the serial port. When you get that working, we can work on adding the additional code to increment the counter, if you need help with that. Or, perhaps I've given you enough clues that you can figure something out. If not, don't feel bad. We'll help.

Dear PaulS,

Thank you. I have read about a code: if (........==.......). Can i use this code?

CekstuffertZ

Thank you. I have read about a code: if (........==.......). Can i use this code?

You can, but >= or <= are probably better choices. Expecting an exact value from an analog sensor is not a good idea.

So: if(AnalogRead<40) activate led.

So: if(..........<40) activate led.

Yes, if ..... is the value read from the ping sensor (and 40 is reasonable).

Ohh its that easy!

thank you very much and i have now the right code to use!.