0
\$\begingroup\$

I want to read the output of a PLC with an Arduino. If the PLC sends a HIGH (5 V) on a OUTPIN, the Arduino should read this HIGH, else LOW. I am generally using this code for this:

pinMode(button1, INPUT_PULLUP);

This way I can only read if the input of Arduino becomes GND, otherwise the Arduino reads every time as HIGH. This is what I want.

But this time the input is only 5 V from the PLC. How to read the 5 V input correctly? If I don't use a pull-up, the Arduino reads absurd values. Like this:

pinMode(button1, INPUT);

How can I read a 5 V input state correctly with an Arduino? I don't want to use an additional resistor or something else.

\$\endgroup\$
7
  • \$\begingroup\$ What type of output does the PLC have, is it 0 V whenever it isn't 5 V? When you don't use the internal pull-up, and connect the PLC's output to an Arduino pin, and their grounds, what "absurd values" do you see? What is the rest of your code? \$\endgroup\$
    – ocrdu
    Commented Nov 3, 2022 at 8:41
  • \$\begingroup\$ well PLC not here with me. A my friend wants to make this project. I will send him only arduino. So I dont know "is it 0 V whenever it isn't 5 V? " . absurd values is seeing after I am testing with touching arduino 5v to button1 pin. like this 1010101111111111111 :). \$\endgroup\$
    – mehmet
    Commented Nov 3, 2022 at 8:48
  • \$\begingroup\$ Which Arduino is it? Does the MCU run at 3.3V or 5V? \$\endgroup\$
    – Justme
    Commented Nov 3, 2022 at 9:22
  • \$\begingroup\$ Arduino NANO... \$\endgroup\$
    – mehmet
    Commented Nov 3, 2022 at 9:23
  • \$\begingroup\$ Have PLC 'open' ouputs? If yes, pull-up resistor is needed. \$\endgroup\$
    – Antonio51
    Commented Nov 3, 2022 at 11:10

1 Answer 1

2
\$\begingroup\$

The problem probably is in the way you test (as described in your first comment).

For testing, you need to switch the button1 pin between 0 V and 5 V, not between "open" and 5 V as you do now, because that won't work properly without a pull-down resistor.

Open (unconnected, floating) MCU input pins can easily change state and show any value. See, for instance, Why can a MCU input floating pin easily change state?

\$\endgroup\$

Your Answer

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

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