I recently bought an IR Reflective Sensor, but I was having trouble getting the wiring to work on a breadboard with the raspberry pi 4B.
I tried connecting it the similar to how the site has it connected to an arduino, but it still doesn’t work.
Would anyone be able to help me with the correct circuit diagram would be nice thanks in advance
Link to sensor:
Any help with the correct circuit diagram would be nice thanks
This might sound like a stupid question but you are putting something white or light-coloured in front of the device to reflect IR aren’t you. There is no indication of anything in the pix and the text is a bit vague
Correct me if I’m wrong here, but the Pi doesn’t possess the hardware ADC required to use an analog sensor such as the reflectance sensor you’re using. You’d need to use an ADC such as the MCP3002 Core stocks. As for using it, SparkFun have a great guide for Python and Pi use with this chip.
I was completely wrong there, this sensor is an on-off affair, and I’ll have to take a closer look at this. Could you post a quick napkin-sketch of your breadboard wiring? I can’t quite make out some of the connections as they are hidden behind other wires. Could you also post any code you’re using, as that might be a problem as well.
Keen to see this working!
Welcome to the forum! This sounds like an awesome project!
I did some digging and came across this tutorial on Adafruits site using the exact same sensor.
In both examples they are using a board with a logic level of 5V, I haven’t had a play around with the sensor myself but the output pin of the sensor might be driven to a dangerous level for the Pi (the Pins aren’t rated to be able to handle!
I couldn’t find a hard maximum for the Pi’s, you can read more about logic levels here: Logic Levels - learn.sparkfun.com), and the pins also arent able to read analog signals - you need an ADC for that!.
You can read the voltage of the pin using a multimeter if you keep the sensor activated to double-check.
To get it up and running, a logic level converter between the output of the sensor (connecting into one of the inputs of the high side) and the ouput to the Pi with a current limiting resistor for best practice, should get you back on track!
Let us know how you go Azula, I’m keen to see where this project takes you!
I think this device is either on or off. Not analog.
I don’t see why this has to run from 5V. Reduce the 470Ω resistor to a value that allows the required current through the IR LED for 3V3 if that is what you are working with. The output should be the open collector of the photo transistor so just return the 10kΩ resistor to 3.3V if that is required. It does not have to be 5V.
PS: I have not seen an answer to my previous question, I quote"
Oh hey, yea I was putting so piece of white plasticcard about 5-10mm infront of it
Oh hey thanks so much for the resources, looks really interesting, I’ll definitely give it a read
Hey, sorry for the late reply, I was at work. Yea I’ll quickly draw that up when I get home and I’ll post it.
Thanks so much for the help everyone
Here’s an attempt at a wiring diagram haha, sorry if it’s messy.
And that’s the test code
I’m fairly new to raspberry Pi projects, so If I’ve made a silly mistake, I apologise for wasting everyone’s time
Again, thank you so much for the help everyone
I don’t know anything about RPi but you seem to have GPIO Pin 5 connected to Ground. Won’t do much there. Try connecting to phototransistor collector, in other words the other end of this transistor where the 10kΩ resistor connects.
Hey, yea I tried that too but still didn’t work
Keep this in mind though. Any IO pin connected to ground is not going to do anything so don’t put it back
I’ve done some reading, and while there isn’t a datasheet on the product, I found a stackoverflow page that suggests using calculating the resistor value based on a forward voltage (unknown in your case but constant for the phototransistor), so you could experiment with gradually smaller resistance values, or use a 10K pot to try and adjust for the differing supply voltage of the Pi.
Still keen to see this working as always!
EDIT: Added link