stepper motor not working

i have made a project which shows the distance of object using lights in led. i have used stepper motor to indicate how it will automatically stop when object is near. the led and ultrasonic sensor is working but the stepeer motor doesnt seem to rotate when object is far. code is below

#include <Stepper.h>

#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11

int redPin= 2;
int greenPin = 3;
int bluePin = 4;
// defines pins numbers
const int trigPin = 5;
const int echoPin = 6;

// defines variables
long duration;
int distance;
int safetyDistance;

Stepper stepper(100, IN1, IN2, IN3, IN4);

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
Serial.begin(9600); // Starts the serial communication
void loop() {
int sensorValue = analogRead(A0);

// Clears the trigPin
digitalWrite(trigPin, LOW);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculating the distance
distance= duration*0.034/2;
if (distance>5)
setColor(0, 255, 0); // green Color

setColor(255, 0, 0); // Red Color

void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);


it is vibrating but not rotating

Have you got the motor working properly with a simple program that make it go (say) 400 steps forward and backward?

If not, get that working first.


PS … To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

distance= duration*0.034/2;

Both distance and duration are integers, so this just sets distance to zero.