Arduino PLC system

Hello! Proudly owner of new Arduino Mega2560 here.

Because I'm more aware of PLC programing rather than C, was looking for way to use it. After a bit of searching I found a library to implement PLC logic.
Here is that page http://www.electronics-micros.com/software-hardware/plclib-arduino/

I'm having a little problem here with code.

#include <plcLib.h>

/* Programmable Logic Controller Library for the Arduino and Compatibles

Bare Minimum - Single bit digital input and output

Connections:
Input - switch connected to input X0 (Arduino pin A0 / Tinkerkit pin I0)
Output - LED connected to output Y0 (Arduino pin 3 / Tinkerkit O5)

Software and Documentation:
http://www.electronics-micros.com/software-hardware/plclib-arduino/

*/

void setup() {
setupPLC(); // Setup inputs and outputs
}

void loop() {
in(X0); // Read Input 0
out(Y0); // Send to Output 0
}

Problem is I have constant Digital output signal (5V) even if I don't have a condition (x0).
Does anyone have any clue?

matija90:
Problem is I have constant Digital output signal (5V) even if I don't have a condition (x0).
Does anyone have any clue?

Are you saying the Pin 3 (Y0) remains HIGH regardless of whether Pin A0 (X0) is connected to +5 or Ground?

If I don't have nothing connected to A0 (x0) Led flashes. As soon as I touch the male part of wire ticked to A0 Led dims, than when I release hand contact Led goes black (no light) and soon lights on again.
I'm not sure if it stays high or not.

Sounds like you're describing a "floating" input. When a pin is connected to nothing and set as an input the pin will randomly return either a HIGH or LOW state. Touching it usually causes it to change due to the charge on your body. Electromagnetic activity will also have the same effect -- try moving your cell phone near the input. Add a length of wire to the pin and it will act like an antenna and exhibit additional, fun behavior.

To counteract this you should:

  1. Avoid reading inputs that aren't connected to anything :wink:
  2. Connect a ~10K resistor between the pin and GND or 5V to keep it at a default low or high state
  3. After setting the pin as input, digitalWrite(pin, HIGH) to turn on the internal pullup; this is equivalent to connecting the pin to 5V via a 20K resistor.

Try the Button example for more details.