Author Topic: IR remote help  (Read 1893 times)

0 Members and 1 Guest are viewing this topic.

Offline FlumpTopic starter

  • Frequent Contributor
  • **
  • Posts: 520
  • Country: gb
IR remote help
« on: February 08, 2015, 02:49:21 pm »
this is code for a steering servo for a IR remote controlled car,
at the moment the servo stays in full left or right position unless the
"center" button is pressed, i would like the servo to center itself when it
recieves no input from the IR remote.
EX: press right button the servo steers right, release button the servo centers itself

can anyone help ?

***************************
#include <Servo.h>
#include <IRremote.h>

unsigned long Value2 = 0xFF10EF; // left
unsigned long Value1 = 0xFF5AA5; // right
unsigned long Value3 = 0xFF38C7; // center
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
 
Servo servo1;

// the setup routine runs once when you press reset:
void setup() {             

Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver

  // initialize the digital pin as an output.

servo1.attach(10); // attack servo to digital pin 10
}
// the loop routine runs over and over again forever:
void loop() {

if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }

if(results.value == Value1) { //right
servo1.write(179);
}

if(results.value == Value2) { //left
servo1.write(1);
}

if(results.value == Value3) { //center
servo1.write(80);
}

}
**********************************
 

Offline Fantasma25

  • Regular Contributor
  • *
  • Posts: 91
  • Country: mx
Re: IR remote help
« Reply #1 on: February 08, 2015, 03:13:55 pm »
You could place a bool variable at the begining of the void loop(), then change it if the ir receiver received data. If it didn't receive anything, then the variable stays the same. Then, you put a statement saying that if the variable didn't change (meaning that the receiver didn't receive anything), then center the cervo.

Another option is to check if the "irrecv.decode(&results)" returns true or false if it received data. If that's the case, then put an else statement after that where you center the cervo.

I hope it helps  ;)
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: IR remote help
« Reply #2 on: February 08, 2015, 04:44:37 pm »
Then also you You should add some timing, if you received a command how long should it steer that position in case no other command was received?
 

Offline FlumpTopic starter

  • Frequent Contributor
  • **
  • Posts: 520
  • Country: gb
Re: IR remote help
« Reply #3 on: February 08, 2015, 06:04:31 pm »
Thanks for the help Fantasma :)

This is my first go at programming Arduino well its my first go at any programming
so I don't know how to implement your ideas but it gives me an idea what to look for
so i will do some googling and see what i can find out  :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf