Noise in input detecting low condition

Hi All,

I'm new to Arduino and I'm playing with my son building a Pinball machine based on an Ardruino UNO. We are facing some noisy reading on an input which should be constantly high and the Arduino has to detect a low condition. This is for a laser sensor that should detect when the laser is interrupted. In our test board we replaced the laser with a normal-closed pulse button. However, we fail to detect the low condition when pressing the button and the behavior seems not deterministic (noise). The first though goes to use a pull down resistor. However, I would like to confirm if it is safe to use a 10K ohm resistor as pull down given that most of the time it is expected to be powered and may cause some damage. Advices are very welcomed.

Thanks,

Welcome to the forum.

Help us help you. After reading the "How to get the best out of the forum" post, follow the instructions to post the code, using code tags, and a photo of a hand draw wiring diagram, with pins and parts labeled. Forum members need this information to diagnose the problem.

Keep in mind that long, loose wires pick up electrical interference from the environment.

Check your circuit. Required are at least 2 wires from the switch or sensor to Arduino GND and input. Also required is a pullup resistor from the signal to Vcc, or mode INPUT_PULLUP.

If your input detecting low condition you need a pullup rather than pulldown

If you really have a normal-closed switch.

Say again how it is wired? Ppl are recommending you use a pull up resistor, and wire the switch between the pin and ground.

When not pressed, the switch is closed, the digitalRead() on the pin will be LOW.

When pressed, the switch is open, and the input will read HIGH as it is pulled up.

A normally closed switch can look pressed from vibration, a 0.1 uF capacitor will stop some of that.

I prefer pull up myself for reasons, but that could also be solved in software. Just invert the digitalRead() right at the moment you do it, in the one place where it is...

HTH

a7

Hi

thanks for the answers. Following the advices, adding code snipped and schematic below. The idea is to use laser transmitter KY-008 650nm and its corresponding receiver (couldn’t find the code name) to detect the condition when the laser gets interrupted (it is worth to mention that we are planning to take into account the environment light interference). So, in normal condition the receiver has the laser beam on the sensor, so it is sending the 5v signal. When the laser gets interrupted, it stops sending the 5v signal. However, this produced that the input signal actually goes “floating” and that is why I was asking about the pull down resistor. Based on what I found, I understand I don’t need a pull up resistor since in normal condition the input is constantly receiving the signal and need to detect when it stops receiving it. Moreover, I found a couple videos on youtube playing the laser sensor, but none of them showed how to address this situation. Thanks again!! (My son is very excited with Arduino :blush: )

const int loserLaserButton = A0;
int loserLaserButtonState = 0;

void setup() {
  pinMode(loserLaserButton, INPUT);

}

void loop() {
  loserLaserButtonState = digitalRead(loserLaserButton);
  if (loserLaserButtonState == LOW) {
    loserRoutine();
  }
}

pinball_laser

Then please do so before proceeding.

Common solution is a pulsed beam and detecting pulses present/absent.

Then please do so before proceeding.

The solution I was referring is a physical one, meaning that the receiver is properly covered/encapsulated to avoid receiving external light and only receive the laser beam.
So, my original question was if it would be safe to add a pull down resistor on A0. Such that when the laser gets interrupted, we get a consistent low on the input.
thanks!

Hi All,
I kept researching and found this discussion lazer receiver gets burned - #29 by wvmarle on which a an “inverted” receiver sensor version is available based on OPL531. So, I can get a high signal when light is not detected on the receiver sensor. I spent some time searching in google but cannot find sensors with the inverted behavior. All I find is the regular behavior, “high signal on light” (*). Some advice on where to buy them would be very appreciated. Thanks!

(*)

Whatever trouble your current sensor is giving you is one thing. I would like to know why you can get one level from it, but not the other. If I understand correctly.

But if in this or any other case all that is wrong is the sense of the sensor, so to speak, please remember that in software many things can be fixed right away.

If for example a sensor returns true (HIGH) for absence, false (LOW) for presence, and you'd like the opposite, just invert the reading you get, right when you get it.

    int sensorReading = !readMySensor();

Here a function readMySensor() is assumed to return a non-intuitive "upside down" reading, so I have used the logical not operator '!' to exchange true <-> false, so the sensorReading variable now carries the opposite logic level, and make true mean presence, much better perhaps.

I'm lazy and scattered, lotsa times I get things backwards in code or wiring or thinking, and the easy way out for a wiring error, for example may well be to just fix the software to match the facts in real life.

This can be made even more flexible by using defined constants

# define ON  0     // for LEDs wired between Vcc and the pin
# define OFF 1

giving you the ability to say

    digitalWrite(someLEDPin, ON);

// or

    digitalWrite(someLEDPin, OFF);

and if your assistant (!) chooses to wire the LEDs differently, you can go to one place and change a few # define statements and all you digitaWrite() statements will deliver the correct logic value to the pin.

HTH

a7

Hi @alto777 ,

Thanks you for taking the time to look at this and suggest alternatives. Yes, indeed can invert the behavior in SW. However, this has some implications for the physical connections to avoid leaving the input floating. For instance, in my setup, the laser should be always transmitting and want to detect when the beam is interrupted (like in a grage door sensor). The receiver sensor I bought has “normal” behavior (high on light presence , low on absence) so I simply inverted the logic in the code (code snippet above). However, the consequence is that when sensor goes low, the input in the Arduino actually goes “floating” instead of ground. Which produced non-deterministic behavior. Therefore, my original question in the topic was about adding a pull down resistor to avoid leaving the input floating when the sensor goes low (on A0 in the above diagram). However, my concern (not being an electronic expert) was that the vast majority of the time the sensor will be sending high to A0 having a 10k ohm resistor pulling to ground. How much current will be constantly sent to ground ? would this be a concern ?

Alternative solution, having found the “inverted” behavior sensor, the normal situation would be the pull-down resistor keeping the input low (no floating), the SW waiting to detect a high, and the sensor occasionally sending a high signal. I would expect no concerns on this approach since it is the normal setup for a pull down resistor. However, it seems it is not easy to find this sensor :frowning:

THANKS!!

Why A0? Is the low level sufficient for a digital input?

With 10k a current of 0.5 mA flows to GND, no problem so far.

Hi @DrDiettrich ,

No particular reason. I’m using it as digital input anyways. I simply exhausted all the digital inputs with buttons, LEDs and LCD display.

With 10k a current of 0.5 mA flows to GND, no problem so far.

Perfect!! thank you very much for confirming this. We are unblocked to continue the project with my son. I appreciate the help received.