Hey everyone first time posting.
I am making a wall avoidance robot using Arduino however I am having issues getting the code to run the way I want.
My issue is: The motor will not operate.
**Observations:**The serial monitor shows that the sensor intermittently takes data very quickly and at the intended rate at other times.
Also,of the LEDs on the driver (A,B,C,D) A lights up and stays lit. The motor itself will also end up becoming warm if left plugged in while inspecting code.
I have also noticed that my sensor will return 0’s when plugged into my breadboard unless I wiggle the pins into a certain position.
My setup is:
Arduino Uno board
HC-SR04 Ultrasonic distance sensor
28byj-48 5 V step motor
Step control board that looks like this one http://www.hobbyking.com/hobbyking/store/__26925__Stepper_Motor_and_Driver_Board_5V.html?gclid=Cj0KEQjw4J-6BRD3h_KIoqijwvkBEiQAfcPiBaDQKext3OZSx4mQhigDhAukq9Po6z5QuXbgatzFavgaAhbP8P8HAQ
My code is:
/*Mark II moves forward as the code states. Now I will attempt to get it to read the distance
and move at the same time*/
//all necessary for the distance calculator
int echoPin=11;
int trigPin=12;
int ledPin=13;
int val=0;
long duration;
//stepper library
#include <CustomStepper.h>
//required statement for the motor
CustomStepper stepper(2,3,4,5,(byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 4075.7728395, 12, CW);
void setup() {
//sets rpm
stepper.setRPM(12);
//sets step per rotation. I dont actually know what to put but the other code works so what the hell
stepper.setSPR(4075.7728395);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin, LOW);
delay(2);
digitalWrite(trigPin, HIGH);
delay(10);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin, HIGH);
//distance is in cm based on speed of sound
val=duration/58.2;
Serial.print("Distance: ");
Serial.print(val);
Serial.println(" cm");
delay(1000);
if (stepper.isDone())
{
stepper.setDirection(CCW);
stepper.rotate();
}
stepper.run();
}
If you need any more information from me I would be more than happy to provide it so I can get this project moving again!