Labeling Machine

Hello !

My name is Cristian nd i'm new to the Arduino world. i've made some small LED, Switches and Servo projects with my Arduino UNO board.
I'm looking to make a labeling machine project using the input from an PNP/NPN output sensor.
Components used :
Micro-switch(to start the labeling cycle), Label sensor , wich is 12-24Vcc , and it it commands a relay witch comands the main drive motor (wich is a motor with brake function)
The description of the machine functioning:

The machine is powered on, and it starts the program, but does not start the motor(relay).
the switch is pressed, then the Arduino sends a signal to the relay, and keeps it on (motor is started) until the next singnal (detection of gap between the labels) , wich stops the cicle. and then waits for the switch to be pressed.

Any ideas/recomandation to study for doing this project ?

Please be patient, I am willing to learn!
Thank you ,
Cristi

Welcome to the Arduino forum. You have undertaken quite a project for a beginner!

Do you have all the mechanical parts of your labeling machine working properly right now?

Paul

Thank you Paul,
Yes, i have tested all the parts.
In fact i have a labeling chasis and components laying around defective at work for about a year,wich i was hoping to revive and improve.
So no stress about mechanical parts. Only the arduino programing and setting up is the issue.

First thing to figure out is how to connect the sensor signal to the Arduino board. I was thinking of using a voltage divider or 5v voltage regulator. What do you think ?

ICristi:
Thank you Paul,
Yes, i have tested all the parts.
In fact i have a labeling chasis and components laying around defective at work for about a year,wich i was hoping to revive and improve.
So no stress about mechanical parts. Only the arduino programing and setting up is the issue.

First thing to figure out is how to connect the sensor signal to the Arduino board. I was thinking of using a voltage divider or 5v voltage regulator. What do you think ?

That's great! You are so far ahead of many of the people posting on the forum.

If this was my project I would focus on the unknown part first and that is how to identify the gap in your labels, what ever that means. Can you use a mechanical sensor or a light sensor that monitors light passing through the label backing? Perhaps a bit more information?

Paul

Hello,

First of all ,sorry for the late reply!

i will try to simplify this:

So the schematic is quite simple : there are 3 components:

1-SW1 (NO switch) connected to +5v and pin 2
2-R (Relay) connected to 5v supply, and command to pin 13
3-SW2 (NO switch) connected to +5v and pin 10

the program will start OFF by default (so digitalWrite(13,0)

whenSW1 is pressed briefly or kept press, then R is turned on UNTILL SW2 is pressed briefly or kept pressed.

i have tried the following code :

void setup(){
pinMode(13,OUTPUT);
pinMode(2,INPUT);
pinMode(10,INPUT);
digitalWrite(13,0);
}

void loop(){
if(digitalRead(2)){
digitalWrite(13,1);
}
if(digitalRead(10)){
digitalWrite(13,0);

}
}

both pins 2 and 10 turn on pin 13 (onboard LED) but do not keep their value

What could be the problem ?

If you had actually drawn a schematic of your wiring, you would see the problem!!!!

You have left the pins FLOATING! when they are not pressed.

Paul

I forgot to mention that i added the 10 k pull-down resistors.

so they are not floating .

for some reason i could not move pin 3 to pin 10 , but ypu get the ideea

both pins 2 and 10 turn on pin 13 (onboard LED) but do not keep their value

These square momentary switch "buttons" have a two pairs of connected legs and two pair of switched legs. You can easily connect them incorrectly.

It is always best to wire diagonally across these switches to ensure that you pick up the switched legs and not the connected ones.

Please verify that you are connected across switched legs of these square momentary switches.

the micro switches are connected correctly. i have tested them previously.
i have even removed them and placed a jumper wire instead.
the behaviour is the same

i have even tried mBlock,

in mblock if i do not use the second “if statement”, the circuit works ok- it only switches on the 13 pin
but i want it to switch off by reading pin 10 also…

It more simple and less prone to error to run these switches between the input pin and ground, where the input pin is pulled up with an internal pullup resistor by using pinMode(#,INPUT_PULLUP).

If you remove the 5v and pulldowns on the switches, change the pinMode to INPUT_PULLUP, and wire the switches between the input pin and ground, and reverse the logic to !digitalRead() does it function as desired?

It would be better if your code responded to a change in state of the switch inputs (when the switch changes from LOW to HIGH, or HIGH to LOW), rather than checking to see if the switch input is HIGH or LOW. Otherwise you will run into problems when trying to start the motor while the 2nd switch is sitting over a label gap, and likewise trouble stopping it if someone decides to sit and hold the start button down. Have a look at the tutorial on State Change Detection

cattledog:
It more simple and less prone to error to run these switches between the input pin and ground, where the input pin is pulled up with an internal pullup resistor by using pinMode(#,INPUT_PULLUP).

If you remove the 5v and pulldowns on the switches, change the pinMode to INPUT_PULLUP, and wire the switches between the input pin and ground, and reverse the logic to !digitalRead() does it function as desired?

Thank you !
It is much more simple now, and it works.

this is the code i used :

void setup() {

Serial.begin(9600);

pinMode(2, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(12, OUTPUT);

}

void loop() {

int Switch = digitalRead(2);
int Sensor = digitalRead(7);

Serial.println(Switch);

if (Switch == LOW) {
digitalWrite(12, HIGH);
}
if (Sensor == LOW) {
digitalWrite(12, LOW);
}

}

BUT:
when i press SWITCH(2), pin 12 is high.
if i release switch 2 and press switch (7) pin 12 is low

t is fine until this , but i need to keep switch 2 pressed, and when i press sw7 smultaneously pin 12 should get low

any thoughts ?

i need to keep switch 2 pressed, and when i press sw7 simultaneously pin 12 should get low

There are several ways to write this compound boolean logic. See && - Arduino Reference

See if this does what you want

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(12, OUTPUT);
}
void loop() {
  int Switch = digitalRead(2);
  int Sensor = digitalRead(7);
 
  Serial.println(Switch);
  
  if (Switch == LOW && Sensor == HIGH) { 
    digitalWrite(12, HIGH);
  }
  if (Sensor == LOW) {  
    digitalWrite(12, LOW);
  }
}