However, I can't find the same IR sensor module used in the first project and planning to use another kind of IR sensor. Will it still work if I use the same code provided by the first project?
Below is the code and I've attached the photo for the IR sensor.
Thank you.
The first pic is the one that was used in the project guide I'm trying to work on, however, I can't find it.
The second pic is the one that I plan to using as an alternative.
My question is, will the code still work if I change the IR sensor module? If not, where in the code is that?
Thank you, again.
The code simply digitalRead()s the pins to which the sensors are attached, and the proposed ones look like they have a simple digital output so should be ok.
The diiference may be in whether the proposed sensor works with the same logic as the originals.
In the code, this:
if(digitalRead(in))
... is short-hand for:
if(digitalRead(in)==HIGH)
That means the output of that sensor goes high when it senses something. Some sensors work the other way round, going low when sensing something; I have one like that. It depends on the way it's manufactured.
It's easy to check though. Just apply power to the pins and measure the voltage across out and ground when it's sensing something and when it's clear. If it's logic is upside down, you will just change the line:
if(digitalRead(in))
... which remember is really:
if(digitalRead(in)==HIGH)
... to:
if(digitalRead(in)==LOW)
(There may need to be further discussion on pullup and pulldown resistors but that can probably wait.)
12Stepper:
The code simply digitalRead()s the pins to which the sensors are attached, and the proposed ones look like they have a simple digital output so should be ok.
The diiference may be in whether the proposed sensor works with the same logic as the originals.
In the code, this:
if(digitalRead(in))
... is short-hand for:
if(digitalRead(in)==HIGH)
That means the output of that sensor goes high when it senses something. Some sensors work the other way round, going low when sensing something; I have one like that. It depends on the way it's manufactured.
It's easy to check though. Just apply power to the pins and measure the voltage across out and ground when it's sensing something and when it's clear. If it's logic is upside down, you will just change the line:
if(digitalRead(in))
... which remember is really:
if(digitalRead(in)==HIGH)
... to:
if(digitalRead(in)==LOW)
(There may need to be further discussion on pullup and pulldown resistors but that can probably wait.)
Okay, thanks. From what I've understood, it's supposed to work just fine, right? Also, if the logic is reversed when I used the proposed sensor, I just need to replace the code with ... LOW.
Planning to work on it this week, hope it ends well.
Yeah ... get it working to do it as the link says, and then I think you may uncover some shortcomings in the whole premise of trying to use two sensors to count occupancy like that.
By the way, since a sensor like that is just off or on, high or low, you can test your code with a button. pinMode() as input pullup, and press to pretend someone's in front of the sensor.
12Stepper:
Yeah ... get it working to do it as the link says, and then I think you may uncover some shortcomings in the whole premise of trying to use two sensors to count occupancy like that.
But that's next week's discussion
I was hoping that there will be no shortcomings since the deadline's on 6 already. And need to do a report on it as well.
12Stepper:
By the way, since a sensor like that is just off or on, high or low, you can test your code with a button. pinMode() as input pullup, and press to pretend someone's in front of the sensor.
Sorry, I am lost starting at testing the code with a button.
JinRar:
I was hoping that there will be no shortcomings since the deadline's on 6 already. And need to do a report on it as well.
The shortcomings are something you can put in the report, with perhaps some suggestions for improvement.
JinRar:
I am lost starting at testing the code with a button.
When the sensor is clear, its output is at a level (high or low) as discussed. When it's obstructed, the output's at the other level (low or high).
A button's exactly the same: unpressed it's high or low depending how it's wired; pressed it's at the other lever, low or high.
So in the normal state, the unobstructed sensor is the same as an unpressed button; when active, the obstructed sensor is the same as a pressed button.
You could mimic someone walking in front of the sensor, by pushing the button for the time it takes them to enter and leave the sensor's "zone".
(I just did that with the code you linked, adjusted for the way my buttons are wired.)
12Stepper:
The shortcomings are something you can put in the report, with perhaps some suggestions for improvement.
I see, I thought it would fail to work at some point during the course or something missing that won't allow the project to work. Thanks, I could really put it in the recommendation part.
12Stepper:
When the sensor is clear, its output is at a level (high or low) as discussed. When it's obstructed, the output's at the other level (low or high).
A button's exactly the same: unpressed it's high or low depending how it's wired; pressed it's at the other lever, low or high.
So in the normal state, the unobstructed sensor is the same as an unpressed button; when active, the obstructed sensor is the same as a pressed button.
You could mimic someone walking in front of the sensor, by pushing the button for the time it takes them to enter and leave the sensor's "zone".
(I just did that with the code you linked, adjusted for the way my buttons are wired.)
Oh, its kind of similar to what the man did in the video sample from the link.
We did the project but somehow the IR sensor seems to be not in sync with the LCD display. The display continues to count even though no object passes through. Is the sensor the problem, the LCD, or the code?
Also, if I may, where can I ask for some help regarding signal conditioning using the datasheet? The technical report requires us to do it (signal conditioning) but we have done something but don't know if it was correct.