Now I have two other problems:
- now that I have the connection there is a conflict between what I transmit via bluetooth and the physical one
- the LCD screen doesn't work.
To better understand this is the delivery:
Design a device that allows you to count objects of different shapes that slide on a conveyor belt, and sort them.
Objects with three different shapes slide on the belt.
The shapes, seen from above and from the side, slide on the surface resting on the base, as in the lower view, but with a random angle of
orientation.
Device operating specifications:
The device must recognize and count objects of each shape, and for each recognized shape a digital signal must be activated
which will allow the object to be sorted by diverting it onto other belt paths intended for packaging, this last phase involves the collection
of objects in packs of 10 pieces, for each type of object.
Objects on the conveyor belt will be sensed using infrared devices.
The quantity of objects counted and the number of packages made, for each type, must be displayed on an LCD display and also
sent, via Bluetooth or WiFi, to a terminal (PC, smartphone, other) for viewing.
The control device must also be equipped with a button that will allow, at any time, to start the conveyor belt or
arrest him. The same button function must also be possible by sending a command from the remote terminal. When the tape stops they will be
object detection sensors are also inhibited. The movement of the tape (active tape) must be indicated by the lighting of a
Green LED. A red LED will indicate the tape stopped status. Conveyor belt motor will be driven (belt moving)
via a low level digital signal, which will assume the high state when the motor is stopped (belt stopped).
Technical specifications:
The objects have homogeneous dimensions: square base with side 9cm and height 3cm; the elevated part of object B is a cube, in position
central, with a side of 3cm, while the elevated part of object C is a parallelepiped measuring 3cm x 9cm x 3cm high placed on one side.
The sorting signals must be of the impulsive type, active at a low level, with a duration of 20ms.
The conveyor belt has a width of 20 cm.
The time between the passage of two consecutive objects in front of the sensors is at least 200 ms, during which they must be
all the actions described above are guaranteed.
This is the Arduino program:
Blockquote#include
<SoftwareSerial.h>
#include "LCD03.h"
const int switchPin = 12; // the switch connects to pin 12
const int redPin = 10;
const int greenPin = 11;
const int pinMotor1 = 8;
const int pinMotor2 = 9;
// Configurazione dei pin per il display LCD
const int rs = A0; // Pin RS collegato ad A0
const int en = 13; // Pin E collegato al pin 13
const int d4 = 2; // Pin D4 collegato al pin 2
const int d5 = 3; // Pin D5 collegato al pin 3
const int d6 = 4; // Pin D6 collegato al pin 4
const int d7 = 5; // Pin D7 collegato al pin 5
LiquidCrystal lcd(I2C_ADDR, en, rs, d4, d5, d6, d7);
//
int switchState = 0; // variable for reading the pushbutton status
char on_off = '0'; // Change to character '0'
SoftwareSerial bluetooth(6, 7); // RX, TX - change these pins as needed
void color(unsigned char red, unsigned char green, unsigned char blue) // the color generating
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
}
void setup()
{
pinMode(switchPin, INPUT); // initialize the buttonPin as input
pinMode(pinMotor1, OUTPUT);
pinMode(pinMotor2, OUTPUT);
Serial.begin(38400);
bluetooth.begin(38400); // initialize SoftwareSerial for Bluetoot
}
//
void loop()
{
// read the state of the switch value
switchState = digitalRead(switchPin);
if (switchState == HIGH)
{
on_off = '1';
}
else if (switchState == LOW)
{
on_off = '0';
}
if (bluetooth.available() > 0)
{
char receivedChar = bluetooth.read();
Serial.print("Received char: ");
Serial.println(receivedChar);
receivedChar = on_off;
if (receivedChar == '1')
{
on_off = '1'; // Change to character '1'
//switchState = HIGH;
Serial.println("Acceso");//turn on
}
else if (receivedChar == '0')
{
on_off = '0'; // Change to character '0'
//switchState = LOW;
Serial.println("Spento");//Turn off
}
}
//switchState = digitalRead(switchPin);
Serial.print("Switch state: ");
Serial.println(switchState);
Serial.print("on_off value: ");
Serial.println(on_off);
if (switchState == HIGH && on_off == '1') // if it is, the state is HIGH
{
color(0, 255, 0); // turn the led on
digitalWrite(pinMotor1, HIGH);
digitalWrite(pinMotor2, HIGH);
lcd.clear();
lcd.print("Oggetto ");
lcd.print(pieceType);
lcd.print(": ");
lcd.print(objectCount[pieceType - 1]);
if (shouldProducePackage()) {
for (int i = 0; i < maxObjects; i++) {
totalPackages[i] += objectCount[i];
objectCount[i] = 0;
}
displayTotalPackages();
}
else if (switchState == LOW || on_off == '0')
{
color(255, 0, 0); // turn the led off
digitalWrite(pinMotor1, LOW);
digitalWrite(pinMotor2, LOW);
}
delay (1000);
}
int countObjects() {
// Simula la lettura da un sensore infrarosso
// Puoi personalizzare questa logica in base al tuo sensore reale
return random(1, maxObjects + 1); // Aggiunto 1 per ottenere un numero tra 1 e maxObjects inclusi
}
bool shouldProducePackage() {
return (objectCount[0] + objectCount[1] + objectCount[2]) >= 10;
}
void displayTotalPackages() {
lcd.clear();
lcd.print("Confezioni totali:");
lcd.setCursor(0, 1);
for (int i = 0; i < maxObjects; i++) {
lcd.print("Oggetto ");
lcd.print(i + 1);
lcd.print(": ");
lcd.print(totalPackages[i]);
lcd.print(" ");
}
}