Hello guys, i am very new to arduino, actually i have never done anything on arduino yet, i'm just trying to do my project. We have 28 BYJ-48 Stepper motor and ULN2003A driver. We are expected to design a garage door, and we are using proximity sensor that will control stepper motor and that motor needs to rotate the garage door 90 degrees. But we couldn't manage to do it. Our stepper rotates 90 degrees + and then -. It doesn't stop and also we don't know how to make sensor and motor work together. It is kinda urgent we couldn't make it by ourselves i need help. Thanks
HINT : There is nothing wrong with the code that you have not posted, nor with the circuit diagram that you have not posted.
#include <Stepper.h>
int motorPin1 = 8; // Blue - 28BYJ48 pin 1
int motorPin2 = 9; // Pink - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
// Red - 28BYJ48 pin 5 (VCC)
int motorSpeed = 1000; //variable to set stepper speed
int count = 0; // count of steps made
int countsperrev = 128; // number of steps per 1/4 revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
//////////////////////////////////////////////////////////////////////////////
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}
//////////////////////////////////////////////////////////////////////////////
void loop(){
if(count < countsperrev )
clockwise();
else if (count == countsperrev * 2)
count = 0;
else
anticlockwise();
count++;
}
void anticlockwise()
{
for(int i = 0; i < 8; i++)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}
void clockwise()
{
for(int i = 7; i >= 0; i--)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}
void setOutput(int out)
{
digitalWrite(motorPin1, bitRead(lookup[out], 0));
digitalWrite(motorPin2, bitRead(lookup[out], 1));
digitalWrite(motorPin3, bitRead(lookup[out], 2));
digitalWrite(motorPin4, bitRead(lookup[out], 3));
}
#include <Stepper.h>
// the number of steps on your motor
#define STEPS 4096
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);
// Variables for ultrasonic sensor
// defines pins numbers
const int trigPin = 5;
const int echoPin = 6;
// defines variables
long duration;
float distance;
void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
//setup for the sensor
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void readSensor() {
//reads the value of ultrasonic sensor and prints it
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
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;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
void loop() {
//clockwise rotation
for(int i = 0; i < 30; i++)
{
// move one step
stepper.step(1);
readSensor();
}
//anticlockwise rotation
for(int i = 0; i < 30; i++)
{
// move one step in reverse
stepper.step(-1);
readSensor();
}
}
And we have this code, but when we put our hand in front of the sensor it stops and when we pull it back it rotates but it rotates 360. We need the opposite when we put the object it will rotate 90 degree when we pull it back it will rotate 90 degree opposite side.
xmperez was banned as he requested.
Any more requests like that ?
Bob.
do you still have the circuit diagram where the pins connections are.can you send it to me