EAL-Industry 4.0-Color Counting Robot

1,038

18

Intro: EAL-Industry 4.0-Color Counting Robot

This project is made by Rasmus Skjerning Nielsen in 3. semester in Automation Engineering at Lillebælt Academy.

This project builds on an earlier project where we used an Arduino to control a robot arm to pick up an element with a electromagnet and place it over a color detector. When the color is detected the robot should put the element in the right container. The system were made to recognize four different colors.

Link to former project (In danish)

Step 1: The New Project

The project was build on the principles of industry 4.0, Smart Connected, Flexible, Social and High Quality Services. The idea with the new project was to collect the data from the Arduino. Make the Arduino check the colors of the elements and count how many of each color has been sorted. The final count data are then send to Node-RED and then put in a MySQL database. From the database a Windows Forms Application takes the data, and shows and handles them. The app is making a stock count that it puts in a new table in the database. In Node-RED there are made a dashboard to control the Arduino and to show the counted values and also the stock count.

Step 2: Arduino Changes

From the earlier project there are a few changes. To make sure that the robot is active, there is connected a LED RGB module. It is connected to the Arduino pins 49-51-53. It is green when the robot is ready to count and red when the robot is done reading.

There are also added the function serialEvent() that make it possible to write to the Arduino no matter where the program are in the code.

Below is the new arduino loop code. There are also added to if statements, if incomeInt = 5, then start robot or if incomeInt = 4, then stop robot. New is also that there in the switch case are added 1 to different integers depending on which color are found. Finally all color counts are collected to a string separated by semicolon and send to Node-RED.

void loop()<br>{
  moveArm(home1, home2, home3);                     // Function move robot home
    
  if (incomeInt == 5)                               // If number is 5 from Node-RED start robot
  {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);		    //  Green light on
    digitalWrite(bluePin, LOW);
    
    irValue = digitalRead(irSensor);                  // Read sensor value
    if(irValue == LOW)                                // Compare sensor value
    { 
      delay(1000);                                    // Delay before robot moves
      moveArm(pickUp1, pickUp2, pickUp3);             // Robot moves to pickup area
      digitalWrite(magnet, HIGH);                     // Magnet activates
      delay(1000);
      moveArm(home1, home2, home3);                   // Robot move up home
      delay(500);
      moveArm(colorUp1, colorUp2, colorUp3);          // Lifted color sensor
      delay(500);
      moveArm(colorDown1, colorDown2, colorDown3);    // Lowered color sensor
      delay(500);
      color = readColor();                            // Run function readColor
      delay(10);
    
    switch (color)                                    // Switch case find color
    
    {                     // Each case go to right color container and drop element.
                          // Update the counted color to int
      case 1:
        moveToBox(pos11Up, pos12Up, pos13Up, pos11Down, pos12Down, pos13Down);
        blackCount++;
      break;
    
      case 2:
        moveToBox(pos21Up, pos22Up, pos23Up, pos21Down, pos22Down, pos23Down);
        redCount++;
      break;
     
      case 3:
        moveToBox(pos31Up, pos32Up, pos33Up, pos31Down, pos32Down, pos33Down);
        yellowCount++;
      break;
     
      case 4:
        moveToBox(pos41Up, pos42Up, pos43Up, pos41Down, pos42Down, pos43Down);
        blueCount++;
      break;
    }
    moveArm(home1, home2, home3);                  // Robot home
    color = 0;                                     // Reset color
  }
 }
   
   if (incomeInt == 4)                              // If number is 4 from Node-RED stop robot
    {
      digitalWrite(redPin, HIGH);
      digitalWrite(greenPin, LOW);
      digitalWrite(bluePin, LOW);

      // The string with the counted values are sent to Node-RED
      outString = String(countNo)+ ";" + String(blackCount) + ";" + String(redCount) + ";" + String(yellowCount) + ";" + String(blueCount);
      Serial.println(outString);
	//Reset values
      blackCount = 0;
      redCount = 0;
      yellowCount = 0;
      blueCount = 0;
      incomeInt = 0;
      countNo++;
    }
}

Step 3: Node-RED

The data from Arduino has to be handled by Node-RED to be sent the MySQL database. Node-RED and arduino are connected by a serial connection using baud rate of 57600. The data are send to a function insert data to MySQL:

var data = msg.payload.split(";");<br>
var tempCountNo = data[0];
var tempBlack = data[1];
var tempRed = data[2];
var tempYellow = data[3];
var tempBlue = data[4];

var out = "INSERT INTO counter (CountNo,Date,BlackCount,RedCount,YellowCount,BlueCount) VALUES('"+tempCountNo+"','"+new Date().toISOString().slice(0, 19).replace('T', ' ')+"','"+tempBlack+"','"+tempRed+"','"+tempYellow+"','"+tempBlue+"')";
msg.topic = out;

return msg;

The function splits up the data and uses SQL to send it to the database.

The data are also send to the function bar chart count. Where it is split the same way, but then placed in an array that is used in a bar chart, that is shown on the dashboard.

var data = msg.payload.split(";");<br>
var tempCountNo = data[0];
var tempBlack = data[1];
var tempRed = data[2];
var tempYellow = data[3];
var tempBlue = data[4];

var bar={};
bar.labels = ["Black","Red","Yellow","Blue"];
bar.series = ['Count'];
bar.data = [[tempBlack,tempRed,tempYellow,tempBlue]];
return {payload:[bar]};

On the dashboard there are also placed two buttons to control the Arduino. When pushed the start button sends out a string with 5 and if the stop button is pushed a string with 4 is send trough the serial connection to the Arduino.

The Update stock button is used to get the stock data created in Windows Forms Application. When the button is pushed it sends a timestamp to activate the function select last stock MySQL.

msg.topic = "SELECT * FROM stock ORDER BY StockCountNo DESC LIMIT 1";
return msg;

It selects all the last elements in each column and creates an array of the data.

The data are then split again in the function bar chart stock and made into an array the bar chart understands, and shown in the dashboard.

var data = msg.payload;<br>
var tempBlack = data[0]['BlackCount'];
var tempRed = data[0]['RedCount'];
var tempYellow = data[0]['YellowCount'];
var tempBlue = data[0]['BlueCount'];

var bar={};
bar.labels = ["Black","Red","Yellow","Blue"];
bar.series = ['Count'];
bar.data = [[tempBlack,tempRed,tempYellow,tempBlue]];
return {payload:[bar]};

Step 4: Node-RED Dashboard

First picture shows how the dashboard looks like when operating and data are received. Picture 2 shows the layout setup for the dashboard.

Step 5: MySQL

To store all the data there are made a MySQL database. In that database four tables are made. The counter table is where all the counting data from the arduino are stored at. The primary key attribute is the CountNo that is given by the arduino which is counted up every count made. Next attribute is the date so there can be made statistics on items counted per day or hour. The last attributes are the values of each color.

The stock table has similar attributes as the counter table. Except for the name of primary key. Now it is called StockCountNo and is the number for each time the stock is updated. The last row is the correct stock count.

The idea with the program was also to sell the counted colors. Therefore there are made a table for customers. Primary key is the CustomerID and then it has the attributes Name, Adress and PhoneNo.

There are also a sale table were the sold items are stored. Primary key is SaleNo and other attributes as date and the sold items. CustomerID is also an attribute in the sale table and are used as a foreign key. The two databases are in relation to each other so all the customer data don't have to be in the sales table, but only the CustomerID number.

Step 6: Windows Forms Application

To get an other application to get the data. There is made a Windows Forms Application. It is made in C# uses SQL to select and insert data to the database. The application is divided in four areas.

The first area is Counter read were it is possible to see all the saved data from the counting. To find data it is possible to search with the countNo or search by date from the drop down menu. The update counts button updates the drop down menu with the latest counts.

The stock area show how many items there are in stock. It is calculated by all the counted items subtracted with the sold items.

In the New customer area it is possible to add a new customer to the customer table. The program finds the last CustomerID and creates the customer as the next number.

The last is the sale area. All the customers created are in the drop down menu and one has to be chosen to create a sale. Number of items wanted to be sold are inputted. There can not be sold more items than in stock. When a sale is created it is possible to see it in the data grid window. The window shows all sales to the selected customer.

Step 7: Industry 4.0

The project also focuses on industry 4.0, and to make production smarter. In this project it is tried to incorporate as much as possible.

Smart connected: All the data from the Arduino are send to a database from were all applications can get the data. The applications can get access to the data from anywhere using the internet. In this project two user interfaces are created an using the same data from the database. So you no longer has to be next to the machine to operate and control it.

Flexible: A robot arm is very flexible and can be programmed to do a lot of things very easily, while other machines only are made to do one thing. In this project it would be easy to make the do other things. Now the robot got a electromagnet mounted, but it could be a gripper to get nonmagnetic materials. Also the color sensor could be changed with other sensors.

Social: Social production is were the consumers can join in and give feedback to a product to make it better. In this project it has been difficult to get a way to get response from customers. But maybe there could have been a text field were someone could send a message to the database.

High quality services: This is were you in a production save as much data as you can and then make a lot of statistics on them. This is to get an overview of where there could be problems in a production and were can it be improved. In this project all data from the machine are saved in the database. Also from the stock and sales system in the application. It can all be made to see statistics on how much are counted or sold over a time.

It is a small robot and even though the project made the robot controllable from anywhere it is possible to work next to it, without being hurt. It works fine without a protection cage.

Step 8: The Final Result

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Plastics Contest

      Plastics Contest

    Discussions