IR remote control of servo using Arduino

Got a little bit done of the control for the sound system… I wasn’t getting good results from the Sharp GP1U5 module I was using until I stumbled upon some work by Ken Shirriff. He has written an IRremote library that supports both sending and receiving and includes support for a few different protocols.

The supported protocols don’t seem to cover the remotes I’m playing with, but luckily, he also did a post on handling arbitrary remotes by generating a hash value. Using that as a starting point, I cobbled together a fairly simple proof of concept sketch.

/*
* IR Remote controlled servo
*
*
*
* IR Remote code from Ken Shirriff (www.arcfn.com), specifically this post:
* http://www.arcfn.com/2010/01/using-arbitrary-remotes-with-arduino.html
*/

#include
#include

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

#define LEDPIN 13

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

int volume = 0;
int max_volume = 180; // determined by max position of the servo
int mute = 0;

void setup()
{
irrecv.enableIRIn(); // Start the receiver

myservo.attach(9,600,2400); // attaches the servo on pin 9 to the servo object with pulse widths for Hitec
// servo

myservo.write(0); // tell servo to go to base position
delay(1000);

Serial.begin(9600);
}

// Compare two tick values, returning 0 if newval is shorter,
// 1 if newval is equal, and 2 if newval is longer
// Use a tolerance of 20%
int compare(unsigned int oldval, unsigned int newval) {
if (newval < oldval * .8) {
return 0;
}
else if (oldval < newval * .8) {
return 2;
}
else {
return 1;
}
}

// Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param
#define FNV_PRIME_32 16777619
#define FNV_BASIS_32 2166136261

/* Converts the raw code values into a 32-bit hash code.
* Hopefully this code is unique for each button.
*/
unsigned long decodeHash(decode_results *results) {
unsigned long hash = FNV_BASIS_32;
for (int i = 1; i+2 rawlen; i++) {
int value = compare(results->rawbuf[i], results->rawbuf[i+2]);
// Add value into the hash
hash = (hash * FNV_PRIME_32) ^ value;
}
return hash;
}

void loop() {
if (irrecv.decode(&results)) {
unsigned long hash = decodeHash(&results);
switch (hash) {
case 0x4B12992B: // Vol Up
case 0x22D912B8:
Serial.println("Volume Up");
volume += 1;
if ( mute == 1 ) {
volume -= 1;
mute = 0;
}
break;
case 0x1BE8C80D: // Vol Down
case 0x776C6E79:
Serial.println("Volume Down");
volume -= 1;
if ( mute == 1 ) {
volume += 1;
mute = 0;
}
break;
case 0x92DFD41C:
Serial.println("Mute");
mute = 1;
break;
default:
Serial.print("'real' decode: ");
Serial.print(results.value, HEX);
Serial.print(", hash decode: ");
Serial.println(hash, HEX);
}
irrecv.resume(); // Resume decoding (necessary!)
if ( volume max_volume ) { volume = max_volume; }
if ( mute == 1 ) {
myservo.write(0);
}
else {
myservo.write(volume);
}
}
}

I’m using a Hitec HS-325HB servo with this code, and I implemented volume controlling from two different remotes I had kicking around – only one had a mute button.

Mute is handled by moving the servo to the zero position, and the next volume up/down will unmute by returning the servo to the correct position.

With the Arduino side basically figured out, the next step is to figure out the best way to tie the volume control and Arduino together. One potential problem is that with the servo hooked up, turning the volume control manually will probably not be possible. I’ll probably add a mute button and up/down buttons to allow control without needing to find the remote control. Doing that should be simple enough, and make it a lot more user friendly.

LightZone

I just started using a new program the other day. It’s called LightZone, and I have a feeling I’m going to be using it a lot. It is an interesting photo editor that is geared towards taking digital photos and prepping them for output. It is definitely geared towards photographers including the Ansel Adams zone system.

It allows you to retouch photos in an intuitive way without worrying about numbers. The reason I started playing with it was that I wanted to find a good way to process my raw (.crw) files in Linux, but I’ll be using it for much more than that. It’s also getting good responses elsewhere.

As an added bonus, for those of us using Linux, we can get a free copy. Definitely check it out!

New (to me) Camera

I’ve been bad… no updates to the site in months. What is especially bad about that is that I have a new camera, which should mean that I’ve got lots of new stuff to post. I picked up a used Canon 10D camera, and am having a blast with it. I spent a lot of time turning an expensive camera into one that uses a pinhole lens… I’ll post details of that in a different post.

I’m still trying to be successful at the ‘one picture a day’ thing, I’ll see how I manage from here but don’t count on exactly one a day. I’m thinking of making it a New Year’s resolution :-)

If you want to watch for pictures, this isn’t going to be the right spot anymore. Instead, you’ll want to go to photos.dragonsbyte.ca. I’ve installed PixelPost there, which is geared for photobloging, and nothing else. I did that because one of the things I was always fighting with was WordPress, and how to get it to show pictures in a simple, clean format. Separating words, and pictures might get me what I am after.

I’ll still be posting here, but it won’t be photos per se. There may be some as part of the posts, but the ‘this is a picture for it’s own sake’ stuff will be handled on the photoblog.

I’ve also finally gotten rid of the re-direct on the www.dragonsbyte.ca page, and replaced it with a very simple page that lets you choose the photoblog, or written one. I’m toying with the idea of setting up an RSS feed on that page that combines the data from the written and photo site. Not sure if it’s worthwhile though, since I have no idea if anyone reading the blog actually uses RSS.

I Am Canada

I Am Canada
So, here’s reason #2… it’s my first published picture. It appears in ‘I Am Canada’ on page 8. I’ve known about it for quite a while, but waited until I actually had a copy of the book in my hands before mentioning anything.

Since I’m a published photographer, obviously my photos are worth more money – I’m immediately doubling the prices of everything :-)

Northern Lights, but why the dupe?

Northern Lights
Yes, I posted this a while ago… why did I post it again? Reason #1: the current blog doesn’t contain entries from last year or earlier.
Does that mean that I’ll be reposting all the earlier photos? Answer: No.
What makes this one special? Answer: ahhh… that’s Reason #2 – tune in tomorrow to find out what it is :-)

Trolleys

Type 1Type 2Type 3Type 4Type 5

Some of the different types of trolleys running in San Francisco. All of these run on the F line which runs from Castro to Fisherman’s Wharf. The rest of the city uses more modern trolley cars, with the obvious exception of the cable cars. I’m not sure that I managed a shot of every single type, but this is the selection I saw.