int sensorPin = 42; // select the input pin for the potentiometer int stepperPin = 23; // select the pin for the LED int dirPin = 40; // 0 for CW 1 for CCW int sensorValue = 0; // variable to store the value coming from the sensor int sensorValue2 =0; // variable for sensor2 int triggerPin = 39; int ledPin = 16; int sensorPin2 = 43; int powerLight = 6; int Enable = 41; void setup() { // declare the ledPin as an OUTPUT: pinMode(stepperPin, OUTPUT); pinMode(dirPin, OUTPUT); pinMode(triggerPin, OUTPUT); pinMode(ledPin, OUTPUT); Serial.begin(9600); pinMode(powerLight, OUTPUT); pinMode (Enable, OUTPUT); } void powerlight(){ digitalWrite(powerLight, HIGH); delay(500); digitalWrite(powerLight, LOW); delay(500); } void scanner(){ for(int i=0;i<4;i++){ digitalWrite(stepperPin, HIGH); //start motor, move 40um delay(2); digitalWrite(stepperPin, LOW);} analogWrite(ledPin, 15); //Open Shutter delay(5); digitalWrite(triggerPin, HIGH); //aquire spectrum delay(10); digitalWrite(triggerPin, LOW); delay(40); digitalWrite(triggerPin, HIGH); //aquire spectrum delay(10); digitalWrite(triggerPin, LOW); delay(40); digitalWrite(triggerPin, HIGH); //aquire spectrum delay(10); digitalWrite(triggerPin, LOW); delay(40); digitalWrite(triggerPin, HIGH); //aquire spectrum delay(10); digitalWrite(triggerPin, LOW); delay(40); digitalWrite(triggerPin, HIGH); //aquire spectrum delay(10); digitalWrite(triggerPin, LOW); delay(40); digitalWrite(ledPin, 0); delay(25); } void reposition(){ sensorValue2 = analogRead(sensorPin2); //using open builds nema23 and half step mode, this is 8mm or 20um/step Serial.print(sensorValue2); if (sensorValue2 >= 500){ for(int i=0;i<400;i++){ digitalWrite(stepperPin, HIGH); delay(2); digitalWrite(stepperPin, LOW); } } } void loop() { powerlight(); digitalWrite(dirPin, LOW); sensorValue = analogRead(sensorPin); Serial.print(sensorValue); if (sensorValue >= 500){ for(int i=0;i<800;i++) scanner(); } Serial.print("aaa"); reposition(); }