TrellBuilt
Old PLC guy but new Arduino guy so
I am working on a remote gate opener and need one more digital input than the 5 Arduino has.
This gate has two control arms so need to separate the right and left gate panels.
Very simple code for testing.
GatePLCcode.jpg 
Reply 0 0
thiagoralves
You can’t use IW1 as BOOL because that is an analog input. Instead, use it as UINT and then create a threshold logic, where if the value is bigger than 30000 it activates a coil, if it is lower it deactivates the coil (use the GT and LT blocks for that). Then you can use this coil as your digital input as usual
Reply 0 0
TrellBuilt

Thanks for the fast response.
I still don't get it. It sounds easy but I have issues getting it to work. What did I make wrong?
Gate 2.png 

Reply 0 0
Rasta31210
Hello "TrellBuilt",
Here is an example for using an analog input in binary.
Capture d’écran 2022-07-04 164922.png  Capture d’écran 2022-07-04 164856.png 
Reply 0 0
thiagoralves
@Rasta31210 that works on simulation, but if you try to upload this code to OpenPLC Runtime you will get compiler errors about bit size length of the variable and location used. %IW locations should be UINT, INT or WORD only. UDINT are 32 bit wide and won't fit on IW locations.

Also, it is a good idea to add some sort of hysteresis to avoid fast switching when the analog voltage is close to the 30000 threshold. Something like this:
analog2dig.png   

Example project attached.
Reply 1 0
Reply