Browsed by
Autor: Badia

How to write a digital output

How to write a digital output

You can write a Digital Output (0 or 24V) through: … int myDigital; … void setup() { pinMode (5,OUTPUT); } void loop() { digitalWrite(5, HIGH); } With this piece of code you’ll put a voltage to the output PLC pin corresponding to the internal “5” pin. In this case, we put 24Vdc to the output. If we want to put 0Vdc, we have to change the “HIGH” value to the “LOW” value.   Note: The example pin “5”, is only an example….

Leer más Leer más

How to read a digital Input

How to read a digital Input

You can read the data of a Digital Input through: … int myDigital; … void setup() { pinMode (5,INPUT); } void loop() { myDigital = digitalRead(5); } With this piece of code you’ll read the voltage of a PLC pin. As our digital input works between 0-24V, the read value (myDigital) will be a value: 0 or ~24V.   Note: The example pin “5”, is only an example. You need to check in your PLC which pin to use for reading,…

Leer más Leer más

How to read an Analog Input

How to read an Analog Input

You can read the data of an Analog Input through: … int myAnalog; … void setup() {} void loop() { myAnalog = analogRead(A0); } With this piece of code you’ll read the voltage of a sensor. As our analog input works between 0-10V, the read value (myAnalog) will be a value between 0-1023. If the value of sensor is (3V), myAnalog value is 3*1023/10 = 307.

How to test / read data from console / RS232

How to test / read data from console / RS232

RS232 commnication is not necessary, but is very useful. You can write some code and you want to switch on a led. The easier way to know what is happening if the led isn’t turning on, is through RS232, and watching what are the values of the vars,…   So, if you have purchased an Ardbox, you’ll need to initialize communications through: Serial.begin(9600); while (!Serial) {} and after that, you’ll be able to send any value to the RS232 port,…

Leer más Leer más

RS485 Communication

RS485 Communication

Arduino based PLC through RS485 port can connect with other devices which also use RS485 communication port PLC available to use RS485: 20 I/Os PLC: Ardbox Analog Ardbox Relay Ethernet PLC: M-duino 21 M-duino 42 M-duino 58 M-duino 19R M-duino 38R M-duino 57R

I2C Communication

I2C Communication

In order to communicate through I2C, we have to do two type of programs. We have to create some code for the Master device (PLC in our case), and another piece of code for the Slave devices, such as PLC, or any other device (RTC clock, ADC,…, that has an I2C available port). Master Code: #include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); delay(500); } void loop() { Serial.println(“Initial”); Wire.requestFrom(2, 1); // request 1 byte from device #2 while(Wire.available()) { char c…

Leer más Leer más

How to Modbus-Ethernet

How to Modbus-Ethernet

Modbus is a Serial communications protocol and it is used for communicating with several industrial devices. It may run over RS485, Ethernet, or whatever hardware interface. If we have an ethernet connection between a lot of devices, we can use this hardware connection (eth), and over it, we can use our own protocol (custom protocol,…), or for instance, Modbus protocol. The way is the same as using RS485, but hardware connections will become much easier, the speed will be higher, and…

Leer más Leer más