Go Down

Topic: Newbies with Arduino Infrared (Read 1 time) previous topic - next topic

lohan

[font=Verdana]Hi, as the topic shows, I'm a newbie with arduino and have some question with infrared LED VS1838B.

i)I am making a remote controlled mini car using arduino infrared and attempt to control it with left/right, forward/backward. What kind of coding should i use?
ii)And the RX is VS1838B, how should I make a TX? Should I find a TX that same frequency with the RX? or i can just use a simple tx and control both tx and rx by arduino?

I'm a newbie and i really mean it. Please give suggestion to me. Thanks! :)
[/font]

afremont

You just need an infrared LED to generate a signal that your receiver can pick up.  There is a library for doing IR remote control, that would probably be the easiest route to go as it will generate the 38kHz carrier for the IR LED.
Experience, it's what you get when you were expecting something else.

JimboZA

Even easier is to use a tv remote and use Ken shirriff's work here to de-code the buttons. Then write a new sketch using the IRremote library to use the buttons' codes to (eg) accelerate, turn, stop etc etc.
My hovercraft is full of eels.

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

lohan

The Ken shirriff's work did help me alot. Thanks! But i still have some question:

i) How should i switch on an led by using the coding? I have no idea to change it. ><

JimboZA

Quote
How should i switch on an led by using the coding? I have no idea to change it. ><


Here's some code I used to make an LED go brighter and dimmer using the "up" and "down" buttons on a tv remote. Note that my particular remote produces 2 codes for each button, alternating on each press.

Code: [Select]
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/

/* well now it controls the brightness of an LED
   LED is PWM'd on pin5
   *******   PWM on pin3 seems disabled when using IR?
   uses the volume key... up to brighten, down to dim
   under rc5, the keys have two toggled values
   down:    411 or c11 hex; 1041 or 3089 dec
   up:      410 or c10 hex; 1040 or 3088 dec
*/
               

#include <IRremote.h>

int RECV_PIN = 11;
int led_pin = 5;   // seems PWM not work on 3 with IR library
int led_bright = 130;  //half way to start
int led_step = 10;     // and change in pwm steps of 10

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(led_pin, OUTPUT);
  analogWrite(led_pin, led_bright);
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
   
    //now check if it's correct key and act...
    //down
    if (results.value == 1041 || results.value == 3089) {
      led_bright = led_bright - led_step;
      if (led_bright < 10) {
        led_bright = 10;
        }
      Serial.print("Going down to ");
      Serial.println(led_bright);
      analogWrite(led_pin, led_bright);
    }
   
    //up
    if (results.value == 1040 || results.value == 3088) {
      led_bright = led_bright + led_step;
      if (led_bright > 255) {
        led_bright = 255;
      }
      Serial.print("Going up to ");
      Serial.println(led_bright);
      analogWrite(led_pin, led_bright);
    }
  }
}


I eventually used similar coding to control robot motors
My hovercraft is full of eels.

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

Go Up