Hello friends. I am trying to use the LM35 to take the temperature value to the LCD screen and to use the two distance sensors to do the counting. The distance sensors work separately well, the first sensor increases the number of people according to the specified distance, and the second decreases the number of people. My problem is that I can not use two distance sensors together, they are continuously increasing when they are working together. I expect your answers, thank you.

Last edited by jwoo on Mon Jan 01, 2018 1:48 pm; edited 2 times in total

Ttelmah

Joined: 11 Mar 2010Posts: 14081

Posted: Fri Dec 22, 2017 9:46 am

Each will 'see' the signal from the other. This is inherent. Think about an echo in a room. One sound source, one echo. However if you have two sound sources you will hear the echo from one, and also the echo (and the sound itself) from the other.

You can use multiple sensors (provided they are aimed away from each other), by using time. You pulse one, and wait for it to see it's reply, then pulse the next and get it's reply. With a time gap between the sensors. The time gap needs to be long enough for all echoes from the first to have ceased before you look at the second.

jwoo

Joined: 22 Dec 2017Posts: 5

Posted: Sat Dec 23, 2017 8:52 am

Ttelmah wrote:

You can use multiple sensors (provided they are aimed away from each other), by using time. You pulse one, and wait for it to see it's reply, then pulse the next and get it's reply. With a time gap between the sensors. The time gap needs to be long enough for all echoes from the first to have ceased before you look at the second.

I tried it with delay command, but again I did not succeed, the number of people on the screen constantly increases and decreases. So the sum value equals 0.

Mike Walne

Joined: 19 Feb 2004Posts: 1758Location: Boston Spa UK

Posted: Sat Dec 23, 2017 9:42 am

How are you implementing "delay command" ?

You've got two people counts which sum to zero.
Where do you get negative people from?

By doing this you make main() code easier to read and debug. Also helps us 'old guys' figure out why your code doesn't work !

Jay

Ttelmah

Joined: 11 Mar 2010Posts: 14081

Posted: Sat Dec 23, 2017 11:51 am

Also:

Code:

set_tris_b(0b00000010); //RB1 as a input
set_tris_b(0b00001000); //RB3 as a input

You do realise that TRIS is not cumulative?. The second function overrides the first....
To set RB1 and RB3 as inputs you want:

Code:

set_tris_b(0b00001010); //RB3 & RB1 as a inputs

You have RB1 actually set as an output. No wonder the second module doesn't actually work....

temtronic

Joined: 01 Jul 2010Posts: 6549Location: Greensville,Ontario

Posted: Sat Dec 23, 2017 12:37 pm

THAT'S the problem with trying to be 'clever' and use 'fast_IO()' unless you get it right you'll cause hours if not DAYS of pain trying to code/recode/recompile/retest/repeat...to get even the simplest code to work.
The ONLY time you need to use fast_IO is a) very,very time critical code and/or b) very small codespace( small program memory )

jwoo

Joined: 22 Dec 2017Posts: 5

Posted: Thu Dec 28, 2017 12:49 pm

Thank you for your answers. I used an old function on the site to calculate the distance, and the system works fine with the delay when I use it. However, I don't want the second sensor to work on the first sensor job, or I don't want the first sensor to run when the second sensor runs. How can I do that?

What you post now ought to work. Unless I'm missing something.
Unless you physically switch the sensor supplies off, they are always going to hear the other signal, but with the delays between this doesn't matter. You would have to use different sensors for them not to hear each other.

There are some timing problems possible because of using the variable for the pin names. Understand that it takes a lot of clock cycles to use a variable like this, so (for instance) the actual trigger pulse width will be much longer than required. Similarly the tests will have extra delays.
Honestly, just use the standard function without variables and generate two copies for the different pins.