#include <Stepper.h>
#define PIN_TRIG 3
#define PIN_ECHO 2
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
Serial.begin(115200);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
myStepper.setSpeed(60);
}
void loop() {
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
int x = pulseIn(PIN_ECHO, HIGH);
Serial.print("Distance in CM: ");
Serial.println(x / 58);
Serial.print("Distance in inches: ");
Serial.println(x / 148);
delay(1000);
if (x <= 100){
Serial.print("Distance in CM: ");
Serial.println(x / 58);
myStepper.step(stepsPerRevolution);
}
}