Interfacing PLC to an arduino

Hi guys,

Is it possible to connect a arduino and a PLC (http://www.ab.com/programmablecontrol/micro/micro800/get/virtualbrochure/EN/micro830.html )?

I was hoping the plc can give an output to the arduino so that the arduino can control a small 5v servo motor.

If I configure the PLC's output signal to a input pin of the arduino......will the arduino read the input as a normal push button function would?

Thanks to whoever reads and replies..........

riazali:
Hi guys,

Is it possible to connect a arduino and a PLC (http://www.ab.com/programmablecontrol/micro/micro800/get/virtualbrochure/EN/micro830.html )?

I was hoping the plc can give an output to the arduino so that the arduino can control a small 5v servo motor.

If I configure the PLC’s output signal to a input pin of the arduino…will the arduino read the input as a normal push button function would?

Thanks to whoever reads and replies…

Yes, but two points to be aware of:

  1. The PLC and arduino must be referenced (wired) to a common ground.
  2. The maximum voltage input for a input pin on a arduino is +5vdc (or +3.3vdc on some models). If the PLC uses a higher voltage or if it’s a negative voltage there will be damage to the arduino. One can use voltage dividers or optoisolators to solve such a voltage mismatch case.

Thank you so much for replying,

The PLC will give an ouput of 24V DC. Im not aware of optoisolators but will give it a look now. How about using a voltage regulator?

Also will the coding be the same as giving any signal input to the arduino? (i am a newbie in arduino programming). Keep in mind I want to control a 5V servo motor through the arduino

riazali: Thank you so much for replying,

The PLC will give an ouput of 24V DC. Im not aware of optoisolators but will give it a look now. How about using a voltage regulator?

No, voltage regulators are for power conversion not signal level conversion. Could be as simple as two resistor voltage divider for each signal used.

Also will the coding be the same as giving any signal input to the arduino? (i am a newbie in arduino programming). Keep in mind I want to control a 5V servo motor through the arduino

Yes, coding is the same as the signal is just a digital input signal as far as the arduino is concerned.

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                
 
int pos = 0;    // variable to store the servo position 
int plc = 7;   // PLC signal input pin


void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  pinMode( plc, INPUT ); // sets pin 7 as an input
} 

void loop()
{
  pos = digitalRead(plc);
  pos = map(pos, 0, 1, 0, 179);
  myservo.write(pos);
  delay(15);
}

Does this look like it would do it? (please lookout for newbie mistakes too, its my first arduino coding.)

I suspect your code would work (haven't tested) however it's a little, shall we say unconventional using that map command for a digital input. But if it works it works and that is the bottom line and what makes coding fun sometimes, especially as a hobby for personal use. I would probably gone the more boring route with the loop function as such (not tested):

void loop()
{
  pos = digitalRead(plc);
     if (pos)
      {myservo.write(180);}
     else
      {myservo.write(0);}
   delay(15); 
}

Ya sure,

I was just trying to stick to what I learnt from examples. The if and else looks good too. I have not tested it yet also. Need to purchase the appropriate PLC, first.

I have a confusion though........ this coding (both the map way and if-else way) requires only one output of the plc. Now literally speaking if the the plc is giving a signal(high) the servo is at 180 deg. , if there is no signal(low) the motor is at 0 deg. If I used two output signals from the plc as inputs to the arduino, then i would have a signal for it to go to 180 and a separate signal for it to go back to 0 deg. Is there a way to code(hack) in such a way that i need only one plc output but i would have the functionality of having 2 separate signals? (maybe the first high signal makes it go to 180, but then the signal goes low but the motor remains in position. Then the second high signal makes it go back to 0 deg and also immediately goes back to low).

I am happy with the easy way but just asking around for other options.

Thank you @retrolefty again for all your support

Well you could always have a single digital PLC output carry more information by just pulsing the PLC output from low to high and back to low where the length of time the signal is high could be measured by the arduino (see pulseIn command), then you end up with a variable value that can be a range of values rather then just a 0 or 1.

any chanse of using the serial port ? might need a converter in between