ir with tv remote control

Hi,

I am very new at this and I have till Dec 6th to finish my art project. I want to be able to use a TV remote control with the arduino board to turn on the lights and a motor. I have bought a SIS 1, IR Detector module and have no idea on how to integrate that in or write the codes. I have the Diecimila board, a shield, plenty of bread boards, a couple of remote controls. Any ideas or help would be great!

A very stressed student.
Janet Z

Hi Janet-

I’m not sure how much you already know about how IR signals are transmitted from the Remote and received by the detector, but I found this document (meant to controll the Parallax BoeBot with a remote) very useful when I was trying to figure out a similar project a few years ago. The code is not for an Arduino, but it should get you started and wouldn’t be very difficult to translate.

Wow, looks complicated but I will try it. My only experience so far is to make blinking lights with the arduino board but I am a fast learner. My question is should I put the Sony code in before the blink code? I want the remote to control the board so the lights should be off and blink when you push the remote control. Hopefully I get the stepper motor to work too and it should work in this order, push the remote, the stepper motor spins, stop, and then the lights blink, stop, and then the 2nd set of lights will blink, then off.

Thanks for all your help!
Janet Z

Sony IR signals are the easiest to decode; I’ve done it with the BASIC Stamp, the SX (I used to work for Parallax), and now I’ve ported the code to Arduino. Give this a try (it worked with my Sony remote):

// --------------------------------------
// SIRCS (Sony IR Control System) Monitor
//
// Jon McPhalen
// www.jonmcphalen.com
// 30 NOV 2007
// --------------------------------------

int irPin = 7;

void setup()
{
  pinMode(irPin, INPUT);
  Serial.begin(9600);
  delay(25);
  Serial.println("SIRCS Monitor\n");
}

void loop()
{
  int key;

  key = getSircs();
  Serial.println(key, BIN);
  delay(250);
}

int getSircs() {
  int duration;
  int irCode;
  int mask;

  // wait for start bit
  do {
    duration = pulseIn(irPin, LOW);
  } while (duration < 2160 || duration > 2640);

  // get 12-bit SIRCS code
  irCode = 0;                                            // clear ir code
  mask = 1;                                              // set mask to bit 0
  for (int idx = 0; idx < 12; idx++) {                   // get all 12 bits
    duration = pulseIn(irPin, LOW);                      // measure the bit pulse
    if (duration >= 1080)                                // 1 bit?
      irCode |= mask;                                    // yes, update ir code
    mask <<= 1;                                          // shift mask to next bit
  }
  return irCode;
}

With this program you can see the values that come back from your remote, then you can plug them into an operational program.

Well I burn my IR Detector module so I went to Parallax to buy their kit and upgraded to 2 day shipping. That will give me 1 1/2 days to finish the project so it may not happen but I will try. I will at least get the lights and steper motor to work but I am hoping for the remote control as it really does add to the piece.

Thanks for your code, I will try to work that in and if I don’t finish for finals, I will finish afterwards and post the sculpting project.

Thank you all for your help, hard being a newbie with little time.

Janet

With respect, don’t assume defeat – you can do it. Test the other aspects of your project and when the IR decoder arrives fold it in. You could be done the day you get your shipment from Parallax. :wink:

Thanks for the support. I also have 2 plaster heads and a brain that I have to finish carving, the lights and motor will go inside the heads and I am guessing it may take me 2 full days to complete.

I finish the stepper motor control last night and I was wondering if anyone knew how I would integrate this into the arduino board. I asked my teacher but he is also new at this and he had no idea. The pictures are below.


I wish I had another month, lol.

Thanks,
Janet

It would be helpful if you could provide a link to documentation for that board. It looks like it has a step button on it, and what you could probably do is tie the Arduino into this (do it carefully); by pulsing an output pin your can simulate pressing the step button on the board. There’s probably a direction input as well. With two pins you can control the steppers speed (by setting a pulse rate) and direction.

I bought this at allelectronics.com, http://www.allelectronics.com/cgi-bin/item/SMKIT-2/305/STEPPER_MOTOR_CONTROLLER_KIT_.html

I scan the directions to build the kit, was amazed that I put it together and it worked.
http://www.zinganobjj.com/pics/cat-smkit-2-stepper-motor-driver.jpg

Problem is I have no knowledge of electronics, just a web designer and an art student but I am planning to buy a few books to learn as this is where I want to go with my art projects in the future. Unfortunately I have little time to read about electronics before the final art project is due on the 6th. Is there a link to read about pulsing an output pin and direction pin? It would be great if I can write a code to control the spins, that would really add to the piece.

Thank you for all your time!
Janet

If you have NO knowledge of electronics I will not encourage you to modify the circuit – if you made a mistake you could damage your Arduino.

With the right skills, however, one could remove the Fwd/Rev and Auto/Man toggle switches and tie the common points of those to two outputs of the Arduino; this would let you control direction and step rate via software Please get help – that circuit is very simple and if the switches are left in you will have problems, possibly damaging your Arduino. One thing you can do to provide a little bit of fail-safe insurance is to put a 1K resistor inline with your Arduino outputs that are feeding the stepper controller; that way, there is no possibility of a short-circuit. What the Arduino will be doing after this modification is providing the direction control (high = Fwd, low = Rev) and step speed (vary the delay between short pulses to the motor controller).

Well that sounds beyond me with the time that I have left. I think I will just leave the motor part out of the arduino as I am not sure how to make it work. And the other motors that I have are unipolar and the driver I bought is bipolar and I am out of time to get the correct parts. I will however add that in the future as soon as I figure it out. So all I need to do now is try to figure out the ir remote with the lights.

Do you have four free pins on the Arduino? If you do, you could drive a uni-polar stepper through a ULN2003.

I am using 8 out of the 13 pins for lights so yes I do, but I could bring it down to 6 lights if need be.

I don’t have a ULN2003. I have a EDE - 1204 http://www.elabinc.com/Semiconductors/ProductOverview/tabid/57/Default.aspx

and a L298N Motor control Chip.

The ULN2003 and ULN2803 are popcorn parts that cost about a buck and are easy to come by. Interestingly, if you use an L293D instead you can control unipolar or bipolar stepper with the same code. The EDE1204 is just adding a layer of interface that you really don’t need (in my opinion); driving steppers is not terribly difficult – I’ve been doing since the days of the BASIC Stamp 1, and that certainly has less power than the Arduino.

hey there,

just read you IR post - I am currently doing a similar sort of thing at uni at the moment using IR to control to control a fan and lights - rather than using a decoder I am using an IR switch that links to the arduino (you get them from maplin if ur in the UK http://store.qkits.com/moreinfo.cfm/MK161) and rather using a TV remote, (though you can if you get a universal switch http://www.electronickits.com/kit/complete/elec/ck1600.htm), you can buy a transmitter from maplin too, it comes with its own case that looks like a key fob but if you needed to make look like a TV remote for the purposes of your project you can easily just swap the case (http://www.wavecom.com.au/Velleman/Mini+Kits/MK162/MK162+2+Channel+Infrared+Remote+Transmitter.phtml
these are the ones maplin sell though they don’t come up on the website for some reason but they’re off the shelf and in the catalogue so no waiting) - the advantages of this is (I’m hoping will be finished tomorrow) that I can just plug the IR switch into the arduino through a circuit the same as the one you would use for a push button and using the same code…the arduino is none the wiser it just receives an HIGH or LOW input and doesn’t have to decode anything…I’ve gotten a similar sort of IR remote to work this way but its distance is low about (30cm), hopefully this should work up to 15m, let us know how you get on and I’ll do the same.

Good luck

Hi,

Exhausted and stressed. I can’t figure out this infared. I will have 2 hours tomorrow afternoon to try again otherwise I will just have to let it go to another project as finals are due tomorrow early eve. I bought the Parallax Infared Remote Appkit (#29122),

I have a picture of my arduino board plus the code I am using, any advice would be great.

And here is the code, it’s a long one as I am animating 2 sculpture heads.

/*
 * Blink
 *
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */
 /*
 *  File....... IRanalyzer.pde 
 *  Purpose.... Records up to 128 signal changes
 *  Author..... Walter Anderson 
 *  E-mail..... wandrson@walteranderson.us 
 *  Started.... 18 May 2007 
 *  Updated.... 18 May 2007 
 * 
 *
 */ 
 
#include <avr/interrupt.h>
#include <avr/io.h>

#define TIMER_RESET  TCNT1 = 0
#define SAMPLE_SIZE  64

int IRpin = 13;
unsigned int TimerValue[SAMPLE_SIZE];
char direction[SAMPLE_SIZE];
byte change_count;
long time;

int redPin = 2;                // Red LED connected to digital pin 2
int whitePin = 3;              // White LED connected to digital pin 3
int whitePin2 = 4;             // White2 LED connected to digital pin 4
int redPin2 = 5;               // Red2 Led connected to digital pin 5
int greenPin = 6;              // Green LED connected to digital pin 6
int yellowPin2 = 7;            // Yellow2 LED connected to digital pin 7
int yellowPin = 8;             // Yellow LED connected to digital pin 8
int greenPin2 = 9;             // Green2 LED connected to digital pin 9

void setup()                    // run once, when the sketch starts
{
  Serial.begin(115200);
  Serial.println("Analyze IR Remote");
  TCCR1A = 0x00;          // COM1A1=0, COM1A0=0 => Disconnect Pin OC1 from Timer/Counter 1 -- PWM11=0,PWM10=0 => PWM Operation disabled
  // ICNC1=0 => Capture Noise Canceler disabled -- ICES1=0 => Input Capture Edge Select (not used) -- CTC1=0 => Clear Timer/Counter 1 on Compare/Match
  // CS12=0 CS11=1 CS10=1 => Set prescaler to clock/64
  TCCR1B = 0x03;          // 16MHz clock with prescaler means TCNT1 increments every 4uS
  // ICIE1=0 => Timer/Counter 1, Input Capture Interrupt Enable -- OCIE1A=0 => Output Compare A Match Interrupt Enable -- OCIE1B=0 => Output Compare B Match Interrupt Enable
  // TOIE1=0 => Timer 1 Overflow Interrupt Enable
  TIMSK1 = 0x00;          
  pinMode(IRpin, INPUT);
  pinMode(redPin, OUTPUT);        // sets the digital pin as output
  pinMode(whitePin, OUTPUT);      // sets the digital pin as output
  pinMode(whitePin2, OUTPUT);     // sets the digital pin as output
  pinMode(redPin2, OUTPUT);       // sets the digital pin as output
  pinMode(greenPin, OUTPUT);      // sets the digital pin as output
  pinMode(yellowPin2, OUTPUT);    // sets the digital pin as output
  pinMode(yellowPin, OUTPUT);     // sets the digital pin as output
  pinMode(greenPin2, OUTPUT);     // sets the digital pin as output
}

void loop()                       // run over and over again
{
    Serial.println("Waiting...");
  change_count = 0;
  while(digitalRead(IRpin) == HIGH) {}                                 
  TIMER_RESET;
  TimerValue[change_count] = TCNT1;
  direction[change_count++] = '0';
  while (change_count < SAMPLE_SIZE) {
    if (direction[change_count-1] == '0') {
      while(digitalRead(IRpin) == LOW) {}
      TimerValue[change_count] = TCNT1;
      direction[change_count++] = '1';
    } else {
      while(digitalRead(IRpin) == HIGH) {}
      TimerValue[change_count] = TCNT1;
      direction[change_count++] = '0';
    }
  }
  Serial.println("Bit stream detected!");
  change_count = 0;
  time = (long) TimerValue[change_count] * 4;
  Serial.print(time);
  Serial.print("\t");
  Serial.println(direction[change_count++]);
  while (change_count < SAMPLE_SIZE) {
    time = (long) TimerValue[change_count] * 4;
    Serial.print(time);
    Serial.print("\t");
    Serial.println(direction[change_count-1]);
    Serial.print(time);
    Serial.print("\t");
    Serial.println(direction[change_count++]);    
  }
  Serial.println("Bit stream end!");
  delay(2000);
  digitalWrite(redPin, HIGH);     // sets the Red LED on
  digitalWrite(whitePin, LOW);   // sets the White LED off
  digitalWrite(whitePin2, LOW);   // sets the White2 LED off
  digitalWrite(redPin2, LOW);     // sets the Red2 LED off
  digitalWrite(greenPin, LOW);   // sets the Green LED off
  digitalWrite(yellowPin2, LOW);   // sets the Yellow LED off
  digitalWrite(yellowPin, LOW);     // sets the Yellow LED off
  digitalWrite(greenPin2, LOW);     // sets the Green2 LED off
  delay(500);                     // waits for half a second
  digitalWrite(redPin, LOW);     // sets the Red LED off
  digitalWrite(whitePin, HIGH);   // sets the White LED on
  digitalWrite(whitePin2, LOW);   // sets the White2 LED off
  digitalWrite(redPin2, LOW);     // sets the Red2 LED off
  digitalWrite(greenPin, LOW);   // sets the Green LED off
  digitalWrite(yellowPin2, LOW);   // sets the Yellow LED off
  digitalWrite(yellowPin, LOW);     // sets the Yellow LED off
  digitalWrite(greenPin2, LOW);     // sets the Green2 LED off
  delay(500);                     // waits for half a second
  digitalWrite(redPin, HIGH);

Wow, I’m confused – but I’m new to the Arduino and haven’t explored interrupts with it. Do you need that to read an IR signal? The code I posted earlier works with the Parallax IR sensor (I used to work for Parallax so I have a lot of Parallax components) and properly decodes Sony IR signals; and it’s dirt simple (straight C). That’s always the best policy, especially when one is under deadline pressure and stressed: keep it simple, simple, simple.

Here’s a quick program that I whipped up – more for my own practice than anything (I’m much more comfortable with BASIC than C), but, perhaps, it will be helpful to you.

// SIRCS (Sony IR Control System) Controller
//
// Jon McPhalen
// 06 DEC 2007

int irPin = 10;
int led1 = 12;
int led2 = 13;

int key;
int enabled = 0;
int status1 = LOW;
int status2 = LOW;

void setup()
{
pinMode(irPin, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
digitalWrite(led1, status1);
digitalWrite(led2, status2);

Serial.begin(57600);
delay(25);
Serial.println(“Control System Ready\n”);
}

void loop()
{
key = getSircs();
// Serial.println(key, HEX);

switch(key) {
case 0x95: // Power key
if (enabled == 0) {
enabled = 1;
Serial.println(“System enabled.”);
}
else {
enabled = 0;
Serial.println(“System disabled.”);
}
break;

case 0x80: // 1 key
if (enabled == 1) {
if (status1 == HIGH)
status1 = LOW;
else
status1 = HIGH;
digitalWrite(led1, status1);
}
break;

case 0x81: // 2 key
if (enabled == 1) {
if (status2 == HIGH)
status2 = LOW;
else
status2 = HIGH;
digitalWrite(led2, status2);
}
break;
}

delay(500); // allow key release
}

int getSircs() {
int duration;
int irCode;
int mask;

// wait for start bit
do {
duration = pulseIn(irPin, LOW);
}
while (duration < 2160 || duration > 2640);

// get 12-bit SIRCS code
irCode = 0; // clear ir code
mask = 1; // set mask to bit 0
for (int idx = 0; idx < 12; idx++) { // get all 12 bits
duration = pulseIn(irPin, LOW); // measure the bit pulse
if (duration >= 1080) // 1 bit?
irCode |= mask; // yes, update ir code
mask <<= 1; // shift mask to next bit
}
return irCode;
}

I posted an implementation which uses timer1 and and input capture at

http://www.phanderson.com/arduino/ir.html

I have not had the time to add a discussion.

Peter H Anderson

In your photo, it doesn’t look like all the pins of the IR receiver are connected to anything; two pins are connected to power/gnd and the signal comes out the third pin; it’s not like a photodiode where there’s a raw signal just from impinging light, the ir receiver is a whole integrated circuit and needs power.

JonnyMac’s photo looks much better!

Thank you all for you help. Being new at this everything is a bit confusing. I didn’t get the remote working for my final project today, ran out of time. However I am not quiting on this ir remote and will post my results when I finish it for those who are trying to do similar things.

I am going for hip surgery tomorrow following 2 weeks later with eye surgery so it may be a couple of months before I get around to finishing the project. Any other advice is always appreciated as I will be researching and working on this from time to time.

Will keep you all posted and thanks!
Janet