Internet controlled robot with Android and Arduino NEED HELP


hi guys!

i making robot controlled on internet , uses android phone shield.

i using this app on phone connected arduino uno , this app on android phone control robot.
basically controller app sends byte command app on phone connected board on usb.

i able control onboard led using code

code: [select]
int ledpin = 13;

void setup ()
{
  serial.begin(9600);
  pinmode(ledpin, output);
}


void loop()

 while (serial.available() == 0);
 
 int val = serial.read();
 
 if (val == 1)
 {
  serial.println("led on");
  digitalwrite(ledpin, high);
 }

 if (val == 2)
 {
  serial.println("led off");
  digitalwrite(ledpin, low);
 }
 
 serial.println(val);




however later attached adafruit motor shield , tried control dc motors nothing happened.
i used code

code: [select]


#include <afmotor.h>
#include <softwareserial.h> 
char val;  // variable receive data serial port
// dc motor on m1
af_dcmotor motor(1);
// dc motor on m2
af_dcmotor motor2(2);
int i;
void setup() {
  serial.begin(9600);   
 
  // turn on motor #1
  motor.setspeed(200);
  motor.run(release);
  // turn on motor #2
  motor2.setspeed(200);
  motor2.run(release);
}
// move forward
void go_forward(){
  motor.run(forward);
  motor2.run(forward);
 for (i=0; i<255; i++) {
    motor.setspeed(i);
    motor2.setspeed(i); 
  }
}
// move reverse
void go_reverse(){

  motor.run(backward);
  motor2.run(backward);

  (i=0; i<255; i++) {
    motor.setspeed(i);
    motor2.setspeed(i);
   }
  }
// move left
void stop_go_forward(){
 motor.run(release);
motor2.run(release);
}
void go_left(){

  motor.run(forward);
  (i=0; i<255; i++) {
    motor.setspeed(i);
   }
  }
  // move right
void go_right(){

  motor2.run(forward);
  (i=0; i<255; i++) {
    motor2.setspeed(i);
   }
  }

// read serial port , perform command
void loop ( )
{
   if ( serial.available())
  {
      // write serial command value
    byte command = serial.read();
    if (command == '1')
   { // forward
      go_forward();
      serial.println("forward\n");
    }

        if (command == '2')
   { // forward
      stop_go_forward();
      serial.println("stop\n");
    }
   
    }
}



the point works if use android serial monitor arduino phone hooked board on usb.

this 1 works on arduino serial monitor not apps

code: [select]
#include <softwareserial.h> //the library seial communication
#include <afmotor.h> // library adafruit l293 arduino motor shield
int incomingbyte = 0; // incoming serial data
int speed_min = 80; //the minimum "speed" motors turn - take lower , motors don't turn
int speed_max = 255; //the maximum "speed" motors turn - can't put in higher

int speed_left = speed_max; // set both motors maximum speed
int speed_right = speed_max;

//as added motor shield library can use following code define our m1 , m2 motors , pwm frequency
//the library takes care of complexity of physical interface arduino uses talk shield , motor
af_dcmotor motor_left(1, motor12_1khz); // create motor #1, 1khz pwm
af_dcmotor motor_right(4, motor12_1khz); // create motor #2, 1khz pwm

void setup() {
serial.begin(9600); // set serial library @ 9600 bps - speed serial interface work at
serial.println("motor test!");// display message test purposes when connected serial monitor
}



void loop() {
  //this our repeating loop - go round , round until switch arduino off
  motor_left.setspeed(speed_left); // minimum speed 135   max speed 255
motor_right.setspeed(speed_right); // minimum speed 135   max speed 255 
       
//first check if there on serial interface
//we using arduino's default serial interface (pins 0 , 1)so no need define these
    if (serial.available() > 0) {
    // read incoming byte:
    incomingbyte = serial.read();
   
    }

  // if there on serial interface read , assigned incomingbyte
  // use switch (case) statement which, depending on incomingbyte, different things
  // runs left , right motors produce movement forward, backward, left, right or stop
  //that's there it!
 
  switch(incomingbyte)
  {
     case 's':
         // stop motors
      { motor_left.run(release); // stopped
       motor_right.run(release); // stopped
       serial.println("stop\n"); //display message test purposes when connected serial monitor
       incomingbyte='*';}
     
     break;
     
     case '8':
       // turn on going forward
     {  motor_left.run(forward);
       
       serial.println("forward\n");//display message test purposes when connected serial monitor
       incomingbyte='*';}
     break;
   
      case '9':
        // turn on going backward
    {   motor_left.run(backward);
       
       serial.println("backward\n");//display message test purposes when connected serial monitor
       incomingbyte='*';}
     break;
     
     case 'r':
     // turn right
     { 
       motor_right.run(forward);
       serial.println("rotate right\n");//display message test purposes
       incomingbyte='*';}
     break;

     
       case 'l':
        // turn left
      {
       motor_right.run(backward);     
       serial.println("rotate left\n");//display message test purposes
       incomingbyte='*';}
     break;
     
     case '1':
        // put in here - example - change motor speeds
      { speed_left = speed_min; // set both motors minimum speed
       speed_right = speed_min;
       serial.println("speed min\n");//display message test purposes
       incomingbyte='*';}
     break;
     
     case '2':
        // put in here - example - change motor speeds
      { speed_left = speed_max; // set both motors minimum speed
       speed_right = speed_max;
       serial.println("speed max\n");//display message test purposes
       incomingbyte='*';}
     break;     
  }
}


can please me figure stuff out?

ok guys figured out. have new problem.
when move joystick in app sends "1" command board.

code: [select]
if (command == 1)
void loop()

  motor_left.setspeed(speed_left); // minimum speed 135   max speed 255
  motor_right.setspeed(speed_right); // minimum speed 135   max speed 255 
  while (serial.available() == 0);
 
 byte command = serial.read();

 if (command == 1)
 {
  serial.println("led on");
  motor_left.run(forward);
  digitalwrite(ledpin, high);
 }


when release joystick stops sending command.
what can stop  motor if there no command?


Arduino Forum > Using Arduino > Project Guidance > Internet controlled robot with Android and Arduino NEED HELP


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor