Browsed by
Tag: Plc Arduino

Ardbox – MDuino Arduino pin

Ardbox – MDuino Arduino pin

This post describes how to gain direct access to Arduino board pins  inside the  Ardbox and MDuino PLCs. This allows to work with the PLCs in the same way as using an Arduino, in other words,  pins at 5V and configurable as input or outpts.

Also, this  enables usage of  sensors  working at lower voltages than industrial standards 10V dc/24Vdc.  NOTE:Make sure the voltage DOES NOT EXCEED 5VDC!!!!!!!!

Following are listed the connections with direct access to the Arduino board  pins.

Ardbox: DE-D7  // RE-D4 // SDA-PIN2  // SCL-PIN3

MDuino: SCL // SDA // RX0 // TX0 // RX1 // TX1 // Pin3 // Pin2

In order to enable the direct connection to Arduino pins, the configuration switches for these connections must be set to OFF position.

IoT in industry improves reliability equipment. Arduino as PLC application.

IoT in industry improves reliability equipment. Arduino as PLC application.


IoT and Plc MDuino

Nowadays, manufacturers need keeping factories running 24×7, and, in order to ensure it, the equipment must be reliable because a failure can cost millions of euros and impact the ability to ship product to customers.   How can IoT help you to increase equipment and minimize unplanned factory downtime? The answer is monitoring factory equipment, quickly, providing maintenance engineers with detailed error message in real time. In this newsletter we will show you an example of how IoT can help in industry.

Project, Hardware and Architecture  

In this project, Opiron Electronics  connect an M-Duino PLC from IndustrialShields to the Xively IoT platform.  This example is going to show you an online monitoring feature for a Factory process, which will enable to maintenance engineers and operators to visualize factory data using Internet, so they´ll can access using smartphones or tablets.  For this reason, we are not going to implement a full automation solution because it is not the scope of this newsletter. Since the hardware point of view, the architecture that we will implement will be as the following picture shows:

Picture Architecture

First steps

First of all, make sure you have a Xively account. If you don’t already have one, you can register for a free account here.  Secondly, select the data you want to visualize. IoT is not going to substitute SCADA systems; you have to think it as an extension, so select the critical data that you would have in the cloud. In our example we will use a temperature.

Software and code

As usual, we will use the Arduino IDE to program our PLC. Furthermore, for this project we will use the Xively library for Arduino which you can download here. You will need the http client library as well, available here. The sketch will upload a datastream to the Xively platform. Xively generates graphs based on data you provide, but you can create triggers and notifications to provide alert capabilities for your application. Regarding the M-Duino PLC code, it can be downloaded here:

2014111_arduino_codeKey Benefits

The main benefits of the Opiron proposed solution are:

  • Online monitoring can reduce maintenance costs and downtime.
  • Connected: Maintenance engineers can keep connected to equipment and process, which means faster repair times and a reliability improvement.
  • Open Source based: Since the hardware and software point of view, this feature means big flexibility, big availability of resources on the internet in case of failures or change implementations, etc.
Industrial Shields harware

Contact us! Do you have a process to be automated? Contact Industrialshields to buy the right open source scalable hardware and to implement the entire solution.

Chloride Dosing System

Chloride Dosing System


Manufacturing drinking water is a process with different steps. The last step is called disinfection, used to destroy microorganisms in water. To achieve it, systems inject chlorine. This technique is called dosing. Dosing is the technique for controlling the addition of a substance to a flowing liquid or gas.  Dosing systems are designed to achieve the required dosing level by maintaining the control signal as a proportion of the fluid flow rate. In this post we are going to develop a chloride dosing system based on Arduino.

Equipment to be used

Dosing control equipment consists basically of the following elements:

  • A controller, in this case we will use an M-Duino PLC.
  • A flowmeter.
  • A dosing pump.
  • A dosing level sensor.nanodac-dosingcontrol

The following figure shows the general arrangement of the dosing control system: The dosing concentration measured by the dosing level sensor is used to stop the pump if a there is high concentration in the tank. The flowmeter provides the input of the control loop, which is connected to the pump (as the output).

Software and code

In this example, dosing level and flowmeter are configured as a 0-10V analog input. The pump works with a frequency driver. As we have to develop a control loop, we have created a PID controller linked to the specified input, output and setpoint. You can find the code to be uploaded here:2014111_arduino_codeKey Benefits

The main benefits of the Opiron – Industrial shields proposed solution are:

  • Flexibility: This application note describes how the Open source based hardware can be used to control the dosing level of a chlorine system. However this same architecture can be used with any liquid or gas using the PID algorithm.
  • Freedom to modify your software: You aren’t limited to what one company believes you need.
  • Easy to be integrated: No matter if you already have an automation system. The Arduino hardware is easy to integrate into your system..
Contact us!

Do you have a process to be automated? Contact Industrialshields to implement the entire solution and to buy the proper hardware.

Developing a packaging machine based on Arduino hardware

Developing a packaging machine based on Arduino hardware


Packaging machines are used to enclose and protect products for distribution, sale, and use. They are very popular in industry because they are safe, reliable, and usually integrated into the process line. They guarantee a big productivity.

In this project, Opiron Electronics will develop a basic packaging machine based on the Open Source Hardware PLC´s from IndustrialShields. Ardbox RelaySystem

Our packaging machine will have three basic control functions: HMI( the Human Machine Interface), PLC (the logic part of the control), and the Motion Control functionality. The main idea of the Project is to develop a reliable and flexible machine. We will make use of an Ardbox Relay as the main processor of the system, but, as packaging machines need to be integrated into more complex systems, as we saw in the Feeding a packaging machine with a frequency driver  post,  we will make use of an M-Duino PLC, which has Ethernet connectivity which can send data to an SCADA. The detailed hardware can be found at IndustrialShields the website.



Hardware and Operation

In this newsletter we are going to show just a part of the packing machine. This is a feeder and the lifter. The feeder consists of a piston, when a product is in front of the feeder, the feeder moves forward and the lifter downs a level. When the lifter is at the lower level, the entire product can be sent to the packaging part. PLC Programming Packing Machine_industrial_shields   The hardware components will be:

  1. Five mechanical switches (Reverse, forward, upper switch, middle switch and lower switch).
  2. 4 relays which are based in Arduino. 2 of them for the feeder (forward and reverse movement) and 2 more for the lifter (up and down movement).

Software and coding

As described above, the system works in six steps. Furthermore, the code has an additional but interesting feature: the capability to receive commands from another PLC (M-Duino), if an operator wants to stop the process remotely. Download the Arduino source code in the link below:   2014111_arduino_code    

Key benefits

  • Remotely control from another PLC capability.
  • Open Source hardware based, which it means reliable, cheap and expandable.
  • Easy to be installed.
A Conveyor Belt Control System with an Arduino PLC and a Rasberry PI Panel PC HMI

A Conveyor Belt Control System with an Arduino PLC and a Rasberry PI Panel PC HMI

Conveyor belts are very common in industry: we can find them in different industries like mining, food & beverage or chemicals.  They are used to deliver heavy materials from one place to another. In this project we will make a control system based on M-Duino PLC hardware that can be controlled through an SCADA / HMI software for food industry.


The application to be developed must ensure that a conveyor belt works properly:

  1. Must verify that the conveyor runs all the time.
  2. If a problem occurs, must alert to the operators of the plant.

To fulfill the requirements, the conveyor system has sensing devices like photoelectric and inductive sensors, lights and relay’s. Specifically, the hardware devices to be programmed and its function are as follows:

  1. Photoelectric sensor: Detect each manufactured product.
  2. Inductive motion sensor: Detect motion of motor.
  3. Relay’s output: Stop motor motion if an error occurs.
  4. Strobe lights: Alert if an alarm occurs.

The system is as shown below:



We are going to program the M-Duino as it follows in the next part of this tutorial.

  1. For the photoelectric sensor, we are going to use interrupts in the rising mode. Each time that we have a new interruption, a new manufactured product has been detected.
  2. To detect that the motor is running we will use interrupts in rising mode as well. Each time that we have a new interruption, we can count a new cycle loop detected.
  3. We are going to use three strobe lights, two of them to alarm if a failure occurs:
  • If the motor has stopped.
  • If a production failure occurs, that it means that we don’t detect products through the photoelectric barrier for more than 30 seconds).
  1. The last strobe light comes from another part of the plant, and indicates that we have product demand, so the conveyor belt should be working. We are going to use relays to stop motors if an alarm occurs.


// Industrial Shields by BOOT & WORK CORP. // Powered by Opiron Electronics // Feb.2015 technical information for newsletter // This sketch demonstrates how to program some // digital input / output signals through an M-Duino // PLC. The sketch is inspired in a real project of a // food plant, where we have to control a conveyor belt. // Keywords: Conveyor Belt, industrial automation. ////////////////////////////// //// PLC: M-DUINO MODULE //// //// Number of inputs: 2 //// Number of outputs: 4 //// you need to configurate the correctly switch position for running like digital / analog or PWM mode ////////////////////////////// //// M-Duino Pins Used: //// Q0.0 — PIN 36 — Digital Output (24Vdc) — Motor Failure Strobe //// Q0.1 — PIN 37 — Digital Output (24Vdc) — Product Demand Strobe //// Q0.2 — PIN 38 — Digital Output (24Vdc) — Product Failure Strobe //// Q0.3 — PIN 39 — Digital Output (24Vdc) — Stop Motor //// I0.0 — PIN 22 — Digital Input (24Vdc) — Photoelectric Barrier sensor, when active, a new product crosses the photoelectric barrier //// I0.1 — PIN 23 — Digital Input (24Vdc) — Inductive sensor, when active, a new loop detected in the motor //Pins defintion #define Motor_Failure_Strobe 36 // Alert if a motor failure alarm occurs #define Product_Demand_Strobe 37 // Alert if a product order is required #define Production_Failure_Strobe 38 // Alert if a production failure occurs #define Stop_Motor 39 // If an alert is detected we will stop the conveyor belt #define Photo_sensor 22 // Photoelectric sensor to detect manufactured products #define Ind_sensor 23 // Inductive sensor to detect the motion in the motor //Thresholds and constant interval times #define MINSPEED_THRESHOLD 500 // We consider that the minimum speed when the motor runs is 500 rpm, if a less speed is detected, we must alert and stop the plant #define time_photo_limit 4500 // We consider an interval of 4,5 seconds as the limit between each product can cross the photoelectric barrier #define rpm_interval 60000 // 1 minute // Variables volatile unsigned int rpm; // Variable to count the speed of the motor, consider rpm as revolutions per minute boolean Alarm; // Variable that says if we are in an alarm state or not unsigned long time_photo; // Variable to count the time between each product cross the photoelectric barrier unsigned long prevTime_rpm; // Variable to count each 60s the rpm of the motor // Functions void speedcount(); void manufacturing(); void setup() // Configuration is here: { // Pin settings pinMode(Motor_Failure_Strobe, OUTPUT); pinMode(Product_Demand_Strobe, OUTPUT); pinMode(Production_Failure_Strobe,OUTPUT); pinMode(Stop_Motor,OUTPUT); pinMode(Photo_sensor, INPUT); pinMode(Ind_sensor, INPUT); // Thresholds settings rpm=MINSPEED_THRESHOLD; // Initial speed value initialized with a higher value of minimun motor speed to disable an initial alarm // Interrupts attachInterrupt(Ind_sensor, speedcount, RISING); // Pin 2 attachInterrupt(Photo_sensor, manufacturing,RISING); // Pin 3 // Variables Alarm=0; } // End setup void loop() // The code in loop() runs repeatedly: { if(millis() – prevTime_rpm > rpm_interval) // Each 60 seconds we reinitialize rpm’s to 0 { prevTime_rpm = millis(); rpm=0; } if (rpm<MINSPEED_THRESHOLD) // Alarms Check I: Motor doesn’t work at the proper speed { digitalWrite(Motor_Failure_Strobe,HIGH); digitalWrite(Stop_Motor,HIGH); Alarm=1; } if(time_photo>time_photo_limit) // Alarms Check II: The manufactured products doesn’t cross the photoelectric barrier { digitalWrite(Production_Failure_Strobe,HIGH); digitalWrite(Stop_Motor,HIGH); Alarm=1; } else if (Product_Demand_Strobe) // Nonmal Conditions { Alarm=0; digitalWrite(Motor_Failure_Strobe,LOW); // The Failure Strobes must be off digitalWrite(Production_Failure_Strobe,LOW); digitalWrite(Stop_Motor,LOW); // The Motor must be running } // End Normal Conditions } // End loop void speedcount() // This function is executed each time that we have a new interrupt { rpm++; // Speed up! } // End speedcount() void manufacturing() // This function is executed each time a new product crosses the photoelectric barrier { time_photo=0; // When a new product crosses the photoelectric cell, the counter must reset } // End manufactuing()

Controlling temperature with a got exchanger through a modulating valve in chemical industry

Controlling temperature with a got exchanger through a modulating valve in chemical industry


In industrial applications, the need to control temperature is usual. A typical element used and designed with this purpose is the hot exchanger, which interchanges two or more fluids with different temperatures.
Ardbox PID loopIn this post we are going to explain how to implement a temperature control through a modulating valve that will regulate the amount of steam that enters the hot exchanger, in order to heat the chemical process. To fulfill the specified requirements, Opiron electronics has developed a PID algorithm which will run on the Ardbox PLC from Industrialshields. Hot Exchanger Logic

Obviously, the main purpose of the aglorithm that we are going to make is a program to control the temperature of the pipe where the chemical process flows.  The element that will give us the chance to regulate the temperature is a modulating valve that has an analog input interface (0 / 10 Vdc) where we are going to send the setpoint from our PLC.

The modulating valve will control the amount of steam that flows to the pipe, and therefore the temperature (the more amount of steam we send, the more temperature there is in the pipe).

To control the temperature, we will use a PID algorithm and a temperature sensor as the input. However, there are other elementary elements to program:

  • valve open / close
  • pump on / off

These will be used from a process safety point of view: basically, if the temperature of the process is out of the limits (>80 ºC).

See below the developed code by Opiron:



// Industrial Shields by BOOT & WORK CORP.
// Powered by Opiron Electronics
// Jan.2015 technical information for newsletter
// This sketch demonstrates how to use a PID with 
// an ARDBOX ANALOG PLC. The sketch is inspired in a
// real project of a chemical plant, where we have to 
// control the temperature of a pipe.
// PID explanation: The purpose of the pid is to 
// control a loop with a temperature sensor and
// a modulating valve. The modulating valve has 
// an analog input where we can send the setpoint
// Keywords: PID, industrial automation, modulating valve
//// Number of Digital inputs: 2  
//// Number of Digital outputs: 3
//// Number of Analog inputs: 1
//// Number of Analog outputs: 1
//// you need to configurate the correctly switch position for running like digital / analog or PWM mode.
//// Ardbox Pins Used:
//// Q0.9 --- PIN 0 --- Digital Output (24Vdc) --- Start / Stop pump
//// Q0.8 --- PIN 1 --- Digital Output (24Vdc) --- Open / Close feeding valve
//// Q0.7 --- PIN 7 --- Digital Output (24Vdc) --- Light alarm indicator
//// I0.3 --- PIN 4 --- Digital Input (24Vdc)  --- Pump runs confirmation 
//// I0.2 --- PIN 8 --- Digital Input (24Vdc)  --- Feed Valve Opened Ok
//// I0.9 --- PIN A0 --- Analog Input (0/10Vdc) --- Feeding Temperature signal
//// Q0.6 --- PIN A3 --- Analog Output (0/10Vdc) --- Setpoint to Modulating Valve


//Pins defintion
#define Pump_Output 0        // Start / Stop pump
#define Valve_Output 1       // Open / Close feeding valve
#define Light  7             // 1 = Red (alarm) / 0 = false (Ok)
#define Pump_Input 4         // Pump Runs Ok
#define Valve_Input 8        // Feed Valve Opened Ok
#define Temperature A0       // Feed Temperature (after PID)
#define ModulatingValve A3   // Setpoint to Modulating Valve

// Other constants
#define HighTemp  80
#define LowTemp  40
#define intervalValve 10000
#define intervalPump 10000
#define intervalTemperature 60000

// Variables
unsigned long Valvetime;            // We use time to check if Valve opens when we have sent an Open Order
double Setpoint, Input, Output;     // PID Values
double kp = 2.5, ki = 30.3, kd = 5.1;         
unsigned long PIDwindowStartTime;   // Use it to compare PID Window Time
unsigned long PumpwindowStartTime;  // Use it to compare Valve Opening time
unsigned long ValvewindowStartTime; // Use it to compare Valve Opening time
unsigned long TemperaturewindowStartTime; // Use it to compare Temperature out of range
boolean valvefail;                  // 0 = Valve OK, 1 = Valve fails
boolean pumpfail;                   // 0 = Pump OK, 1 = Pump fails
boolean tempfail;                   // 0 = Temp OK, 1 = Temp fails

// Objects
PID TemperaturePID(&Input, &Output, &Setpoint,kp,ki,kd, DIRECT);

void setup() 
{ //Configuration is here:

  //Pin settings
  pinMode(Pump_Output, OUTPUT);

  // turn the PID on

  // Ini variables

} // End setup

void loop() {    // The code in loop() runs repeatedly:

if (tempfail)   // Alarms check I: tempfail

else if (valvefail) // Alarms check II: Valve can't be opened

else if (pumpfail) // Alarms check II: Pump doesn't start properly

    Input = analogRead(Temperature);
    if (Input> HighTemp || Input < LowTemp)     {     if(millis() - TemperaturewindowStartTime>intervalTemperature)  //We count 1 minute             
      TemperaturewindowStartTime += intervalTemperature;
    analogWrite(ModulatingValve, Output);
    if (Pump_Input==0)    //We wait for the Opened confirmation from the valve
    if(millis() - PumpwindowStartTime>intervalPump)  //We count 10s until the Valve is Opened. If the Valve doesn't return the opened confirmation, we send an alarm                
      PumpwindowStartTime += intervalPump;
   } // end If Pump_Input
   else if (Pump_Input==1)
   } // end Valve_Input==1
    if (Valve_Input==0)    //We wait for the Opened confirmation from the valve
    if(millis() - ValvewindowStartTime>intervalValve)  //We count 10s until the Valve is Opened. If the Valve doesn't return the opened confirmation, we send an alarm                
      ValvewindowStartTime += intervalValve;
   } // end If Valve_Input
   else if (Valve_Input==1)
   } // end Valve_Input==1

  } // end else, normal conditions
} // end loop