Hi all,
I'm in a bit of a trouble with my DC motor and a sonar range finder. This is an extremely simple problem but since I am a max/msp user I am not familiar with arduino coding that much.
I need to activate my DC motor for 1000 msec and return it if the range finder detects anything in the range of 2 meters [roughly, doesn't need to be accurate.]
I am using the ladyada mshield : Arduino motor/stepper/servo control - How to use
and Maxbotics LV-EZ3 : http://www.maxbotix.com/MaxSonar-EZ1__FAQ.html
and this is my code so far : {it has errors}
#include <AFMotor.h>
AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor.setSpeed(200); // set the speed to 200/255
}
void loop() {
int distsensor, i;
long time;
/*
for (i=0; i<50; i++) {
pulseServo(servo,0);
}
for (i=0; i<50; i++) {
pulseServo(servo,400);
}
return;
*/
distsensor = 0;
for (i=0; i<8; i++) {
distsensor += analogRead(0);
delay(50);
}
distsensor /= 8;
Serial.println(distsensor);
if (distsensor <= 500) {
Serial.print("tick");
motor.run(FORWARD); // turn it on going forward
delay(1000);
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(500);
Serial.print("tock");
motor.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}
any help or suggestion would be greatly appreciated, I have 24 hours to get this thing working!
cheers,
mani