Control stepper motor with a sonar module
hello, i'm beginner arduino , i'm busy project want control stepper motor distance person sonar. i'm pretty close think problem stepper motor uses positive values go clockwise , negative values go counter clockwise. in code sonar measures in cm gives positive values stepper motor. how make numbers negative when person comes closer sonar module?
her code now:
i hope can me! in advance
her code now:
code: [select]
#include <steppermotor.h>
steppermotor motor(8,9,10,11);
#define trigpin 6
#define echopin 12
void setup() {
serial.begin (9600);
motor.setstepduration(1);
pinmode(trigpin, output);
pinmode(echopin, input);
}
void loop() {
long duration, distance;
digitalwrite(trigpin, low);
delaymicroseconds(2);
digitalwrite(trigpin, high);
delaymicroseconds(10);
digitalwrite(trigpin, low);
duration = pulsein(echopin, high);
distance = (duration/2) / 29.1;
motor.step(distance);
}
i hope can me! in advance
how make numbers negative when person comes closer sonar module?pick distance represents threshold want , subtract sonar measurement.
...r
Arduino Forum > Using Arduino > Project Guidance > Control stepper motor with a sonar module
arduino
Comments
Post a Comment