Stepper motor laser sensor input

Hi Everyone,

This is my first post here, so I hope I do everything right!

My problem:

I made my own small conveyor belt (Stepper motor conveyor belt by ErwinDuif - Thingiverse) and now I want to add a KY-008 laser diode and sensor (https://www.elabpeers.com/ky-008-laser-x-laser-detector.html) to this system so it automatically stops when a object breaks the laser beam.

I'm really a beginner in programming a Arduino so I don't know where to start:
I have the neme 17 working with a easy driver and some basic code, and i can get a value out of the sensor that is 0 for when the beam is broken and 1 if the beam is good.

So the code must be something like:

if laser output = 1, stepper motor run
if laser output = 0, stepper motor stop

But I don't know how to make that in working code
Is there some one that can help me!!

Laser_code.ino (558 Bytes)

stepper_code.ino (237 Bytes)

Do you know how to write code to see if a switch is open or closed? See the IDE example code. this is exactly the same thing.

Paul

Something like (untested):

int Laser = 6;
int Detector = 7;

void setup()
{ 
  Serial.begin (9600);
  pinMode(Laser, OUTPUT);
  pinMode(Detector, INPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
}

void loop()
{
  digitalWrite(Laser, HIGH);
  boolean val = digitalRead(Detector);
  if(val)
  {
    digitalWrite(9, HIGH);
    delay(1);          
    digitalWrite(9, LOW); 
    delay(1);
  }
  //Serial.println(val);
  // delay(200);
}