The Electronics
I made a few objectives for myself when designing the hardware, and I think I met them all reasonably well. They were to:
- Use the absolute minimum amount of power possible in standby mode. I wanted this remote to be able to sit on the shelf for at least 2 years, and still be ready to go;
- Be as small as possible, while still using a standard battery size and just protoboard;
- Be relatively cheap - at least a good margin cheaper than the $50 off-the-shelf remotes sold by the big brands; and
- Have an interface for an external footswitch and an external device using 5V logic. The external device could then control this module and use it for timelapses, etc.
Here is the schematic I developed for the project (click the image for a larger version):
Looking at that schematic in more detail, there's a few important notes to be made about some of the component selections:
- The voltage regulator I used was this Pololu regulator. It was probably the most expensive component on the board, at around $5. It can step up/down anywhere between 0.5-5.5V to 5V. Given the AAA battery would be 1.5V (or 1.2V for rechargeable), this regulator would do a swell job of keeping the voltage high for the rest of the electronics.
- The two BS170 MOSFETs are being used as switches. Q3 is in line with the normal switch, such that when pulsed with a 5V input, the remote will fire, just as if the button was pushed. Q1 is being used in a slightly different way though. Given I wanted this remote to have the lowest possible power consumption, that meant I would have to disconnect all of the electronics from the battery and only apply power when the button is pushed (or Q3 is 'opened'). To do this then means that when the button goes up, power will stop being applied again, even if the AVR still has some computing to do. So, Q1 is controllable by the AVR such that once power is applied to the AVR, the first thing the AVR does is pull pin 6 high so that it can then control when it wants to disconnect the battery. This also proves to effectively debounce the push button as well.
- The 2N3904 BJT is just being used to amplify the signal over the IR LED. The IR LED I used was capable of withstanding spikes of about 1W, so adding in the BJT allowed me to increase the range of the remote a bit. I've only tested it to about 6m, but I think it could go further. Tuning that base resistor would allow for more current to flow through the LED, if you feel the need for even more power. It's necessary to use this boosting BJT because the pins of the AVR can only supply up to 25mA before being at risk of damage.
- The 8MHz oscillator is not really necessary for this application. I started off using it, thinking that the more precise PWM signal would be better, but really, it's overkill. I've now reverted back to the internal 1MHz oscillator, and it works just fine. Given this is such a short pulse and IR communication in most consumer products tends not to be super precise, using the internal oscillator will save you 50 cents and will lower the probability of something going wrong with that extra component.
To actually put together the board there was quite a bit of tricky protoboard soldering and precise component leg bending involved. I would have liked to have just gone surface mount everything and set up a PCB for the project, but due to time constraints, that didn't happen. If you would be interested in a full tutorial and some documentation on how I set up and soldered the protoboard, let me know in the comments. If there's enough interest, I'll make another post detailing the build process. For now, here's a pretty timelapse of me soldering one up:
The Code
Developing the code for the project was pretty simple, once the IR shutter code for the Pentax DSLRs was found. I found the below shutter code on this forum:
From there, coding it up on the AVR was pretty straight forward. I used Atmel Studio for generating the hex file and a $10 avr-isp off eBay to program the AVR. You can find my code, the hex file, and a bunch of other useful resources in my Google Drive folder for the project. Here's the code:
I found Adafruit's TV-B-Gone remote kit code to be a helpful resource for me when I was putting together my code.
From there, coding it up on the AVR was pretty straight forward. I used Atmel Studio for generating the hex file and a $10 avr-isp off eBay to program the AVR. You can find my code, the hex file, and a bunch of other useful resources in my Google Drive folder for the project. Here's the code:
/*
* PentaxRemote.c
*
* A very basic program that simply fires the 'take photo' IR command for
* Pentax cameras, then switches itself back off again. Use case in mind is
* that the power source will be directly connected to a button and a FET
* switch. When the button is pressed, all the AVR does is turn on the FET
* switch (to keep power until it's ready to switch off), send the IR code
* and then turn itself off again when it's finished sending the code.
*
* Created: 10/08/2014 10:16:17 AM
* Author: Anthony Stancombe
*/
#define F_CPU 1000000UL // 1 MHz
#define PWM_FREQ 38000 // 38kHz
#define INFO_LED PB2 // An LED for letting the user know the avr is running
#define PWR_SWITCH PB2 // FET switch, directly controlling the power source
#define IR_LED PB0 // The IR LED for outputting the remote signal
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/delay.h>
int main(void)
{
// Set up the two LEDs and FET switch as outputs.
DDRB = _BV(INFO_LED) | _BV(IR_LED) | _BV(PWR_SWITCH);
// Switch the info LED and FET switch on
PORTB |= _BV(INFO_LED) | _BV(PWR_SWITCH);
// Switch the IR LED off
PORTB &= ~_BV(IR_LED);
// Set up the PWM freq
OCR0A = ((F_CPU / PWM_FREQ - 1)/ 2);
// Start transmitting the code. The code is 50% duty cycle PWM at 38kHz,
// following the pattern -
// 1) 13ms on, 3ms off,
// 2) 1ms on, 1ms off,
// 3) 1ms on, 1ms off,
// 4) 1ms on, 1ms off,
// 5) 1ms on, 1ms off,
// 6) 1ms on, 1ms off,
// 7) 1ms on, 1ms off,
// 8) 1ms on, 1ms off
transmit_IR_segment(13, 3);
for (int i = 0; i < 7; i++) {
transmit_IR_segment(1, 1);
}
PORTB &= ~_BV(PWR_SWITCH); // Cut the power off by turning off FET switch
}
// transmit_IR_segment: Transmits a segment of an IR code, by turning on 50%,
// 38kHz PWM for a specified on time, then turning it off
// again for a specified off time. Uses pin 5 (PB0).
// params: OnTime [int] => How long to pluse 50%, 38kHz PWM, in
// milliseconds.
// OffTime [int] => How long to wait before returning,
// with the PWM off, in milliseconds.
void transmit_IR_segment(int OnTime, int OffTime) {
// Reset the timer and flags
TCNT0 = 0;
TIFR = 0;
// Set up timer 0 to generate a 38kHz carrier
TCCR0A =_BV(COM0A0) | _BV(WGM01);
TCCR0B = _BV(CS00);
// Leave the PWM on for the on time
delay_ms(OnTime);
// Now, switch off the PWM and the IR LED
TCCR0A = 0;
TCCR0B = 0;
PORTB &= ~_BV(IR_LED);
// Wait for off time
delay_ms(OffTime);
}
// delay_ms: Implementation of delay function that gives _delay_ms from
// delay.h a value at compile time to make it happy. The timing
// does get slightly off by doing this, but only by some
// minuscule amount that doesn't cause problems for this code.
// params: Time [int] => How long to delay. (milliseconds)
void delay_ms(int Time) {
while (Time--) {
_delay_ms(1);
}
}
I found Adafruit's TV-B-Gone remote kit code to be a helpful resource for me when I was putting together my code.
The Case
Making the case was a lot of fun, given I have a friend with a 3D printer. To develop the case, I used OpenSCAD. I find OpenSCAD to be incredibly awesome for creating 3D models, because I'm more comfortable with the programmatic approach. I can never seem to get the fancy double-click, mouse-swipe-left, press-A-three-times tricks that all of the graphical CAD programs require.
All of the SCAD files and STLs can be downloaded from my Google Drive folder for the project. Here are a few pictures of the case and the external footswitch I made:
A few things to note about the box:
All of the SCAD files and STLs can be downloaded from my Google Drive folder for the project. Here are a few pictures of the case and the external footswitch I made:
A few things to note about the box:
- There is an insert inside the box that isn't in the STL. That insert is some soft cushioning foam I put in there to make the electronics fit in nice and cozy.
- The pictured button is a clearish-white button that I bought and glued to some clear, stiff plastic, so that I could achieve a nice, tactile feel from the push button switch on the board, even if it was slightly misaligned.
- The lid is snap fitting, and works really well. It will easily hold shut when dropped, but is not too difficult to get off with your fingernails as well. I did have to whittle it a bit with a utility knife though, just to get the fit exactly right.
Final thoughts...
If I were to do this project again, I would probably aim to make the whole remote smaller. It feels a tad bit clunky, having it be so big. This could be achieved by changing the power supply to something a bit more expensive and small, like a LiPo battery, and PCBifying the electronics.And that's really all there was to it! If you have any suggestions or questions, feel free to comment below and I'll respond as soon as possible. Thanks for taking the time to read this, and I hope it helps you out if you're thinking about making your own IR remote.

















