Infared Receiver problem


hi,
i building obstacle avoidance robot 2 ultrasonic distance sensors. wanted implement override keyes remote. if robot stuck somewhere, remote out , let thing. finished building robot not override yet. problem starts: uploaded program(the code below) have motors spinning , ir receiver looking out signals , in serial monitor has found. motors need more 5v usb when plug in mounted power (the mounted power 9v + 5v usb) source on robot, serial monitor doesn't pick signals. why doing that?

code:

code: [select]

#include <afmotor.h>
#include "irremote.h"

#define righttrigpin a5
#define rightechopin a4

#define lefttrigpin a3
#define leftechopin a2


// created our first motorx (called "motor") on port 3 of motorshield:
af_dcmotor leftmotor(3);

// again, time our second motor called "motor2" on port
// 4 of motorshield:
af_dcmotor rightmotor(4);
// have 2 motors called "motor" , "motor2"

/*-----( declare constants )-----*/
int receiver = 46; // output pin of ir receiver arduino digital pin 46

/*-----( declare objects )-----*/
irrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'
/*-----( declare variables )-----*/

void setup() {
 
 serial.begin(9600);
         
 pinmode(righttrigpin, output);
 pinmode(rightechopin, input);
 
 pinmode(lefttrigpin, output);
 pinmode(leftechopin, input);
 
 irrecv.enableirin(); // start receiver

}

void loop() {
 
  int rightduration, rightdistance, leftduration, leftdistance;
  digitalwrite(righttrigpin, high);
  delaymicroseconds(100);
  digitalwrite(righttrigpin, low);
 
 
  rightduration = pulsein(rightechopin, high);
  rightdistance = (rightduration/2) * 0.03435;
 
 
  delay(33);
 
  digitalwrite(lefttrigpin, high);
  delaymicroseconds(100);
  digitalwrite(lefttrigpin, low);
 
 
  leftduration = pulsein(leftechopin, high);
  leftdistance = (leftduration/2) * 0.03435;
 
 

 leftmotor.setspeed(100);
 rightmotor.setspeed(140);

 

 if (rightdistance > 30 && leftdistance > 30)
 {
   leftmotor.run(backward); 
   rightmotor.run(backward);
 }

 
 if (rightdistance < 30)
 {
   leftmotor.run(forward);
   rightmotor.run(backward);
 }
 
 
 if (leftdistance < 30)
 {
   leftmotor.run(backward);
   rightmotor.run(forward);
 }
 
 if (rightdistance < 30 && leftdistance < 30)
 {
   leftmotor.run(backward); 
   rightmotor.run(forward);
 }
 
 if (irrecv.decode(&results)) // have received ir signal?

  {
//    serial.println(results.value, hex);  un comment see raw values
    translateir();
    irrecv.resume(); // receive next value
  }
 
}

void translateir() // takes action based on ir code received
{

  switch(results.value)

  {

  case 0xff629d:
  leftmotor.run(backward);
  rightmotor.run(backward);
  break;
  case 0xff22dd: serial.println(" left");    break;
  case 0xff02fd: serial.println(" -ok-");    break;
  case 0xffc23d: serial.println(" right");   break;
  case 0xffa857: serial.println(" reverse"); break;
  case 0xff6897: serial.println(" 1");       break;
  case 0xff9867: serial.println(" 2");       break;
  case 0xffb04f: serial.println(" 3");       break;
  case 0xff30cf: serial.println(" 4");       break;
  case 0xff18e7: serial.println(" 5");       break;
  case 0xff7a85: serial.println(" 6");       break;
  case 0xff10ef: serial.println(" 7");       break;
  case 0xff38c7: serial.println(" 8");       break;
  case 0xff5aa5: serial.println(" 9");       break;
  case 0xff42bd: serial.println(" *");       break;
  case 0xff4ab5: serial.println(" 0");       break;
  case 0xff52ad: serial.println(" #");       break;
  case 0xffffffff: serial.println(" repeat");break; 

h

  }// end case

  delay(500); // not immediate repeat


} //end translateir



/* ( end ) */

you might more assistance if post diagram of wiring along model numbers of teh main devices using.....


Arduino Forum > Using Arduino > General Electronics > Infared Receiver problem


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code