Hi guys, I'm developing a color sorting project using arduino and python open CV. The colors of the objects(red,green,blue) will be detect by a web cam and the color of the object is send to arduino ide using open CV libraries by serial monitor 9600. The objects will be moved using a conyeor belt. I have to save the count of the number of red,blue,green and total count of the objects that were passed on the conyeor belt. From the open cv program the output will be sent as red object =r, blue object =b, green =g.
I have tried to get the count by adding "if" function to add respective color if the r,g or b input has recieved to the arduino ide by serial monitor 9600 as follows,
`void loop() {
if (Serial.available() > 0){
char color = Serial.read();
if (color == 'r'){
Serial.println(color);
red++;
}
else if (color == 'g'){
Serial.println(color);
green++;
}
else if (color == 'b'){
Serial.println(color);
blue++;
}
}`
This code is not working properly because the output from Open CV program is sent continuously if an object’s color is identified as follows.
Please, I need some advice to resolve this.
Thank You.