How to control stepper motors with hc-rs04 on Aruino uno? [closed]

  arduino, arduino-uno, c++
#include <CustomStepper.h>
#include <Ultrasonic.h> //Here I added 2 libraries

CustomStepper stepper1(4,5,6,7); 
CustomStepper stepper2(8,9,10,11); //Here I connected ports for stepper motors.I have 2 of them

int example1 = 1; 
int example2 = 1;

Ultrasonic ultrasonic(12, 13); //I connected the subscriber to ports 12.13
int distance;

void setup()
{ 
    Serial.begin(9600);
    stepper1.setRPM(10); 
    stepper1.setSPR(2075.7728395); 
    stepper2.setRPM(10); 
    stepper2.setSPR(2075.7728395);
}

void loop()
{
    if (stepper1.isDone() and example1 == 1)//Wiring for stepper motors
    {
        stepper1.setDirection(CCW);   
        stepper1.rotate(1);   
    }
    stepper1.run(); 
    if (stepper2.isDone() and example2 == 1)
    {
         stepper2.setDirection(CW);  
         stepper2.rotate(1);      
    }
    stepper2.run();   
    
    distance = ultrasonic.read();
      //hc-rs04 records the distance of the object in cm.
    Serial.print("Distance in CM: ");
    Serial.println(distance);

}

I downloaded 2 sketches. # 1 for stepper motor. # 2 for hc-rs04. They work separately. But I need that when hs-rc04 receives a signal in the state of 20 cm, a code is triggered that will stop the stepper motor.

Source: Windows Questions C++

LEAVE A COMMENT