I have a half scale bowling alley that uses an infrared laser sensor to detect when the ball is rolled. At present I am using an Arduino Uno to detect that signal. The Uno works in tandem with a bowling software called “ScoreMore” which uses a PC camera to monitor the bowling pins and display a score on a monitor. The software works great. However, I have long had issues with some flakiness surrounding the laser sensor. In frustration, I removed all the wiring and put this project aside for 18 months. Fast forward to today, I am in the process of picking up where I left off. Let’s start fresh on this and not dig up my past wiring sins shall we?
There is a tag on each sensor and here is the tag on the 3 wire piece. It shows that is NPN and NO. The power supply voltage is 6-36 VDC. I plan to use 18 ga wire to connect the BK (signal) wire to the Uno and to read that pin with an input pullup. The sensors (BN+ and BU-) will be powered with 18 ga wires to the power supply and ground respectively. There is approximately 10’ of wire required.
My control panel has an 8 amp power supply for 5, 12, and 24 dc volts. I am powering a short string of LED’s and the UNO so the power supply is NOT working very hard. Yes, I have checked the output voltage and it is right on for all 3. I have 1 spare mechanical relay if needed to isolate the higher voltage power requirement from the Uno.
At present, if I power the sensor with 5 vdc it seems to work (infrared beam appears and with the beam is interrupted, the light on the sensor turns on or off (I can’t remember which). However, since the tag calls for a power supply of 6-36 volts AND since I have 12 or 24 volts readily available, I am prepared to use either one instead of powering directly with 5 VDC from the Uno.
Unfortunately, I did not measure the signal voltage or amperage from the BK lead when I last had this wired up. I do not want to assume I can hook that wire directly to the Uno.
According to the instructions from the software, ScoreMore, this is the suggested wiring for the photoelectric switch but as you can see it is a 5VDC signal which using 5 VDC I suspect may have been my previous issue.
Can someone suggest how best to wire the components I have available. I have a ton of different sized resistors in case a pull up resistor is needed in the wiring.
BK is a normally open NPN output, which supplies no voltage or current. It simply acts as a switch to ground and is completely safe to connect to any MCU input.
A pullup resistor from BK to the MCU Vcc (5V or 3.3V as appropriate) is required. For 10' of wire, I suggest a 1K or 2.2K pullup.
Don't forget to connect the grounds (sensor supply negative to Arduino GND).
@jremington That’s good to know about the BK wire. Do you have any suggestions on how best to power the photoelectric switch? Again, I have 5, 12, and 24 vdc available.
@jim-p care to weigh in? You created this sketch for someone on a similar topic but an entirely different photoelectric switch of course.
That schematic was for a very different type of sensor.
Powering the Uno via the 5V output can be problematic. The supply needs to be well regulated with low ripple, free of noise and transients. You should not connect the USB or anything to Vin when you power via the 5V output.
Some people claim that those sensors work on 5V but the operating conditions were unknown. If you have 12V, I would use it.
What are these other devices connected to the Uno?
@jremington just to be clear, I should add a resistor on the wire running from the photoelectric switch to the Uno (presumably as close to the Uno as possible) in the size range of 1000 to 2200 ohm. Also, I should now use INPUT instead of INPUT_PULLUP in my Arduino sketch.
@jim-p My apologies for not explaining that image of the Uno better. The highlighted pins get wired to the photoelectric switch. The Uno itself is powered by the USB port from a computer and NOT from the 5V pin.
This photoelectric switch is just a small portion of my bowling lane project. The full project details and wiring diagram, which is a work in process, are in these attachments. The Uno controls the items associated with the ScoreMore software system (lights for ball 1, ball 2, strike, spare, etc). I added a Mega board to control a string pinsetter, the ball return, and the sweep for my bowling game. The Uno portion runs great with the exception of the photoelectric switch. Once I get the whole thing working I’ll likely transfer everything on the Uno over to the Mega. The Arduino sketch for the Uno was provided by ScoreMore and I am actively working on the Arduino sketch for the Mega. I’ll create another post for help on the sketches/combinging the Uno and Mega at a later date.
@jremington whoops! I had to read up on pullup resistors and your suggestion makes sense to me now. I hope we have stumbled on the answer to my real problem which has been an erratic photoelectric switch. I’m going to mark this discussion solved.
The solution is as follows: When monitoring for an input signal (in my case a photoelectric switch), you must consider the distance between the two devices (and the wire sizing). For shorter distances you might be able to use the internal pullup resistor (by defining the Arduino pin as INPUT_PULLUP). If your signal is flaky, the distance may be too great between the devices and you may need to use an external pullup resitor instead (Arduino pin to be defined as INPUT in this case). I’ll leave the explanation of resistor sizing to the experts. @jremington was kind enough to offer this example for the wiring. My revised wiring sketch is also shown below.
Wires act as antennas to pick up electrical noise from overhead lighting, nearby electrical machinery, etc. The longer the wire, the more noise.
Low value resistors act to dampen the noise, so try 2.2K and if that is not reliable, drop the value to 1K or even lower.
The lower resistance limit is determined by the maximum current draw allowed for the open collector output, which should be specified in the sensor data sheet.