Obstacle avoidance stepper
Read moreI designed this project because I needed to solve a problem with an old stencil machine. The stencil was not going in the same trajectory so this is how my project works:
When the sensor detects that the stencil has moved slightly, the stepper activates and rotates the lever which repositions the stencil on the right trajectory.
This can be reversed by removing the ! in the if (detect != HIGH)
void setup() {
Serial.begin(9600);
pinMode(3, INPUT); //IR Sensor
pinMode(8, OUTPUT); // Stepper Direction
pinMode(9, OUTPUT); // Stepper Step
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
int detect = digitalRead (3);
if (detect != HIGH){
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(500);
}
else{
if(detect == LOW)
digitalWrite(9, LOW);
delayMicroseconds(500);
digitalWrite(9, HIGH);
delayMicroseconds(500);
}
}
*the speed is set to 500ms.
Comments