ainfirdaus
Dear,
I found a problem when I tried ADC with arduino Nano. 

I just used adc %IW0.0 and %QX0.0. If adc value was greater than 1000, the lamp would power on. But, when adc not connected to any pins, the lamp blinking. When I connected the adc pin to 3,3v(675), the lamp powered on.

Thank you
Reply 0 0
thiagoralves
First thing: You should use %IW0 to %IW4 instead of %IW0.0 to %IW0.4. Im sorry, the table on the website is wrong, and I should have fixed it already.

Anyway, your problem is not related to that, because virtually %IW0 is equal to %IW0.0 from OpenPLC perspective. The problem is that 1000 for the ADC is a very low number. You must keep in mind that OpenPLC registers are 16-bit wide, therefore, the ADC value range is from 0 to 65536. On the Arduino Nano, a value of 1000 in the ADC represents 0.076v (5 / 65536 * 1000). This is almost zero! Therefore, if you leave the ADC pin floating, the noise from your environment will make the lamp blink. If you want the lamp to be activated when there is a voltage bigger than 3.3v, you should set your comparison value to anything bigger than 43254, because 5 / 65536 * 43254 = 3.3. I would set the number to 50000 (3.81v).
Reply 0 0
ainfirdaus
I thought the ADC using 10 bit because atmega328 uses 10 bit ADC

I have just tried and it worked. I put a resitor pulldown to ADC pin

Thank you
Reply 0 0
diegohap
Which blocks should I use to read the ADC input ??.
Reply 0 0
thiagoralves
You don't use any block. It reads by default on locations %IW0, %IW1, %IW2...
Just add a variable on your variables list that is located in one of those locations (depending on which ADC pin you want to read), and then use this variable with your comparing blocks, arithmetic blocks, or any logic block you want.
Reply 0 0
Reply