Hello all,
First to introduce myself: I am an automotive engineer with limited programming skills.
I am new to arduino but determined to make this project work.
As the project stands now I have an arduino mega, an external 5v power supply, 24v power supply, 8 channel relay board and 8 channel opto-coupler.
The project I am working on is an unwinding table: this table grips material and while it is clamping, a heat wire is applied that "welds" the material together. Then the material is pulled forward after which it is cut off by another hot wire that should go out after x seconds. Then the clamping plate goes up and back again to the beginning. This schematically looks like this.
I got it working by simply controlling the relays via different delays. The goal is to make it work through sensors.
This is the code with the simple delays:
#define clamp 6
#define linear 7
#define cut 8
void setup() {
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
}
void loop() {
digitalWrite(cut,LOW);
delay(500);
digitalWrite(clamp,HIGH);
delay(1500);
digitalWrite(linear,HIGH);
delay(4000);
digitalWrite(clamp,LOW);
delay(1000);
digitalWrite(cut,HIGH);
delay(1000);
digitalWrite(linear,LOW);
delay(4000);
}
This makes it move exactly like it should, but there are no safety features possible hence I want to use sensors for moving to the next step. First video shows how it moves
There are 2 sensors on each cylinder at the end stops.
To read the sensors I used an opto coupler because the sensors work on 24 volts. The code to read it and drive a relay looks like this: (this was a standard piece of code that I modified a bit)
int input_pin = 5;
int led_pin = 9;
#define clamp 6
void setup()
{
pinMode(6,OUTPUT);
pinMode( input_pin , INPUT_PULLUP);
pinMode( led_pin , OUTPUT);
Serial.begin(9600);
}
void loop()
{
int i = digitalRead( input_pin );
// digitalWrite(led_pin);
Serial.println(i);
if (i == LOW) { // check if the input is LOW (no detection)
digitalWrite(clamp, HIGH); // turn LED OFF
} else {
digitalWrite(clamp, LOW); // turn LED ON
}
}
The intention is that the system will work by means of the sensors that must be active in certain steps in the process in order to proceed to the next step. (see excel picture)
Video down below is to show the setup with a sensor.
I wanted to tackle this project on my own but it is more difficult than I anticipated for. From what I have seen the best way to make this work is by a state machine. Because a state machine is pretty advanced (at least for me) I was hoping to get some tips and tricks or good example code that I can use.
Hope some of you can help me.
Thanks in advance
