2

I am looking to wire a break beam sensor to gather results and save them as eventually as JSON data. I am however totally new to hardware and believe there is an issue with the circuit.

I have the breadboard powered at 5V and the connected to the Pi in GPIO 12. As you can see from the image below I then have a 10k resistor running between the ground and the GPIO wire. I am fairly sure the python scripts I am using are correct but there could well be an issue there if the wiring is correct.

LINK TO BREAK BEAM SENSOR

The current response I am getting is that the beam is always unbroken even when they are not. If there is anything else you wish for me to supply do let me know.

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)    
GPIO.setup(12, GPIO.IN)


if True:
   if(GPIO.input(12) ==1):
       print(“Broken”)
   if(GPIO.input(12) == 0):
       print(“Un-broken”)

Current breadboard wiring (Please ignore right hand side of breadboard)

6
  • "connected to the Pi in GPIO 12" -> A common mistake for newcomers is confusion regarding the pin numbering. Since you are using the BCM scheme this should be the fifth pin up from the USB ports on the outside row.
    – goldilocks
    Aug 8, 2016 at 20:10
  • Thanks @goldilocks just had a check and it is connected to the correct pin Aug 8, 2016 at 20:12
  • You might also want to include a model number or link for the beam sensor. Beware that the GPIO logic level is 3.3V and you mention the breadboard is wired to 5V; some sensors have logic levels distinct from their supply voltage, but if it does not, do not connect it directly to a GPIO this way, you may damage the pi by applying 5V through the GPIO pin. Hopefully this is not what has already happened...
    – goldilocks
    Aug 8, 2016 at 20:15
  • @goldilocks the link has now been added. The unit says it can take both 3.3V and 5V with the 5V being able to work at a better range. They are going to be used on mailboxes so 5V would be needed. I have tested the GPIO pin with the second LED circuit you can see on the right hand side and all is working fine. Aug 8, 2016 at 20:21
  • The point is not how much voltage the sensor takes. The point is how much it is going to output to the pi. You CANNOT output 5V to a GPIO pin or you WILL damage the Pi. The GPIO pins are not 5V tolerant. They are 3.3V. That Adafruit tutorial uses an Arduino as an example, further evidence that it will output 5V. Disconnect it from the GPIO.
    – goldilocks
    Aug 8, 2016 at 20:27

1 Answer 1

1

Pretty sure you have some of the logic backward.

   if(GPIO.input(12) ==1):
       print(“Broken”)
   if(GPIO.input(12) == 0):
       print(“Un-broken”)

However, in the Arduino example, the beam is considered broken when the signal goes low, meaning when unbroken it will be high. This is why the sensor line requires a pull up; what you have in your photograph is a pull down to ground.

This might also explain why the GPIO doesn't read high when the input is unbroken, and why you managed not to damage the pi -- the "open collector" output is being pulled down that way no matter what.

It's not clear from the (non-English) data sheet if using a 3.3V supply will mean the output is 3.3V as well, in which case it would be safe to use that way. Otherwise you will need a level shifter or something similar in between in order to interface with the sensor.

Once that's resolved (and/or if you are willing to gamble), the resistor should connect to the 3.3V rail, not ground. This will pull the pin's value high except when the beam is broken and the input sinks the current (when it will become low).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.