You Are Here: Home » AVR ATmega Projects » Build your own (cheap!) multi-function wireless camera controller using Microcontroller AVR ATMega8

Build your own (cheap!) multi-function wireless camera controller using Microcontroller AVR ATMega8




Introduction

Ever fancied building your own camera controller?

IMPORTANT NOTE: Capacitors for the MAX619 are 470n or 0.47u.  The schematic is correct, but the component list was wrong – updated.

This is an entry into the Digital Days competition so if you find it useful, please rate/vote/comment favourably!  If you reallly like it and are a stumbler, hit “i like it!” 🙂

Update: featured on hackaday! hackaday.com/2009/10/13/a-different-breed-of-camera-controllers/
Update: new photos of the laser trigger in action!
Update: First Prize =D, thanks for voting and/or rating!

camera controller

This instructable is mainly for the benefit of SLR users looking to get a bit more mileage out of their cameras, however if there are any point and shoots with IR interfaces, you might find this interesting. Certainly this will also work (with a bit of modification) with camera hacks where you can wire up logical outputs to camera trigger terminals.

This started off as a full blown tutorial, but due to some unexpected constraints i encountered later on, it may be more of a guide as to how to accomplish various things – i’ll often leave you the choice on how you could do things which i think is a better way of doing things than just blindly saying “you must do this”.  Think of this as a lesson in camera controller design.

I’ve provided schematics and full code so you can always just copy it.  It will be a simple case of transferring the design to a stripboard and adding the LCD for most people.  I’ve gone through how to breadboard it since the process is very similar and allows for correcting mistakes before you make the design permanent!

Features:

Single shot mode
Interval (time lapse) mode
Triggered shot (trigger from external sensor) mode with variable conditions
Included sensor designs – light, sound (many more possible!)
Total cost – under £25 (excluding tools)
LCD Display for easy change of settings
Compatible with Nikon/Canon (coded), potential support (untested) for Olympus/Pentax
No firmware modification needed
Uses IR so is both wireless and doesn’t damage your camera

I had the idea for this after sitting outside in the cold clicking my remote control for hours. I was doing an 8 second interval for around 1000 shots. I thought, hey, it’s just an IR LED isn’t it? Why can’t i replicate it and make my own remote with a built in delay?

I then found out (somewhat embarrassedly, because i thought i’d had a massive brain wave) that this has been done and there are even a couple of instructables on the topic.

Where my implementation differs from most intervalometers and diy remotes is that it allows for a lot of customisation and modularity, is compatible with both Nikon/Canon (and likely others later) and combines the ability to take a picture on a particular trigger.

The idea is simple. You want to take a picture of something quite fast (limited currently by the lag on your shutter, for me 6ms). There are a variety of methods for doing this:

1. Trial and error  you try to take the picture at the right moment
2. Improved trial and error  you black out the room, put your camera on bulb (open shutter) and fire a flash at the right time
3. Buy a dedicated trigger controller that has some kind of audio/light sensor to take the picture at your command
4. Build one yourself!

Ok, 1 and 2 are fine for messing around and can yield some very good pictures. But what im going to show you is that its possible to construct a circuit that will give you consistent results time and time again. Most importantly, in these tight times, the cost is lower than alternative models (some people have produced kits doing this kind of thing, but they cost a fortune  see links).

The versatility of the design is this:
If your sensor generates an output voltage between 0 and 5V, you can use it to trigger your camera!
On the face of it this is a boring statement, but once you begin to understand the implications it becomes very powerful. By simply monitoring a voltage level, your trigger could be light based (LDR), sound based (microphone or ultrasound), temperature based (thermistor) or even a simple potentiometer. In fact, just about anything. You could even link the circuit up to another controller and provided it can give you a logical output, thus you can trigger from it.

The only major limitation of the design currently is that it works only with IR interfaces, it would be fairly simple to modify the software and hardware to output via mini-USB or whatever sort of interface is required.

Note: Source Code:

I have provided some applications in step 13.  The code i run on my controller as of now is up there in a hex file along with the main c file and its dependencies.  You can simply run my code if you are unsure about compiling.  I’ve also included some sample code that you can use in various steps (they’re named obviously like remote_test, intervalometer test and adc test.  If i refer to code in a step, odds are it’s in there.

EDIT: An update about balloons popping – it seems i was a bit short sighted when i said you could easily shoot photos of popping balloons.  Turns out that the skin on the average balloon travels so fast that it’ll have popped completely by the time your camera fires.  This is an issue with most cameras, NOT the controller (which senses the ADC at a rate of around 120kHz).  The way round this is to use a triggered flash, which is doable if you add an extra wire out and another small circuit.  That said, you could in theory use something else to pop it and play with the delay (or even change the delay code to include microseconds).  A air pellet travelling 1m at 150ms-1 takes about 6-7ms, enough time to trigger and shoot.  Just moving the gun would provide a rudimentary delay of a few microseconds.  Again, apologies about this, i’m going to play about tonight if i can get hold of some balloons, but there are still many uses for an audio trigger, like fireworks!

I’ve put a quick and dirty time lapse below to show that it works however 🙂

Don’t forget to read, rate and/or vote!

Cheers, Josh
Disclaimer

In the unlikely event that something goes horrifically wrong or you somehow brick your camera/dremel your cat, i am not liable for anything.  By starting a project based on this instructable, you accept that and continue at your own risk.

If you make one of these, or use my instructable to help you – please send me a link/photo so i can include it here!  The response has been overwhelming so far (at least by my standards) so it’d be awesome to see how people are interpreting it.  I’m working on revision 2 as i type 😉

Some initial thoughts…

So, how are we going to build this thing?

Microcontroller

The heart and soul of this project is an AVR ATMega8. It is essentially a slightly trimmed version of the ATMega168 chip that Arduino use. It is programmable in C or Assembly and has a variety of really useful features that we can use to our advantage.

” 28 pins, the majority of which are input/output (i/o)
” Onboard analog to digital converter
” Low power consumption
” 3 onboard timers
” Internal or external clock source
” Lots of code libraries and samples online

Having lots of pins is good. We can interface with an LCD screen, have 6 button inputs and still have enough left over for an IR LED to shoot with and some status LEDs.

The Atmel AVR series of processors has a lot of support online and there are plenty of tutorials in getting started (i will go over this briefly, but there are better dedicated tutorials) and heaps and heaps of code to mull over. For reference ill be coding this project in C using the AVR-LibC library.

I could have easily gone with PIC to do this, but AVR is well supported and all the examples i’ve found for remotes have been AVR based!

LCD Display

There are two main types of display, graphical and alphanumeric. Graphical displays have a resolution and you can put pixels wherever you like. The downside is that theyre harder to code for (although libraries exist). Alphanumeric displays are simply one or more rows of characters, the LCD has an onboard store of basic characters (i.e. the alphabet, some numbers and symbols) and its relatively easy to output strings and so on. The downside is theyre not as flexible and displaying graphics is virtually impossible, but it suits our purpose. Theyre also cheaper!

Alphanumerics are categorised by their row and column count. The 2×16 is pretty common, with two rows of 16 characters, each character being a 5×8 matrix. You can get 2×20s too, but i dont see the need. Buy whatever you feel comfortable with.

I chose to use a red backlit LCD (i want to use this for astrophotography and red light is better for night vision). You can go without a backlight – its entirely your choice. If you choose a non backlit route you will save power and money, but you might need a torch in the dark.

When looking for an LCD, you should ensure that it is controlled by the HD44780. It is an industry standard protocol developed by Hitachi and there are a lot of good libraries that we can use to output data. The model i bought was a JHD162A from eBay.

Input

Input will be done by buttons (simple!). I chose 6 – mode select, ok/shoot and 4 directions. Its also worth getting another small button for resetting the micro in case of a crash.
As for the trigger input, some basic ideas are a light dependent resistor or an electret microphone. This is where you can get creative or stingy depending on your budget. Ultrasound sensors will cost a bit more and require some extra programming but you can do some really neat stuff with them.

Most people will be happy with a microphone (probably the most useful general sensor) and electrets are very cheap. Be aware that itll need to be amplified too (but ill go over this later).

Output – Status

The only real output we need is status (besides the display), so a couple of LEDs will work fine here.

Output – Shooting

For taking pictures, we need to interface with the camera and for that we need a light source that can produce infra-red radiation. Thankfully there are a multitude of LEDs that do this and you should try to pick up a reasonably high power one. The unit i chose has a current rating of 100mA max (most LEDs are around 30mA).

You should also take care to note the wavelength output. Infrared light is in the longer wavelength part of the EM spectrum and you should be looking for a value of around 850-950nm. Most IR LEDs tend towards the 950 end and you may see a bit of red light when it’s turned on, this isn’t a problem, but it’s wasted spectrum so try to go closer to 850 if possible.

Power

How are we going to power all this? Well, it’s going to be portable so batteries! I chose to use 2 AA batteries which are then stepped up to 5V. I’ll go over the reasoning behind this in the next few sections.

Casing and Construction’

How you do this bit is entirely up to you. I decided to use stripboard for the circuit after prototyping because it’s cheap and flexible and saves designing a custom PCB. I have provided the schematics so you are free to make your own PCB layout – although if you do, i would be grateful to have a copy!

Again the case is entirely your choice, it needs to be able to fit the screen, buttons (in a fairly intuitive layout if possible) and the batteries. As circuit boards go, this one isn’t that complicated, a lot of the connections are simply to things like the buttons/LCD.

Power Management

Power Management

Power Management
For a project like this it’s obvious that portability should be a key aspect. Batteries are thus the logical choice!

Now, for portable devices it is fairly key that you pick a battery source that is either rechargeable or easily available. The two main options are the 9V PP3 battery or AA batteries. I’m sure some people will assume that a 9V battery is the best option because hey, 9V is better than 3 right?
Well, not in this case. 9V batteries whilst very useful, produce their voltage at the expense of battery life. Measured in mAh (milliamp hours), this rating tells you in theory how long a battery will last operating at 1mA in hours (though take it with a pinch of salt, these are often under ideal, low load conditions). The higher the rating, the longer the battery will last. 9V batteries are rated at up to and around 1000mAh. Alkaline AA’s on the other hand have almost three times as much at 2900mAh. NiMH rechargables can reach this, though 2500mAh is a reasonable amount (note that rechargeable batteries operate at 1.2V not 1.5!).

The LCD screen needs a 5V input (�10%) and the AVR (the microcontroller) needs roughly the same (though it can go as low as 2.7 for low frequency clock speeds). We also need a fairly stable voltage, if it fluctuates about it could cause problems with the microcontroller.

To do this we’ll use a voltage regulator, you need to make a choice over price vs efficiency now. You’ve got the option of using a simple 3-pin voltage regulator like the LM7805 (78 series, +5 volts output) or a small integrated circuit.

Using a simple regulator

If you choose to go with this option, you need to bear a few points in mind. Firstly, three pin regulators almost always need an input that is higher than their output. They then step the voltage down to the desired value. The downside is that they have awful efficiency (50-60% is good going). The upside is that they’re cheap and will run with a 9V battery, you can pick up a basic model for 20 pence in the UK. You should also bear in mind that regulators have a dropout voltage – the minimum gap between input and output. You can buy special LDO (Low DropOut) regulators that have dropouts at around 50mV (compared to 1-2V with other designs). In other words, look out for LDOs with a +5V output.

Using an integrated circuit

The ideal way to go is a switching regulator. These will be, for our purpose, normally 8-pin packages that take in a voltage and give us a regulated output at a high efficiency – almost 90% in some cases. You can get step up or step down converters (boost/buck respectively) depending on what you want to put in, alternatively you can buy regulators that will take either above or below the desired output.

The chip i’m using for this project is a MAX619+. It is a 5V step up regulator that takes 2 AA’s (the input range is 2V-3.3V) and gives a steady 5V out. It only needs four capacitors to operate and is very space efficient. Cost – �3.00 including the caps. Arguably it’s worth the splurge just to get a bit more use out of your batteries. The only major downside is that it’s not short circuit protected, so if there is a current surge, be warned! This is reasonably trivial to fix with an add on circuit however:

Another useful chip design – although not nearly as neat a solution is the LT1307. Again, a 5V regulator, but it can take a variety of inputs and has useful things like low battery detection. It costs quite a bit more at nearly �5 with inductors, large capacitors and resistors.

Voltage Rails

We are going to be using two main voltage rails (plus a common ground). The first will be the 3V from the battery, this will be used to power the LEDs and other relatively high power components. My MAX619 is only rated up to 60mA (though absolute maximum is 120mA) so it is easier to connect the microcontroller to a MOSFET to control any LEDs. The MOSFET draws almost no current and acts as a break in the circuit when the gate input is under around 3V. When the microcontroller sends out logical 1 on the pin, the voltage is 5V and the FET turns on, then just acting as a short circuit (i.e. a piece of wire).

The 5V rail will power the LCD, Microcontroller and any amplification circuits for input sensors.

Power Consumption

If we look at various datasheets, we note that the AVR takes no more than 15-20mA at maximum load.

The LCD takes only 1mA to operate (at least when i tested, budget for 2). With the backlight on, it’s really up to you to decide. Connecting it straight up to the 5V rail (i tried) is fine, but make sure it has an onboard resistor (follow the traces on the PCB) before you do. It drew 30mA that way – terrible! With a 3.3k resistor it’s still viewable (perfect for astro photography) and only draws 1mA. You can still get decent brightness using a 1k or otherwise. I’m fine with mine drawing just under 2mA with the backlight on! If you want, it’s trivial to add a brightness knob using a 10k potentiometer.

The IR LED might take 100mA maximum, but i have had good results with 60mA across mine (experiment!). You can then halve that current because you’re effectively running at a 50% duty cycle (when the LED is modulated). Anyway, it’s only on for a fraction of a second so we don’t need to worry about this.

The other LEDs you should play about with, you may find that only a 10mA current is enough to give you a good brightness – certainly look for low power LEDs (excluding the IR one), youre not designing a torch! I chose not to add a power indicator in my circuit, simply because it’s a lot of current draw for not much use. Use the on/off switch to check if it’s on!

In total, you shouldn’t be running more than 30mA at any one time and with a theoretical supply of around 2500 (allowing for variation) mAh that should give you well over 80 hours straight with everything on. With the processor idled for most of the time this will at least double/triple, so you shouldn’t have to change your batteries very often.

Conclusion

There we go, that was easy wasn’t it! You can either go cheap and cheery with a 9V battery and a LDO regulator at the expense of efficiency or pay a bit more and use a dedicated IC to do it. My budget was still under �20 even WITH the IC, so you can drop it even further if you need to.

A Closer Look at the ATmega8

A Closer Look at the ATmega8Pins

Image 1 is the pinout diagram for the ATMega8 (exactly the same as the 168/48/88, the only difference is the amount of onboard memory and interrupt options).
Pin 1 – Reset, should be held at VCC voltage (or at least logical 1). If grounded, the device will soft-reset
Pin 2-6 – Port D, general input/output
Pin 7 – VCC, supply voltage (+5V for us)
Pin 8 – Ground
Pin 9,10 – XTAL, external clock inputs (part of Port B)
Pin 11 – 13 Port D, general input/output
Pin 14 – 19 Port B, general input/output
Pin 20 – AVCC, analogue supply voltage (same as VCC)
Pin 21 – AREF, analogue voltage reference
Pin 22 – Ground
Pin 23-28 Port C, general input/output

Usable i/o ports: D = 8, C = 6, B = 6
A total of 20 usable ports is great, for simplicity you should group your outputs either into ports (say, D as the output port) or into groups on the board – you might want the LCD to run from Port C just to keep the wires tidy in that corner.
There are three extra pins that are required for programming. Those are MISO (18), MOSI (17) and SCK(19). These will happily act as i/o pins if needed though.

Clocking

The signal that we send to the camera needs to be precisely timed (accurate to around a microsecond) so it’s important we choose a good clock source. All AVRs have an internal oscillator that the chip can get its clock from. The downside of this is that they can fluctuate around 10% with temperature/pressure/humidity. What we can do to combat this is use an external quartz crystal. These are available in anything from 32768kHz (watch) to 20MHz. I’ve chosen to use a 4Mhz crystal as it provides a decent amount of speed yet is fairly power conservative compared to perhaps 8Mhz+.

Onboard Power Management

I really wanted to use sleep routines in my code.  In fact i wrote the first version to rely heavily on idling the processor while time lapsing.  Unfortnuately, due to time constraints, i ran into some issues with running the clock externally and interrupting using the timers.  In essence i’d have to rewrite the code to deal with the controller simply not waking up – which i could do, but time is against me.  As such, the device only draws 20mA ish so you can get away with it.  If you’re really up for it, then by all means fiddle with the code, all you need to do is to clock internally and then run Timer 2 in asynchronous mode using the 4MHz crystal for the more accurate delays.  It’s simple to do, but time consuming.

ADC

The swiss army knife in the AVR toolset, the ADC stands for Analogue to Digital Converter. How it works is relatively simple from the outside. A voltage is sampled on a pin (from some sensor or other input), the voltage gets converted into a digital value between 0 and 1024. A value of 1024 will be observed when the input voltage is equal to the ADC reference voltage. If we set our reference to be VCC (+5V) then each division is 5/1024 V or around 5mV. Thus an increase of 5mV on the pin will increase the ADC value by 1. We can take the ADC output value as a variable and then fiddle with it, compare it with things, etc in the code. The ADC is an incredibly useful function and allows you do lots of cool things like turn your AVR into an oscilloscope. The sampling frequency is around 125kHz and must be set in proportion to the main clock frequency.

Registers

You may have heard of registers before, but fear not! A register is simply a collection of addresses (locations) in the AVR memory. Registers are classed by their bit size. A 7 bit register has 8 locations, as we start from 0. There are registers for just about everything and well take a look at them in much more detail later. Some examples include the PORTx registers (where x is B, C or D) that control whether a pin is set high or low and sets pull up resistors for inputs, the DDRx registers which set whether a pin is output or input and so on.

The Datasheet

A behemoth of literature, weighing in at around 400 pages; the AVR datasheets are an invaluable reference to your processor. They contain details of every register, every pin, how timers work, what fuses should be set to what and much more. They are free of charge and you will need it sooner or later, so download a copy!

www.atmel.com/dyn/resources/prod_documents/doc2486.pdf

Leave a Comment

You must be logged in to post a comment.

Read previous post:
A sunrise and sunset lamp with LEDs

You know it, in the winter time it is hard to get up, because it is dark outside and your...

Close
Scroll to top