Error in my programme. Can anybody help?

This is my first time program. I try to make my stepper motor (28BYJ=48) move when detect movement using Ultrasonic (HC-S404).

Model : Uno Rev3

[code]
#include <Stepper.h>
#define STEPS 2048
Stepper stepper(STEPS, 8, 10, 9, 11)

//const int dirPin = 2;
//const int stepPin = 3;
//const int enPin = 8;
const int trigPin = 2;
const int echopin = 3;
long duration;
int distancecm;

void setup ()
{
Serial.begin(9600);
//pinMode(dirPin,OUTPUT);
//pinMode(stepPin,OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
//digitalWrite(enPin,OUTPUT);
}

void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distancecm = duration * 0.034 / 2; //V=2

if (distancecm <= 10)
{
stepper.setSpeed(15);
stepper.step(2048 * .5);
delay (1000);
stepper.setSpeed(15);
stepper.step(-2048 * .5);
}
}

[/code]Preformatted text

You can help us by posting a schematic, not a frizzy thing showing all interconnections, power supplies etc. Also include links to technical information on all the hardware devices.

I manage to solve the problem. Thanks mate

1 Like

What did you find?