0

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.

ocrdu
  • 8,705
  • 21
  • 30
  • 42
mehmet
  • 1,049
  • 11
  • 32
  • 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? – ocrdu Nov 03 '22 at 08:41
  • 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 :). – mehmet Nov 03 '22 at 08:48
  • Which Arduino is it? Does the MCU run at 3.3V or 5V? – Justme Nov 03 '22 at 09:22
  • Arduino NANO... – mehmet Nov 03 '22 at 09:23
  • Have PLC 'open' ouputs? If yes, pull-up resistor is needed. – Antonio51 Nov 03 '22 at 11:10
  • The PLCs I am familiar with don’t have 5 V outputs (usually for industrial I/O is 24 V, but maybe I’m too old). Also PLC usually have I/O cards with different features (4-20 mA Input / Output, 24 V digital In / Out, just to name a few). Best to check everything first. – Tyler Nov 03 '22 at 12:22
  • Check if the arduino maybe has internal pull-down. – RemyHx Nov 04 '22 at 09:30

1 Answers1

2

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?

ocrdu
  • 8,705
  • 21
  • 30
  • 42