Archive for the ‘Electronic Projects’ Category

Creating a simple Flash app with Kinect

lucky larry flash kinect

First of all read up on how to set the Kinect up on your computer, I’m using Windows XP here.

Getting the Kinect setup on your PC: OpenNI / Primesense

Interfacing Kinect with Flash & AS3

Now you’ve read those (If you needed to), for this tutorial you’ll also need Flash CS4 or later, which you can download a demo from Adobe for free. Alternatively you can use the opensource actionscript compilers – I’m only using Flash to quickly draw some objects because I can’t be bothered to code them, so you can take my actionscript file and add to it if you don’t want to use the Flash IDE. One note though, you’ll need to compile and run this as an executable (.exe).

You can download ALL my files here

I say *ALL* because it seems that everyone’s more than happy to show their video of this working but no one shares their code, at the very least they share the .exe files. So here it all is and it’s very simple to follow, making use of the excellent AS3 server and libraries from

lucky larry flash kinect files

To quickly test this out, plug in the Kinect, download and unzip my folder, start as3-server.exe and then start LuckyLarryFlashKinect.exe. Perform the Cornholio pose and it should start tracking your right hand. Push your hand out to press a button.

Hopefully that worked albeit a bit glitchy. So how was it done? I’ll walk through this assuming you have some Flash knowledge but essentially it’s just a rehash of the demo on

First get that demo of Flash, I tried CS3 but the AS3 kinect libraries are a bit buggy, so I’d recommend grabbing the latest demo from Adobe’s site, I’m using CS5.5 which works fine for this, but CS4 works just as well.

The LuckyLarryFlashKinect.fla file literally just has the buttons, hand icon and a link to an external actionscript file, if you really wanted to you could just draw that with actionscript code and compile the file using an open source alternative – I’m just being lazy.

If you open that up, you’ll see I have a movieclip called all with an instance name of all

actionscript instance name

That contains the movie clip buttons and 6 instances of the button movieclip

flash kinect buttons

The button movieclip has 2 frames in there, one for on and another for the off state, you could easily change the colour etc… in actionscript but I wanted to specfically show the nextFrame function in my code.

flash kinect hand

The hand movieclip is called Right, this is the hand icon which has another movieclip called handhit. I have this so that I can have a much smaller, more precise hit test bounding area. Under the properties for each movieclip on the stage you’ll see that they have instance names to link them to actionscript. Other than that, the files publishing settings are set to Actionscript 3.0, and to create a SWF and EXE file.

That’s it. Everything else happens in the actionscript file which I’ll walk through in more detail.

Looking at actionscript file now…

First we create our package and import the necessary libaries

	// load relevant libraries
	import flash.display.MovieClip;
	// AS3 kinect 
	import org.as3kinect.*;
	import org.as3kinect.as3kinectWrapper;
	// Greensock for programmatic tweening for rollovers etc...
	import com.greensock.*;
	import com.greensock.easing.*;

Now we create our package class extending the movieclip object and declare our private variables

	public class LuckyLarryFlashKinect extends MovieClip
		// declare new instance of the AS3 wrapper
		private var as3w:as3kinectWrapper;
		// configure a 'depthLimit' limit in millimetres, you need to stand further back than this
		private var depthLimit:Number = 800; 
		// store the depthLimit of the right hand
		private var right_z:Number;
		// store if something has been pushed
		private var isPush:Boolean;

The next function creates the link to the skeleton data via the libary files and then registers 3 event listeners, 1 for the skeletal data and the others for Enter Frame

		// declare the event listeners for skeleton tracking and enter frame
		public function LuckyLarryFlashKinect()
			as3w = new as3kinectWrapper();
			as3w.addEventListener(as3kinectWrapperEvent.ON_SKEL, on_skeleton);

On the EnterFrame function we get the skeletal data and check for the depth of your hand, adding or removing the interaction event listener depending upon the distance. In this function, I also handle the rollover, since it’s present every time irrelevant of depth, I’ll explain that for loop a bit later on.

		private function EnterFrame(event:Event)
			// get skeleton information to retrieve right hand info
			//Depth detection event listener - set it to work at a minimal depthLimit
			if ((right_z < depthLimit)){
				removeEventListener(Event.ENTER_FRAME, interaction);
			}else if ((right_z > depthLimit)){
				addEventListener(Event.ENTER_FRAME, interaction);

			/* Rollover
			 * Because we're not detecthing depthLimit and just x and y, this function lives
			 * outside of the interaction function it loops through all the items within 
			 * the buttons movie clip and do hit detection on each one, instead of declaring 
			 * each individual possible hit test we handle it in a much smaller for loop
			var i:int = 0;
       		for(i; i < all.buttons.numChildren; ++i){
				if (right.handhit.hitTestObject(all.buttons.getChildAt(i))){
					// use greensock to make the buttons bigger/smaller, 0.1, {scaleX:1.10, scaleY:1.10, ease:Cubic.easeIn});
				} else {, 0.1, {scaleX:1, scaleY:1, ease:Cubic.easeIn});


After this we declare the skeleton function to get the data for the right hand and map it to our movieclip named right. For the x and y data I alter this to translate the tracked data to the screen, without this you can only control a very small space inside the movieclip. Unlike the demo files, here we're also looking at z index/ distance from the sensor, this is the real difference between the demos.

		private function on_skeleton(event:as3kinectWrapperEvent):void
		// gets hand tracking and data to build into gestures
			var skel:Object =;
			// right hand position, fetched from the AS3kinect wrapper/ skeleton data
			// I add a multipler (*4) and an offset (-400) to compensate for using right hand only, saving me stretching!
			right.x = (skel.r_hand.x*4)-400;
			right.y = (skel.r_hand.y*3)-400;
			right_z = skel.r_hand.z;

In the final function, interaction, I just observe the right hand depth (z) and if that's less than my depth variable I then execute the hit tests dynamically to figure out which button to click/ animate. So I'm assuming that you stand further back than my depth limit, when the hand is less than this, you're pushing a button. I guess instead of calculating the distance of your hand from the sensor, we could calculate the distance of your hand from your shoulder, head or neck allowing you stand as close or far away from the sensor as you want as your hand depth then becomes relative to your body and not the sensor.

		private function interaction(e:Event)
		/* function that does all the button clicking /gestures
		 * in this case we're concerned on the detected depthLimit to figure out if
		 * a button has been 'pushed'
			// if right hand is at required depthLimit for 'pushing'
			if (right_z < depthLimit){
				removeEventListener(Event.ENTER_FRAME, interaction);	
				/* Same as the rollover loop, detect the hit but also register that
				 * something has been 'pushed'

By setting a depth element (depthLimit), it's this that creates the push to click gesture. However there is an issue, because we're always calculating the z index of your hand in the application file, there's quite a bit of lag and when you want to use logic loops such as 'while' then this can cause you some memory issues in Flash, especially since actionscript is not a multithreaded language.

        		var i:int = 0;
        		for(i; i < all.buttons.numChildren; ++i){
			        if(right.handhit.hitTestObject(all.buttons.getChildAt(i))&& isPush==false){
						isPush = true;
						// greensock shrink the button, 0.06, {scaleX:1, scaleY:1, ease:Cubic.easeIn});
						if(all.buttons.getChildAt(i).name == "myMovieClipName") {
							//Do something for an individual button
            		} else if (right.handhit.hitTestObject(all.buttons.getChildAt(i))&& isPush==true){
						isPush = false;				
						all.buttons.getChildAt(i).prevFrame();, 0.06, {scaleX:1, scaleY:1, ease:Cubic.easeIn});
						if(all.buttons.getChildAt(i).name == "myMovieClipName") {

The final part of the interaction function is the hit test which then loops through each button and skips to it's next frame if it's the one hit, I also left in some logic to get the name, in case you wanted specific functions. I use the for loop rather than write a whole series of if statements, it works by getting the number of child movieclips in the parent movieclip and then iterates through this number to get the index of any child movieclip. With that we can also get the name, frames etc... of that clip. You can read more here about Dynamic hit tests in Flash & AS3

In this loop we record whether something has been pushed so we can skip back and forward between frames - if you were loading new content/ new screen on a button press then you wouldn't need this logic, it's just there as a quick hack.

Finally, be warned, if you introduce a lot of complex actionscript, then expect it to drastically slow down, the tween animations being used are actually happening much slower than they should. This is because of the way in which we're grabbing the Kinect data. If you were to do this with the Microsoft Kinect SDK on Windows 7 you'd still have the same issue due to the amount of middleware needed to get this to run. Looking forward however, my hope is that from Windows 8 onwards we could have native Kinect like the Xbox, I doubt Microsoft will ever support any none Microsoft platform or even their own older OS.

Here's the video of me using the app just to prove that it does work although the push gesture is a bit glitchy...

Interfacing Kinect with Flash & AS3


A very quick guide on how to hook up the Kinect with the AS3Kinect project, you can find all the relevant information on the different wrappers for AS3Kinect at:

The AS3Kinect project works with either OpenKinect and OpenNI and you’ll need a specific version depending on the wrapper that you’re using. Talking of wrappers here’s a couple of things to remember about them:

  • You can’t have more than one running, so you have to pick and install one
  • Each one has different features, the main advantage of OpenNI is that it provides skeletal tracking data

I show how to set up the OpenNI & Primesense drivers here: Getting the Kinect setup on your PC: OpenNI / Primesense

I went the route of OpenNI purely for skeletal tracking for some of the projects I was working on. To get that skeletal data you just as easily could use the Microsoft drivers that they released only after everyone hacked the Kinect and then Microsoft realised they were missing out. BUT while they work a bit better and provide everything, it ties you to Windows 7, which I don’t have and don’t need. I also dislike the idea of being tied to specific software.

So, anyway, follow my set up for OpenNI as that’s what I’ll be using in later tutorials. Now you’ve done that it’s very easy to use the AS3 server, just download it at:

Unzip that somewhere and in the XML file you’ll need to add in the license key (Similar to the OpenNI setup steps):

For reference my later projects/ examples will have this info done for you.

The .exe file is your AS3 socket server that pulls the data from the OpenNI drivers for you to use in your Flash projects via the as3kinect actionscript libraries. I tend to keep an instance of the server in the same folder as my Flash project as well as the libraries. You’ll always need to have this running to get Kinect data, incidentally, if you close your Flash projector file (.exe, .swf) you’ll need to restart the server each time.

AS3demofilesIf the AS3 server doesn’t start and if you’re sure the drivers are installed, first check the power! If the Kinect is not plugged into the power supply and you’re just trying to use the USB power, this isn’t going to work.

Anyway, to test this works download the demo AS3 files:

Unzip that, start up your AS3server and then run 3d_test.exe if it’s all working then you should get something like the following screenshot:


To get the Kinect/ OpenNI drivers to recognise you, you’ll need to perform the pose which I’ll refer to as ‘The Cornholio’ cornholio

Once you’ve done that you should be able to see the program tracking your hand movements.

Now that’s all working have a look at to get an idea of how to pull data using the as3kinect library (in the org folder).

Got it? Good, time to move on and I’ll show some examples of using this data.

Getting the Kinect setup on your PC: OpenNI / Primesense

Here’s the full details and process on getting your Kinect running on your PC using the OpenNI and Primesense drivers, yes this may be a little old news for some, but my guide here will actually get your Kinect running pretty much first time rather than leave you to guess and try to follow the other guides out there.

So first of all you’ll need a Kinect! Now we’ve sorted that out, the rest is easy and just a matter of following the steps – I’m documenting this as much for my own use as well as yours… I’m doing this for a Windows XP laptop, but you can do this on Ubuntu, Windows 7, Mac OSX etc…

1. Remove any existing drivers

First of all, if you have any drivers previously installed for the Kinect, such as OpenKinect, Freenect, Microsoft Kinect drivers etc… you’ll need to remove/ uninstall them. They will appear in the device manager under Human Interface and normally be called something like Xbox NUI Motor, Xbox NUI Camera, Xbox NUI Audio. Incidently when you install the OpenNI/ Primesense drivers, they are named differently and you do not want to under any circumstances use the above drivers.

2. Download and install the following drivers & binaries

download kinect sensor driver

Head on over to Github and get this package which you want to download that and then navigate to the Bin directory and install the relevant driver for your OS. This has the drivers precompiled for you but you can also compile this from source. The file will be something like:

  1. SensorKinect-Win-OpenSource32-

OpenNI downloads

Next, you’ll want to go to OpenNI.orgs download page and for each of the options select stable choose which development package you want for your OS:

  1. OpenNI Binaries
  2. OpenNI Compliant Middleware Binaries
  3. OpenNI Complient Hardware Binaries

You can also download & compile these from binaries by going to the OpenNI github page

So now you should have 3 files something like:

  1. openni-win32-
  2. nite-win32-
  3. sensor-win32-

Or whatever you’ve compiled from Git, run the installs etc…

On the Primesense Nite installation, if prompted for a key, add the following:


Now that’s done you’ll need to download and install the Microsoft Visual C++ Redistributable Package for your OS which can be found at:

In my instance I’m using the x86 one, for windows 7 use x64 etc… just grab the latest one available. This allows you to run the OpenNI applications.

3. Plug and pray

Now plugin the Kinect – make sure you have the power plugged in as well, not just the USB! Your computer should recognise the Kinect and want to install the drivers – make sure you choose the Primesense ones if prompted – I found that when I had old drivers it remembered the location, so I just zipped up the folder and archived it to remove it from the driver search.

Device manager after successful install

If all goes well you should have 3 hardware installation screens on Windows and the device manager should show the hardware under Primesense

4. Setup

Now that’s installed there are a few more things you need to do in order to hook up OpenNI and Primesense, namely a few XML config files which you just need to add in the same license key so that Primesense will work for you that key was:


Insert OpenNI key

Link OpenNI and Primesense

5. Finished

Now that’s done you can start to play around with the examples – there are various wrappers/ API’s available to you to now use this to create applications.

  1. Test out OpenNI by running the NiViewer sample
  2. Test out Primesense by running any of the samples there

Primesense sample

Now you have that installed you can move on to using various wrappers etc… to hook the Kinect up to Flash, Silverlight, Processing, Arduino, Java, Python etc…

Playing with Peltier Elements

Something I’ve been continuously dabbling in is producing electricity. I figure that it’s not enough just to use it and I should look at ways in which I can produce and scavenge it to understand it better.

This is a simple exercise in which we look at Peltier elements and the Seebeck effect. By running electricity through a Peltier element you can make a device which can either heat or cool something. Not only that but by heating or cooling one side of the Peltier element you can generate electricity from something either hot or cold – note that this isn’t free energy and this is only useful for recovering waste energy.

And if you doubt any of this, then give it a go for yourself.

For this project you’ll need the following items (shown above):

  • Heat sinks – I ripped them out of an old computer, from the CPU and the graphics cards – basically you’re looking for anything aluminium or copper based, sheet or section metal will also work just as well.
  • Batteries – I’m using 3 AAA batteries to generate about 100ma / 3.5 V
  • Breadboard – not essential but useful for a quick circuit
  • Low power LED – I’ve added a couple of short leads to mine
  • Electrical tape (just in case) – balanced the heat sink on above the candle and also taped the multimeter probes to the peltier
  • Candles + lighter/matches
  • Thermometer – this is a medical one, use anything you have to hand (get a proper one, mine was rubbish)
  • Multimeter
  • Toothpaste – Yes! This is correct, it’s not a mistake.
  • A Peltier element

You should be able to find everything you need around the house for free, you don’t need anything fancy except of course the Peltier. To get one of these, they are used in some computers to help cool the CPU but probably, like me, you’ll just have to buy one. I got mine from Farnell Electronics – they have a good range of them on the site between £11 and £125, they also ship worldwide which is handy. The one I chose is a bit pricey at about £20, but it has a good temperature differential, low internal resistance and fairly low voltage/current at maximum temperature differential – meaning I won’t need to use a huge power supply to see it working. This is the Peltier element I used and here’s more Peltier elements listed.

Ideally after doing this experiment, I want to get a few more and you may also want to do that as well once you realise what you can do with them. Anyway, I guess I should actually explain what a Peltier Element is…

What is a Peltier Element

In 1821, Seebeck found by using two different metals that are connected by two separate junctions, they will develop very small voltage if the two junctions at maintained at different temperatures.

In 1834, Peltier discovered the opposite of this, he found that if you apply a voltage to the same setup that it caused a different temperature at each junction, allowing you to generate both heat and cold from the voltage. Although what’s actually happening is heat transfer, the heat is transferred from one side to the other, making this a solid state heat pump.

You may also find they are referred to as TEC’s – ThermoElectric Coolers or in some cases TEG’s – ThermoElectric Generators. Essentially the Peltier Element is a combination of lots of very small thermocouples, junctions between 2 different metals or semi conductors and these are sandwiched between 2 ceramic plates and then encased in silicon.

They are in no way as efficient as regular refrigeration and are used for the benefit that there is no maintenance, no moving parts and they can occupy a much smaller space. They are used when the rapid heating or cooling or something is needed – typically lab work.

So if they’re so inefficient why do we care?…

Energy Scavenging with Peltiers

OK, so you can’t get a lot out of these, but the point is by combining them in systems that produce a lot of wasted heat, we could minimise the waste and reclaim this. Granted, this is not going to amount to much, but scale it up and you can see why car manufacturers such as BMW are beginning to combine them around the exhaust – some of that wasted heat from the engine can be converted to electricity. So if you’re going to waste heat, why not get the most out of it?

Imagine an oven lined with these, or a device that could cook your food and chill something at the same time. Of course, it’s much harder than that, unfortunately Peltiers aren’t able to transfer much heat and because they work by creating a temperature differential, you need a way extract the heat and keep the other side cool at the same time. So just sticking them out in the sun or on the side of your oven isn’t going to generate electricity, it works on a car exhaust because of the air flow when the car moves cools one side.

OK, enough talk, on with the demonstration…

Generating temperatures with Peltier Elements

This circuit is really simple, we’re just going to connect the Peltier to the battery cells and measure the voltage. You can see from the picture above, I’m using the breadboard to connect the two, but this is just me being lazy. Be very careful when you connect this to the battery – one side is going to get very hot. For safety I’m resting this on one of the heatsinks. These temperatures are generated from a 3.5v source and to show room temperature I’ve added another thermometer.

Here’s the hot side giving out 42.6 degrees C

And the cold side was too cold for my thermometer to read – need to get a better one but it felt much like something fetched from the fridge

What I did find is that when I had the heatsink on the hot side, I got a much better result, also there was no notable heat from the hot side, however much more heat off the batteries! It seems these are much better at cooling that heating.

Generating electricity from heat

Still a simple circuit, but this time no batteries! the LED is going to be powered by the Peltier (hopefully), it’ll be really dim and if you can’t see anything, use the multimeter to measure the voltage and current – I did warn you not to expect much! The trick of course is to remember basic physics, heat rises, so ideally you want your peltier to the side of the heat source so that only one side is heated, otherwise you’re not creating the optimum temperature differential – this is what the metal is for – conducting heat to the peltier. First time and I get 0.5volts and 260 mA, not enough to light the LED.

Oh and the toothpaste? So, the surface of the heat sinks and the peltier are going to have lots of imperfections and because of this, they won’t transfer as much heat in between the element and the heatsinks. You could use thermal paste but I don’t have any to hand – I found using toothpaste (seriously!) works just as well for a short time, however, under heat it soon dries out. It’s also much much cheaper to use as you experiment. Basically I think any kind of paste will do, whatever you have to hand. I found that with this, I got additional voltage and current generated (0.67V and 350mA), as below – also just to prove I really did use toothpaste, I added in the picture of the nice striped toothpaste being applied.

I also increased the heat source to 2 candles which proved to substantially improved the readings to 1.05 volts and just over 520 mA!!. Still not enough to fully power my LED and I have a feeling that prolonged temperatures like this even with my toothpaste additive is shortening the life of this Peltier.

If I could generate airflow over the heatsink on the non-heated side, I suspect I could further improve the temperature differential and create more electricity and also further distance the heat source, it was still much too close but Idid the best with what I had.

In conclusion

So there you have it, from 2 candles I very inefficiently generated over a volt of electricity, I could really refine this and improve it but unless I’m using candles anyway, then there’s no point other than for demonstration. I’d be interested in adding in multiple elements to generate more, which I may do in the future, but I’d have to run this from something where there is wasted heat – maybe my motorcycle engine block.

Anyway if you want to get some energy back from the heat you’re wasting, want to heat something, want to cool something then have a look at these. They’re probably not that efficient used to cool electronics, such as computers but there are plenty of niche uses that can be found for them and they’re definitely worth playing with if you get the chance.

I was also surprised that the elastic band holding this all together didn’t snap off! 🙂

One top tip – to remove the toothpaste, the best thing to use is… a toothbrush! And unlike thermal paste, it leaves your heat sink smelling minty fresh.

I now have visions of a candle powered Arduino!!

Shakeable Dynamo Part 4: Building the bridge rectifier

[ad#Google links]

Shakeable Dynamo Part 1: Why bother?
Shakeable Dynamo Part 2: Building the initial dynamo
Shakeable Dynamo Part 3: How electromagnetic induction works

Lets start off by securing our coils on our alternator by removing the cardboard guides and then getting some clingfilm and wrapping a piece around your coils and then wrap a bit of tape around it to secure it all. Now we know it works, we don’t want to risk our coils moving or our connections breaking.

What’s a rectifier?


So what is a rectifier? A rectifier converts AC current to DC current, so we convert the current that changes direction to flowing in one direction. That means we’ll then get the full benefit of the electricity we’re creating rather than only half of it. Rectifiers use a series of diodes to achieve this. A diode (pictured left) is essentially a valve, it lets the flow of electricity through only one way, shown by the green arrow in my diagram, the silver band indicates the cathode  (-). By arranging a few of these together we can then convert our current by forcing current to flow one way.

How does a bridge rectifier work?

In the diagrams to the right, the flow of electricity is shown, red arrows for positive, black for negative. In the top diagram the current flows across the top diode from the alternator to the output, negative is flowing across the bottom from the green wire, back through the diode to the alternator. When the magnet changes direction and the current reverses, the bottom diagram shows that the flow is blocked and can only flow to the same positive output. So no matter which way the magnets move or whichever direction the current moves in the diodes always divert the flow to the same points.

How to build a bridge rectifier circuit

With that understood we can then plug in our hook up wire from our alternator into a breadboard to build the basic rectifier circuit which we can then check that it works and solder it to our leads. You can see in the series of photos below that we take the 2 leads from our alternator, connect them to the diodes as per the circuit diagram, then we attach another 2 leads to the 2 remaining ‘corners’ of our bridge rectifier – and remember these now are direct current and one lead will be positive and the other negative so it will matter which way you attach the LED or any other component.

Shakeable dynamo: Build a bridge rectifier

Cut and solder the diodes and leads together.

Shakeable dynamo: Solder the bridge rectifier

Then ‘wrap’ the circuit over the end of the tube.

Shakeable dynamo: Trim and wrap the rectifier around the end of the biro

And finally secure it into place with some electrical tape.

Shakeable dynamo: Tape over the connections

You can see that I’ve also soldered on an LED to the new DC power supply, also remember to mark out which wire is positive and which is negative. Here’s the final result again working…

Coming up – improving the alternator and charging a battery with it…

Shakeable Dynamo Part 3: How electromagnetic induction works

Atoms of a magnet

[ad#Google links]

Shakeable Dynamo Part 1: Why bother?
Shakeable Dynamo Part 2: Building the initial dynamo

Right, so we’ve built the initial alternator/ dynamo and it works, not amazingly, but it works and we need to make this is a little bit more robust and protect all those lovely windings as well, at the same time we also need to convert our alternating current (AC) and convert that to direct current (DC), so that we can use this to power a small circuit/ LED without it turning on and off all the time. First I should probably explain how this all works… (feel free to correct me if I am wrong in my assumptions)

How do magnets work?

Atoms of a magnetEvery magnet creates a magnetic field due to the arrangement of the atoms in the material, in very simple terms, the atoms are spun so that most of the electrons are on one side of the atom, creating a negative charge on one side, while the lack of electrons on the other side of the atom exposes the positive charge of the protons in the nuclei. In the very simplified diagram to the left, the  nuclei are blue and the electrons are orange and their arrangement produces the  different overall charges with more electrons flowing to one end of the magnet. This also explains why when you cut a magnet in half you will get 2 magnets, not a separate south and a north pole. This then creates the polarisation effect we see in magnets and this is also where naming conventions jump into confuse matters! So first of all magnets are referred to has having a ‘north’ and a ‘south’ pole due to this polarisation effect from the different atomic charges. This is because when suspended freely, the magnets ‘north end’ will spin to point to the Earths magnetic north, which if you think about it makes no sense, since magnets attract the opposite pole (North attracts South). What is really happening is the ‘north’ pole of a magnet has a negative charge due to the arrangments in the atoms and it’s attracted to the positive charge of the Earths magnetic north – so either the north end of our magnet is actually south or the Earths magnetic north is actually magnetic south.

How does electromagnetic induction work?

how electromagnetic induction works

Electromagnetic induction essentially is where a magnetic field or flux causes the flow of electrons in a conductive material. This is actually important to us in explaining what’s happening in our alternator, our north pole of the magnet is negatively charged, the south has a positive charge. This means that they will always try to attract an opposite charge, so when a magnet passes through or near an object with good electrical conductivity, the electrons in the conductor will be attracted to the south pole of our magnet, while the north pole  will repel the electrons. This creates a movement in the electrons, essentially creating a flow of current, some materials will have a better conductivity as the electrons are able to move more freely. You can see in my basic diagram above how the magnet will attract and repel the electrons (orange circles) in the wire thus creating the alternating flow of electrons or current – without getting too complicated alternating means the current flows in 2 different directions which produces a sine wave.

Now, what happens as our magnet passes through our coils is that the electrons are pushed and pulled creating our alternating current, so the current switches directions based up on whether the electrons in the coils are being attracted or repeled. This then means that at either end of our coil there is an intermittent electrical charge switching between positive and negative, so an LED attached to one end will only light up when the magnets push/ pull the electrons in one direction.

Whats the difference between alternating current (AC) and direct current (DC)?

We want to get all the power of the alternator and not just half of it so we need a way to create a constant flow of current/ charge/ electrons so that our LED will always light up no matter which way the magnets are moving. This is where our rectifier comes in, converting or AC to DC (Direct Current). Direct current is where the current flows in only one direction, classically this is described as going from positive to negative and in most electronics this is the model that is used, however, in physics it’s considered the other way around!

Now that’s all understood we can move on to building our rectifier for the generator

Shakeable Dynamo Part 4: Building the bridge rectifier

Shakeable Dynamo Part 2: Building the initial dynamo

[ad#Google links]Shakeable Dynamo Part 1: Why bother?

Firstly, there is no such thing as ‘free energy‘ you have to always put something in to get something out. I call this free energy because it comes from your own movements rather than having to pay cash for a battery or the juice to charge it, I guess it’s better to call it ‘financially free energy’. Also when you look at this, some of you may point out that this isn’t a dynamo because it generates AC current, but I call it a dynamo because of the bridge rectifier built in to that converts this to DC.

Basically like all alternators and dynamos it works on the principle of converting mechanical energy into electrical energy by inducing current in a conducting medium, such as copper wire, using a magnetic field. Typically this is done by rotating a magnet inside coils of wire.

My alternator works in much the same way – we move a magnet through a coil of wire to induce a current, only we do this in a linear motion rather than circular. There are lots of crazy equations out there that state how much current you will get from a magnet of certain strength, a certain number of coils of wire of a certain thickness etc…

Mine is much much simpler – I first did a very small test to check that the principle worked, with only a few coils I got a current. Then I just kept winding until I got to a certain thickness and invariably got bored! My windings weren’t at all neat and were all over the place, so if my bodge job worked a more precise version will work better (probably).

So the main question arises – how much current can I get out of the smallest amount of wire and magnets. My aim was to build something to the thickness of an AA battery.

Ok, lets look at all the parts you’ll need, it’s actually not that many and for your magnets and wire – get it off ebay, you’ll get far more for far less than from buying them from a retailer.

What you need to build a simple dynamo / alternator


  • 1 biro or piece of tubing with a 6mm diameter cut to roughly 10cm in length, the magnets will need to slide freely down the tube
  • At least 3 neodymium (rare earth, super strong) circular magnets with a diameter of 6mm – you can buy a set of 50 for not very much – these are really strong so be careful
  • Magnet/ winding wire around a 32-42 AWG, thinner wire (42 AWG) means more coils
  • 4 ‘N’ series rectifier diodes – any will work fine for our low voltage most of the 1n series have the same voltage drop – I used 1n004’s
  • Some hookup wire – around 18-22 AWG (any wire will do really) for soldering the magnet wire to and building the circuit.
  • An LED (for testing)


  • Soldering iron & solder
  • Breadboard – useful to build the bridge rectifier and test the dynamo
  • Cutters & wire strippers
  • Also handy to have a multimeter to check the output and a couple of screwdrivers or sticks to help spool the wire

Other materials

  • Some clingfilm and electrical tape

So lets build it step by step with my photos, at the end of this you’ll have the basic dynamo, Step 4 at the bottom will show you how to build the rectifier and the theory behind that.

How to build the alternator

First check that your magnets slide easily through your tube, you may need a few connected together to stop them spinning inside or getting stuck.

Now get your tubing or pen and cut it to size, about 10cm in length

Shakeable dynamo: Cut the biro

Next we need to add some ‘guides’ so that we can keep our coils in place on the pen, I used a square of cardboard from a box taped on the ends

Shakeable dynamo: Add a guide for the coils

Now the fun part, winding the coils. First don’t bother taping down the end of the wire, instead make a small cut in one of the guides and use this to hold the wire in place as you wind – you need to be able to get to both ends of the wire later on! You’ll need to save about 5-10cm.

The easiest way to coil the wire would be do use a drill or something to spin the tube, taking wire off the reel, but this wire is so thin that if it gets snagged it will snap and you have to start all over again. Best to do it by hand and watch some TV as you do it, it doesn’t take that long just stick your tube over the a screw driver so you can spin it and stick the reel onto something like a drum stick.

With the reels stick on your lap, the reel between your legs, you can now hold the tube and spin it on the screwdriver to wind the coils and keep a fairly good tension. If you want to be precise then you can wind the coils accurately or like me just wind away in any fashion.

Shakeable dynamo: Spool the magnet wire on to the biro

I kept winding until my coils got to the thickness of an AA battery, so a diameter of about 12mm – took a while but after a while it gets easy, especially if you’re not fussed on how well it’s wound.

Next we take 2 pieces of our hookup wire, remove the casing on either end and then wrap one end of the copper magnet wire to one end of each wire, you’ll need several coils around this wire.

Shakeable dynamo: Wrap the ends of the magnet wire on to some thicker wire

Now get out that soldering iron and get it heated up, the heat of the solder on the ends of the wire will melt away the very thin varnish on the copper magnet wire while it also binds it to the hook up wire. Be careful as the thin wire will snap very easily and you’ll need to repeat this step.

Shakeable dynamo: Solder the wires

Before we go further you may want to check that the connections are good with a multimeter set to measure continuity. As long as there is some fluctuation in the initial reading all is good. You can see that I’ve temporarily secured my magnet wire to the guides. This is also a good time if you want to measure the current generated when your magnets pass through the tube / pen.

Shakeable dynamo: Test for continuity

And thats it, shake the magnets inside the tube to generate a current the basic alternator is built, you can hook that up to a breadboard to play with, if you add an LED and shake the generator you’ll see the LED light up, it’ll be quite dim and no matter how fast you shake the magnets, the LED doesn’t remain consistantly powered, this is because the current is alternating and an LED require direct current instead.

Once you’re happy and understand whats happening we can proceed to step 3 which improves up on the blinking LED and gives you a current you can actually use.

Shakeable Dynamo Part 3: How electromagnetic induction works
Shakeable Dynamo Part 4: Building the bridge rectifier

Shakeable Dynamo Part 1: Why bother?

[ad#Google links]

First of all I have to start by condemning Brother Industries for what ultimately motivated me to build this basic prototype, allow me to explain and I apologise for the rant, the good stuff follows…

I read an article on the BBC news website (Vibration packs aim to replace batteries for gadgets) about a new type of battery developed by Brother that would require no external power source to charge it, just vibration from shaking it a few times. The aim being to replace batteries in low power applications such as TV remotes etc… thus removing alot of these batteries from the environment and ultimately saving energy.

A really nice, clean and elegant solution which could really benefit not only the developed world but for people in the developing countries. What a great company Brother Industries is until you read at the bottom of the article “There are no plans to commercialise the batteries as yet, according to Brother.”

Wait… So you’ve invented, or rather figured a way to not only replace millions of batteries in the common household, cutting down on waste and pollution providing free energy. But also a way to provide cheap portable power sources to people who can’t afford batteries, giving us as near as you’ll get to an ‘ever lasting battery‘!

And instead of rushing this to market, you do what… Nothing! Absolutely nothing. What a shame and a waste, I can’t help but feel that people at Brother have an interest in Duracell etc… as they obviously wouldn’t appreciate a battery that you don’t need to replace. It’s that kind of mindset of greed and ignorance that ruins the planet for the rest of us.

So this is leading somewhere, I assure you! I thought, how hard can this be to build my own – wouldn’t it be great to build a set of batteries that I could use to power my remote, wait wouldn’t it be even cooler to use this to power my Arduino? or even better build an interactive TV remote that you used like a wand to change channel with no power source needed. When you start imagining the potential applications and how this could revolutionise electronics and interactivity, its even more of a shame on Brother for doing nothing with this. Imagine Nintendo using this in their Wii remotes for instance? Imagine this being used to build a simple water tester… etc.

Anyway, here’s the start of it I’m going to show you how to build a basic dynamo with a bridge rectifier that converts our AC current to DC, and the size of it is not much bigger than an AA battery – it’s my first attempt and it turned out pretty well. It generates enough electricity to power an LED – doesn’t sound like much but when I figure out a condensing and charging circuit that’s when the fun starts – for which I’m hoping that you fine people of the web will help me out! 🙂

Ready to learn a bit about electro-magnetism and inductance?

Shakeable Dynamo Part 2: Building the initial dynamo
Shakeable Dynamo Part 3: How electromagnetic induction works
Shakeable Dynamo Part 4: Building the bridge rectifier

Arduino – Redefining the TV Remote

We use them every day, but has no one got bored of pressing buttons on a stick, it’s far too much effort pressing buttons! Surely there are better ways to control a device? After doing some work with my Nikon camera using IR to control it, I wanted to do the same with other devices. Check out the video at the bottom of this post…

However, unlike the Nikon remote, my Samsung TV remote has many many buttons so each IR sequence sent from the remote will be different. This can be a problem when you want to decode the signals, which while not impossible I am lazy, so thankfully Ken Shirriff has built a library to do just that and while its built for TV remotes you can decode an IR signal to its raw pulses using it. Essentially the library senses IR and notes each pulse and gap between pulses, Kens library saves a lot of time and its well coded – I’ll cover the basics of it in a bit.

My idea is to capture the IR sequences and then using the Arduino send them by using different inputs other than buttons. My first idea is to use my SRF05 distance sensor (You can use any distance sensor) and the premise being that different distances from the sensor send different signals to the TV. So rather than pressing a button you just wave your hand above the sensor. Of course this is slightly limited but since I only have 5 channels (yep – only 5!) so it turned out to be quite feasible.

There are drawbacks to this of course – the main one being that you can only define so many actions in the sensors dectection range. But there is plenty of range to do the basics, power, sound and channel and by constantly measuring distances we can even say the direction of movement, up to down and vice versa, can have an effect on what signal to send. For example moving your hand closer to the sensor will change the channel down.

So first of all you may want to read some of my other tutorials/projects concerning IR and the SRF-05 and Sharp IR (it should also work well).
Arduino Nikon IR Intervalometer Camera Remote
– contains handy wiring diagram!
Arduino and Sharp GP2Y0A02 Infrared distance sensor

(Other Arduino projects and tutorials)

OK, next take a look at Ken Shirrifs IR library and guide here:

Arduino TV Remote Components

IR Diode
3pin (NPN) Phototransistor/ IR receiver (
Radio Shack 276-640 IR receiver, Panasonic PNA4602, Vishay TSOP4838 – or just get one out an old mouse)
SRF-05 (or any distance measuring device e.g. Sharp IR GP2Y0A02)
Jumper wires

Oh and stating the obvious but you’ll also need a T.V with working remote to steal the signals from – course you can use other remotes (stereos etc..)

The circuits themselves are very very easy to build, an IR LED to pin 3, a IR receiver to pin 11 and the SRF-05 I’ve plugged into pins 2 and 4. I have all of them in one breadboard and it works very well (see below).

Using Kens Arduino TV Remote Library

If you download the library and then unzip it to your Arduino/Libaries directory (older versions, I think its Arduino/hardware/libaries). The library assumes that your phototransistor/ IR receiver is on digital pin 11 and your IR diode is on digital pin 3. Typically you want a IR receiver with a 38Khz range – they seem to work best for me.

How to get our TV infrared/ remote codes

First of all use Ken’s IRrecvDump example (should be in your examples menu) load this into your Arduino and begin to capture your remotes codes. My Samsung wasn’t recognised so I used the Raw codes – there’s plenty of documentation on Ken’s site for this – it’s really simple, even I could figure it out. You need to note how many pulses etc.. it decodes in the raw signal which helpfully is outputted e.g. Raw (68):

Now we process the codes slightly and put them in an array for each one now that we have our codes and the information we need to use them – since mine are in the raw format I need to clean them up slightly ready to be put in my code – just adding commas etc…

Now we can test the remote codes to make sure you can control your TV

Now using the IRsendDemo example, altering it my case to send the raw signal, we can test the codes to make sure that we can control the T.V – just use the basic sketch to send the codes which I edited slightly just to use an array for the raw code. You can check out the library files themselves to see the functions.

 * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff


IRsend irsend;

// just added my own array for the raw signal
unsigned int powerOn[68] = {4450,4500,550,1700,500,1750,500,1750,500,600,550,600,500,600,550,600,500,600,550,1700,550,1700,550,1700,500,600,550,600,500,600,550,600,500,650,500,600,550,1700,500,650,500,600,550,600,500,600,550,600,500,600,550,1700,550,600,500,1700,550,1700,550,1700,550,1700,500,1750,500,1750,500};

void setup()

void loop() {

      // altered the code just to send/test my raw code


Add the distance sensor

This is actually the hardest bit and it’s not that hard really I just used my previous work and adapted it and wrote a few statements concerning the detected distance. You just have to spend some time debugging and getting your values right to ensure that your commands are only sent at the right time and that it doesn’t get confused. My code is still a little buggy if you’re not used to how to move your hand but it does work well once you’re used to it.

[ad#Google Ad in content]

    Larrys alternative TV remote - oops no buttons!
    Sends signals to TV based upon sensor readings

    Makes use of Kens Shirriffs IRremote library
    An IR LED must be connected to Arduino PWM pin 3.
    Version 0.1 July, 2009
    Copyright 2009 Ken Shirriff

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .

IRsend irsend;

const int numReadings = 5;   // set a variable for the number of readings to take
int index = 0;                // the index of the current reading
int total = 0;                // the total of all readings
int average = 0;              // the average
int oldAverage = 0;           // the old average
int echoPin = 2;              // the SRF05's echo pin
int initPin = 4;              // the SRF05's init pin
unsigned long pulseTime = 0;  // variable for reading the pulse
unsigned long distance = 0;   // variable for storing distance

// setup my arrays for each signal I want to send
unsigned int powerOn[68] = {4450,4500,550,1700,500,1750,500,1750,500,600,550,600,500,600,550,600,500,600,550,1700,550,1700,550,1700,500,600,550,600,500,600,550,600,500,650,500,600,550,1700,500,650,500,600,550,600,500,600,550,600,500,600,550,1700,550,600,500,1700,550,1700,550,1700,550,1700,500,1750,500,1750,500};
unsigned int soundUp[68] = {4450,4500,550,1700,550,1700,500,1750,500,600,550,600,500,600,550,600,500,600,550,1700,550,1700,550,1700,500,650,500,600,550,600,500,600,550,600,500,1750,500,1700,550,1700,550,600,500,600,550,600,500,600,550,600,500,600,550,600,550,600,500,1700,550,1700,550,1700,550,1700,500,1750,500};
unsigned int soundDown[68] = {4400,4550,500,1750,500,1700,550,1700,550,600,500,600,550,600,500,600,550,600,500,1750,500,1750,500,1700,550,600,500,650,500,600,550,600,500,600,550,1700,550,1700,500,600,550,1700,550,600,500,600,550,600,500,600,550,600,500,600,550,1700,550,600,500,1750,500,1750,500,1700,550,1700,550};
unsigned int channelUp[68] = {4400,4550,500,1700,550,1700,550,1700,550,600,500,600,550,600,500,600,550,600,500,1750,500,1700,550,1700,550,600,500,600,550,600,500,650,500,600,550,600,500,1700,550,600,550,600,500,1700,550,600,500,650,500,600,550,1700,500,600,550,1700,550,1700,550,600,500,1700,550,1700,550,1700,550};
unsigned int channelDown[68] = {4450,4500,500,1750,500,1750,500,1700,550,600,500,650,500,600,550,600,500,600,550,1700,500,1750,500,1750,500,600,550,600,500,600,550,600,500,600,550,600,500,650,500,600,550,600,500,1700,550,600,500,650,500,600,500,1750,500,1750,500,1750,500,1700,550,600,500,1750,500,1750,500,1700,550};

void setup() {
  // make the init pin an output:
  pinMode(initPin, OUTPUT);
  // make the echo pin an input:
  pinMode(echoPin, INPUT);
  // initialize the serial port:

 void loop() {

    // loop for a number of readings on the SRF-05 to get an average to smooth the results. Much like all my other examples
    for (index = 0; index<=numReadings;index++) {
      digitalWrite(initPin, LOW);
      digitalWrite(initPin, HIGH);
      digitalWrite(initPin, LOW);
      pulseTime = pulseIn(echoPin, HIGH);
      distance = pulseTime/58;
      total = total + distance;
    // store the previous reading
    oldAverage = average;
    // store the current reading
    average = total/numReadings;
    // debug to check for spikes in the sensor etc..

    // now the fun part...
    // if my distance is less than 5...
    if (average <= 5) {
      Serial.println("Power Off");
      // use Kens IR library to send my signal (array, number of items in array, Khz)
      // these delays depend on how long it take my device to recognise the signal sent and to act - I don't want to send signals that aren't getting read etc..
      // otherwise if my hand is higher
    } else {
      // check to see if my hand is in the registered space above the sensor
      if (average <=20 && average >=10 && oldAverage >=10) {
        // the below statement is our sensitive the readings are so if the current and previous readings are different with a tolerance of +/- 1 we can look at the direction of movement
        if ((average != oldAverage)
        && (average+1 != oldAverage)
        && (average-1 != oldAverage)) {
          // if the current reading is higher than the previous, then my hand is moving upwards
          if (average > oldAverage) {
            Serial.println("Channel Up");
          } else {
            // otherwise if it is below then my hand is moving downwards
            if (average < oldAverage && oldAverage <=20) {               Serial.println("Channel Down");               irsend.sendRaw(channelDown,68,38);               delay(2000);                        }                  }          // otherwise my hand must be stationary so check where it is.         } else {           // if my hand is stationary between 10 and 15 cms away from the sensor           if (average >= 10 && average <=15) {             Serial.println("Sound down");             irsend.sendRaw(soundDown,68,38);           } else {             // if my hand is a bit higher up...             if (average >= 16 && average <=20) {               Serial.println("Sound up");               irsend.sendRaw(soundUp,68,38);             }           }         }         }     }        // clear our index and total for the next reading just in case     if (index >= numReadings)  {
      index = 0;
      total = 0;

[ad#Google Ad in content]

Removing Crackle from Guitar

guitar pot

Got a cheap fender-like guitar I’ve had a while and it doesn’t always work, I plug it and then it crackles and cuts out frequently and if I turn the dials it also crackles. A friend wanted to use it so I’ve got motivated and I’ve gotten round to fixing it.

These steps apply to most modern guitars – if it’s a vintage you may not want to follow the steps.

It’s very simple to fix the electrics for the average guitar nothing really that concerning and removing the crackle from the pots/ dials is as easy as just buying some cleaner. It really is that easy.

Testing the jack with a mini amp

To test the connections/ circuitry as well as a multimeter I found it really useful to use a mini amp and headphones so I could listen for changes and improvements as I reproduced the fault.

First things first start with the jack and remove this from the guitar to inspect the connections. Should be a couple of screws holding the jack plate in and you’ll need to remove this and then unscrew the jack from the plate – there should be a couple of nuts holding it in place.

Faulty jack - half the problem...

Next have a look for something obvious – in my case the joint just wasn’t soldered properly. I cut the wires, stripped the ends, then resoldered the connections after removing the previous solder (or lack of in this case).

Cut wires from jack and strip wire down

Repaired jack

Moving the jack with the amp and headphones connected, listening now I can see the connection is fixed but turning the pots/ dials I hear the crackling still. The jack is the first place to start for a loose connection but if the problem is not the jack or still persists with an intermittent connection  after you’ve fixed the jack then you have a loose connection elsewhere. Next obvious place to check is the grounding/ earth wire – normally attached in the back of the guitar, there is a plate to remove to access this and the truss rod. Basically you’re looking for a wire that is connected to the guitar itself by way of a plate or something similar.

Check all the connections

If that connection looks fine, next check the connections on each pickup, in cheap guitars these joints can be poorly soldered so check and repair. Lastly check the connections on the switches the wiring isn’t too tricky to check just be methodical.

Hopefully you’ve found your loose connection(s) and fixed them, if not you’ll need to go through each connection with the multimeter. If however you’re now left with a crackle/ static sound anytime you turn a dial or use the pickup selector switch read on.

Removing the crackle
So to remove the crackle when turning the dials etc… Just take the pickguard off, if you haven’t already, by removing the screws around the outside. You’ll need some electrical contact cleaner in a spray can with a straw. You need to have a cleaner that is solvent based but also include lubricant since potentiometers and switches should be greased and not left dry as that will make things worse. I found a can down in my local motor store and any decent electronics store should sell it. Again make sure the spray is a lubricant!

Spray contact cleaner into pots and switches

On each switch or pot spray the cleaner  between the back of the pickgaurd and the dial. Keep you face away as it’s likely to spray back a bit and you dont want this in your eyes! You don’t need much spray just a couple of squirts, when done turn the dials back and forth to work in the cleaner, you should feel an improvement and the dial should feel smoother to turn. Repeat for each pot/ dial. For the pickup selector switch spray into the top of the switch from the front of the pickguard and work the cleaner in by flicking the switch back and forth.

Testing electrics

So now plug in the amp and headphones and listen for the crackle – it should be gone now – good way to test as put a string on the guitar and play it.

Hopefully that’s fixed your issues.