IAN LANG ELECTRONICS

During the course of an afternoon of sorting out the junk in the office I came across something I didn't know I had- a Battling Grannies game.  It appears that one granny has a frying pan and the other a rolling-pin and you control them by infra-red and make them bash each other.

Hmmm. It's an infrared is it? So I dissected one of the grannies to find out what she was made of (what??!! would you rather I let her get bashed?) and found on IR board with an embedded controller, and a rather nice motor/wheel unit. Sorry Granny, you're losing those because I want to experiment with the IR receiver board.

 

 

An Infra-Red Connection

Go Back

First impressions of the board was that the build quality was a bit, well poor, but subsequently it proved to be surprisingly robust and works very well indeed.

 

Attaching it to my UNO experimenting board I used the following code to find out what happened at the outputs when each button was pressed:

 

//condition green a0 yellow a1 5v supply

void setup(){

  Serial.begin(300);}

 

  void loop (){

Serial.print(analogRead(A0));Serial.print("    ");Serial.print(analogRead(A1));

Serial.println();

  }

Here's a close up of the board, the thing sticking up on the three wires is the sensor. Now, for its size I'm quite impressed with this board as it picks up the IR signal at a fair distance and doesnt need the transmitter pointing directly at it. Plus it cost me nothing whatsoever. A win all round I'd say. Well, apart from the granny I took it out of.  But if she will go round bashing her neighbours with a frying pan, she deserves all she gets.

 

Now, in principle this works exactly the same way as the radio control we looked at earlier. The board gives us only two channels to work with, so what purpose can we put it to?

Well, I'm going to use it to switch on and off a number of superbright LEDs to get a small lamp lamp out of it.

The actual light I get out of this won't be up the standard of an incadescent bulb, but using just six superbrights you'd be surprised just how much you do get. I'm going to use yellow ones, they don't shine as brightly as the other colours but they don't hurt your eyes as much if you look into them by accident either.

So here's the wiring then:

It's a very simple construct with this board. After some head scratching, pencil-chewing and swearing I found that the best way to do it was to have the outputs from the IR board input to the Arduino at A0 and A5 and have those two pins pulled reliably low by the pull down resistors you can see there which are about 200 ohms or so. Testing as above, pressing one button kept A0 low and put A5 at a reading of 1022, and the other kept A5 low and put a reading of 750 at A0.

 

So, what this does when you've coded it up is the following:

 

Pressing one button on the transmitter (the leftmost one in my case) makes the LEDs light up one after another with a half-second interval inbetween. The LEDs light from pin 2 upwards, and once it gets to pin 7 any further input is ignored.

 

Pressing the other button extinguishes the LEDs from pin 7 downwards, one after the other and again with a half second interval inbetween.  Once it goes down to pin 2, any further input is once again ignored.

 

Now, you could use a relay, a 9V supply and a P9 bulb and holder to make this an incandescent bulb and torch. Incredibly, given all the bits of junk I've got around here, I don't have a P9 and I can't be bothered to go down the shop and pick one up, so LEDs it is. Just a thought if you feel like doing something like this for yourself.

 

On to the code that does it then:

int range=2;

 

void setup(){

  for (int t=2;t<8;t++){

    pinMode (t,OUTPUT);Serial.begin(300);

  }}

 

  void loop (){

        Serial.println();

    Serial.print(range);Serial.print("   ");Serial.print(analogRead(A0));Serial.print("   ");Serial.print(analogRead(A5));

    delay(500);

  if (analogRead (A5)>0){

    range=range+1;}

    if (analogRead(A0)>10){

    range=range-1;}

range=constrain (range,2,8);

 

     for( int t=2;t<8;t++){

      if (range>t){

        digitalWrite (t,1);}

        else{ digitalWrite (t,0);}}

       

     

   

  }

 

As you can see, there's hardly any of it. All the hard work is done on the embedded controller on the IR board leaving the Arduino free to do the switching unimpeded. Cantering through, the very first thing we do is declare a global variable of int type called range. It's going to keep track of which pin we're lighting or extinguishing. I've left the serial in there that I used to see what was happening, and set pins 2 to 7 as output modes by running a for/next loop.

In the loop, I make it wait for half a second before doing anything, and this is what causes the time delay between lighting/ extinguishing. Whether A5 or A0 is high depends on which button I'm pressing, and if I'm lighting LEDs I add 1 to the variable range and if I'm extinguishing them subtract 1. I then constrain the variable so that it can't be lower than 2 or larger than 8 and this is why any further inputs get ignored. Using that variable in a for/next loop I can now command the state of each pin and thus the LED attached to it. I simply say if the pin under consideration has a lesser numerical value than range, light it, otherwise extinguish it.

 

The advantage that an IR transmitter has over a radio is that it's not as prone to interference (man made or otherwise) and doesn't interfere with anything else. The disadvantage is that you can't get as good a range, and although this one was pretty omnidirectional if anything's in the way the signal will not reach the receiver. All in all, I prefer IR for shorter distances, and radio for longer or round corners.

 

A very practical piece of recycling that whiled away a Thursday afternoon most pleasantly was this project. Now, I've just got to find something to do with the plastic granny............

 

 

Ian Lang December 2011