Self balancing robot

Ugly! Accelerometer in wii nunchuck, Gyro in Wii motion plus (right side)

In the near future I really want to build a quadrocopter, and would possibly need to do this for two of the interns I’ve been pursuing (NASA JPL or OSF). I was trying to figure out a good place to start and actually get some tests in. After doing some thinking I assume that a quad’s control system is similar to a self balancing robot only in two axis. On a quad I would read the pulses coming from a tx/rx system to adjust the target balancing angle. So far I’ve only put in two days into this robot, yes I am aware that I may not be approaching this the best way! please leave advice! So far it’s been 1 day to get the wii motion plus working with the wii nunchuck (they have the same I2C address…), and 1 day writing the software and building the robot. Everything is very rough so far, so I’m going to wait to post the source code! If you want a copy please leave a comment and I’ll send you the three versions! Once I get more familiar, I’ll surely write a very detailed guide!

Control system:

My current control system. Edit: I calculate angle from the accelerometer right after the offset and scaling.

I’m using a complementary filter, which is used to combine a gyro (accurate but drifts over time) and an accelerometer (not so accurate but doesn’t drift). Anyway look at the control picture to see exactly how I’m doing the calculations. Everything underlined in blue I want to get rid of/move. Possibly I will want to keep the MA so that I can do a standard deviation. The standard deviation could help the platform tune the complementary filter. A high standard deviation for the accelerometer would tune the complimentary filter constants to .999(gyro)/.001(accel) where as a low standard deviation may set it to .95(gyro)/.05(accel) and make it a continuous tuning function.  I’ve also been brainstorming on methods that would allow robot calculate the balancing angle for the platform. As far as phase shift: I’m not too worried about the accelerometer’s phase shift due to the filters, but the gyro needs the phase shift to be an absolute minimum!

Talking to two I2C devices with the same address. Had to include my new tool - saleae logic analyzer

How I would improve results:

The wii motion plus is a ~20$ three axis 2000deg/sec gyro with a plastic case, sockets, PCB, and a I2C pass through chip. This really isn’t the right type of gyro for this type of robot, and I seriously question the quality of the gyros on board. I can say the same for the accelerometer on the wii nunchuck too. I’ve also thought of a few ways to calibrate the system and get the gyro/accel units to match up with each other. Regardless the results are pretty good and I may just need to tune everything. Those servos are also slow as beans! My plans are to replace the gyros with less than 500deg/sec gyros, clean up the algorithm and work on perfecting it! I also need to put the IMU on the pivoting point of the platform.


segway05 – I probably won’t get around to taking another wack at this till summer, so here’s the most recent code. Not many comments other than the blatant mistakes pointed out.

Great resources:

Complementary filter by MIT

Tilt with accelerometer

Calculating angles with accelerometer

Using wii nunchuck and Accelerometer together – Just an FYI if you disable the Wii motion plus to talk to the nunchuck via passthrough port, the wii motion plus takes about 100ms to turn back on which is SLOW. I don’t  have a wiimote/wii, so I can’t listen in on them talking with my logic analyzer. This method is good since both devices have the same I2C address…


Sorry about the terribad quality videos!


Linear resistive divider for the ADC


Simulation of changing -24v to 24v into ~ 0 to 5v.

This is a topic that’s very simple, but I’ve seen individuals do it in ways that are really over complicated. My example will show how to measure from -24v to 24v using a 10bit Analog Digital Converter (ADC) with an analog reference of 5v. The micro controller for this example will be an Arduino since it’s easy to get up and running. If you are having issues with selecting resistor values for your situation, leave a comment and I’ll help you out!

Design and deriving the equation:

Vdivide eqn paper

Circuit and deriving the equations.

This is a circuit that’s basically an addition to the simple voltage divider which gives one the ability to measure high voltage ranges using an ADC with limited voltage ranges. I’m going to be using a voltage divider that starts out at half the Vdc, which is 2.5v for the Arduino’s 5V power. From there I’m going to use a higher valued resistor to pull the 2.5v up to nearly 5v at it’s peak positive voltage, and down to 0v for its minimum negative voltage. If you wanted to measure just negative voltages then get rid of Rc (use infinity in the equation).

Equations required with explanation.

For deriving the equation, I just used nodal analysis. As you can see there is no calculus or anything very math intensive, but there are some variables. This isn’t a guide on circuit analysis, but if you need some tutorials on signal analysis look around youtube or try the book – Schaum’s Outline of Basic Circuit Analysis. Just as a warning there are a similar methods of doing nodal/mesh analysis that will get different equations but yield the same final equation.

Note: Vout is the output of the resistive divider, which will be what’s connected to the Arduino’s analog input (ADC). Vout should only go from 0-5v. Vac is the input to the overall circuit which may vary from positive to negative voltages. Vout may be found by using 5*(double)analogRead(pin)/1024.

Usage notes:

This isn’t a volt meter! If you build it and you’re not measuring a voltage, you’ll notice that it reports a few volts although nothing is connected. Connect Vac to Ground and you should get close to zero volts. As you can see the example above is fairly low impedance, but you can use higher resistors.

The two resistors standing up are both 10k. Two 10k resistors in parallel are equivalent to 5k. Red wire running off of picture is Vac and black is ground.

As for problems: the only thing I can think of is if the ADC wasn’t giving off good readings. If you’re measuring something that’s time critical or behaves sinusoidally, don’t put any capacitors on Vout since this will do a phase shift on Vout. If you’re worried about voltage spikes then you could use two  zener diodes facing oppositely. Also remember that in this example the voltage spread is over 24*2 = 48 volts, so with a 10bit ADC that’s 48/1024 ~ .5 volt increments.

Example code and material:

Voltage equations from above (pdf)

Arduino example program (pdf)

I was going to use this for a 3 phase triac driver with simple pwm. I needed a zero volt detector on one phase which would allow me to calculate the other phases and trigger the triacs at the right time. Originally I was going to sample the voltage with the ADC and look for about 2.5v coming to the ADC. I ended up using a simple voltage divider and a comparator which is definitely a better route! Now you can measure negative voltages with your ADC or Arduino!

Standard Deviation and Moving Average

Recently my neighbor paid me to build a key less entry system for his dorm room. I decided to go the economical route and use a button/potentiometer that sits outside the door and an Arduino on the inside that controls a servo connected to the lock. For my room, I thought it would be interesting to use a Ping))) ultrasonic distance sensor instead of the potentiometer and lose the button.

The Ping))) sensor kept taking readings while my hand was moving. In order to fix this I decided use a Moving Average filter, then calculate the Standard Deviation of the values currently included in the M.A. filter. When my hand is still, the Standard Deviation will become very small.

Example code:

M.A._and_S.D.(pdf)- “storeValue(variable);” is how to enter data into the array, then call M.A. and S.D.

Not much of a circuit required! Arduino's regulator also powers Ping))). Servo has it's own 5v regulator... needs capacitors

pingDoorLocker(pdf) – As you can see, this program blew up a little…

Download .pde source code from RapidShare

I tried to make the M.A. and S.D. code very easy to follow. Some things could have been combined in the S.D. and Variance method, but to the beginner what I wrote above is probably easier to understand since it follows the equations. As for the pingDoorLocker – I threw that code together very quickly.

Follow up notes: That was probably the worst way to do this project… I thought of a few ways how to write the program that would chop the code WAY down, but this is an example about using M.A. and S.D.! Pretty bad use of a M.A. filter if you ask me!

His door unlocker.

Since I did put a few hours into building my neighbor’s door opener, here’s an image of it! He didn’t want numbers on the potentiometer dial, so I made the LED flash the number that is currently being entered.

Code for his door opener (pdf) – leave a comment if you want schematics/code on rapid share since pdf loses tabs.

A Beginner’s Guide to the MOSFET

IRFP260N image from Pins are Gate, Drain, Source from left to right.

If you need to switch high current and or high voltage loads with a micro controller you’ll need to use some type of transistor. I’m going to be covering how to use a MOSFET since it’s a better option for high power loads. This guide will be just a brief introduction that will discuss how to drive a MOSFET in a simple manner with the ultimate goal of making it act like an ideal switch. I’m not going to get into any of the topics such as Triode region, Saturation, Threshold Voltage, etc…

Refer to the N or P channel basic wiring schematics and remember the three pins: Gate, Drain, and Source. When I mention something like Gate-Source potential difference, I’m talking about the difference in voltage between the two pins.

Thank you for supplying many of the parts that will be part of this review/guide. I wanted to also mention that all parts performed great!

N channel MOSFET

How to think of a MOSFET:

A MOSFET may be thought of as a variable resistor whose Drain-Source resistance (typically Rds) is a function of the voltage difference on the Gate-Source pins. If there is no potential difference between the Gate-Source, then the Drain-Source resistance is very high and may be thought of as an open switch — so no current may flow through the Drain-Source pins. When there is a large Gate-Source potential difference, the Drain-Source resistance is very low and may be thought of as a closed switch — current may flow through the Drain-Source pins.

P channel MOSFET

N channel – For an N channel MOSFET, the source is connected to ground. If we want to let current flow, we can easily raise the voltage on the gate allowing current to flow. If no current is to flow, the gate pin should be grounded.

P channel – Looking at the P channel MOSFET, the source is connected to the power rail V2. In order to allow current to flow the Gate needs to be pulled to ground. To stop the current flow, the gate needs to be pulled to V2. A potential problem is if V2 is a very high voltage it can be difficult raising the gate to the V2 voltage. Not only that, but the MOSFET has limitations on the Gate-Source potential difference. Also note that logic is inverted for a P type MOSFET!

Drain-Source resistance – Ideally we want Drain-Source resistance to be very high when no current is flowing, and very low when current is flowing. The main issue using MOSFETs with micro controllers is that the MOSFET may need 10-15 Gate-Source potential difference to get near its lowest Drain-Source resistance, but the microcontroller may run on 5v or 3.3v. Some sort of MOSFET driver is required.

IRFP260N gate capacitance

IRFP260N current curves.

Gate-Source Capacitance – There is also a capacitance on the Gate-Source pins which prevents the MOSFET from switching states quickly. In order to quickly change voltage on internal capacitance, the MOSFET driver needs to be high current. It needs to actively charge (source) and discharge (sink) the capacitor too (for N channel)!

MOSFET Drivers:

A  half bridge is capable of doing what was mentioned above! There are many ICs available which can do this. Here’s a list of just a few that I’ve tested. Schematics are also provided!

Fet driver is a Half Bridge

  • MIC4422YN – Max of 18v, 9Amps peak, 2 Amps continuous.
  • MCP1407 – Max of 18v, 6Amps peak, 1.3 Amps continuous.
  • UCC27424  – Can drive two MOSFETs, Max of 15v, 4Amps typical.

All of these drivers performed nearly identically (~20ns rise, ~30ns fall). Note that although these can be used for more than just MOSFET drivers, these chips do not have much heat dissipation capabilities!

MOSFETs I’ve tested:

It was originally part of the plan to get some data about these guys, but I have been very busy with school. The MOSFETs have plenty of graphs inside the datasheets!

P MOSFET body diode causing unintentional current to flow.


MIC4422YN and MCP1407

  • IRFP260N – 200v, 50A, N channel.
  • IRF3703PBF – 30v, 210A, N channel. Misleading ratings! Read my Datasheet Notes at end.
  • RFP30N06LE – 60v, 30A, N channel.
  • FQP27P06– 60V, 27A, P channel.

An Important Reminder – Don’t forget that typically the heat sink on the back of a mosfet is connected to the Drain! If you mount multiple MOSFETs on a heat sink, the MOSFET must be electrically isolated from the heat sink! It’s good practice to isolate regardless in case the heat sink is bolted to a grounding frame.

Body Diode – Mosfets also have an internal diode which may allow current to flow unintentionally (see example).  The body diode will also limit switching speed. This won’t be a concern if you’re operating below 1mhz.

Si component generals

Great cheat sheet, includes MOSFETS. –

Side note about Gate – Source voltage: MOSFET Gates can go above or under the source voltage. So for an N channel mosfet with a source at 0v, a -10v on the gate would allow current to flow. Verify this with your MOSFET’s datasheet!

Schematic Diode – If the load is somewhat inductive, you’ll need to put a diode to discharge the inductor. If you want more detail, look at the International Rectifier pdf at the end. My “Intro to the Boost Converter” also talks about the nature of inductors when quickly switched on/off.

Gate-Source ringing – There are a few methods that I’ve heard of / seen to limit ringing on the gate. Ringing decreases efficiency, and if excessive, can damage the MOSFET. You can use a zener and resistor in series with the zener’s cathode connected to gate, anode connected to source for N channel. P channel will have the zener flipped. Add a resistor to limit current going through the zener, and watch those breakdown voltages! There is also another diode you could look into called the TVS diode.

Datasheet notes – If a part has too good to be true ratings, check the application notes carefully. For example, the IRF3703PBF claims 210 Amps continuous drain current at 25ºC. We don’t have to do any thermal calculations to know 220 Amps is a TON of current for a TO-220 package! A closer look on page 8, note 6 reveals that it can pass a maximum of 75 Amps continuously due to the package thermal limitations. For future advice: IRF is pretty good at giving accurate ratings, but you have to look for things like this. Now in the real world lots of testing reveals if your design is bad, or if you’re working with a dishonest or incompetent supplier with inaccurate/misleading data sheets.

UCC27424, MIC4422YN, MCP1407

Mosfet Example

Arduino Mosfet Example

Without the driver, the Gate takes longer to charge, and it peaks at 5v. Excessive ringing due to no gate ringing suppression.

Great Additional Reading:

International Rectifier MOSFET application note

High speed MOSFET driving guide

Boost Converter Intro with Arduino

Driving some neon lights.

Let’s say that you’re trying to drive a few Nixie clock tubes, or you want to make a strobe light. A variable high voltage DC power supply from 50-200+ volts may be required. Transformers are terrific, but difficult to find the right one and a pain to wind. Why not use a boost converter? They’re easy and don’t necessarily require a guru for basic operation. This guide is meant for the individual who wants to build a simple boost converter, and may need refreshing on the theory. It will also help determine what parts will be required.

Is this guide right for you?

boost equations

Basic inductor and boost converter equations. D is the duty (0 fully off, 1 fully on)

Boost converters typically get less efficient as they increase voltage out/voltage in ratio. If 100+ volts are required from a 12v source, the load will need to be a fairly high impedance. Don’t expect to run a 60watt light bulb from this boost converter! If precision is required, you may want a dedicated boost converter IC which will do the job better. This guide is intended for educational purposes.


I’m going to be using, oh you guessed it — an Arduino for this example! As usual any micro controller will do (3.3v or 5v), but this project requires analog voltage reading. If your favorite micro controller doesn’t have an ADC (Analog to Digital Converter), buy one or you can make your own!


Boost converters work by taking advantage of a fundamental property of inductors: inductors use stored energy to maintain current. The key is that the inductor will vary voltage to maintain whatever current was present before the system (circuit) changed. Once the power supply is removed from a charged inductor, it may be easier to think of the inductor as an electromotive force rather than a passive component. Refer to the images to see it a bit more illustrated. Some of the key inductor equations are also listed.


Basic overview. Original image from Wikipedia.

On state – Current can flow through the closed switch. There is a potential difference across the inductor. The fundamental property of inductors tells us that the inductor resists change in current. Initially the inductor current is near zero when the switch closes, but current will ramp up quickly as the inductor charges till the circuit goes into the Off state.

Off state – Current no longer flows through the switch. The inductor tries to maintain current, and it acts as a current source which means that voltage can sway, in this case it flips polarity due to discharge. The inductor voltage will immediately jump up to the voltage of C3 and maintain original current till the potential energy of the inductor is transferred to the capacitor. As the capacitor charges, the inductor will continue to jump up the the capacitor’s voltage, even if it’s much greater than Vin.

The Circuit:

boost converter circuit

Schematic, C1, C2 are 12V. C3, FET1, and D1 must be rated for high voltage output. Arduino shares ground with this circuit. ~12v means around 12v, that’s not a negative.

The mosfet(FET1), diode (D1), and capacitor (C3) will need to be rated for voltages greater than the peak voltage. The mosfet and diode will need to have a current rating greater than the current peak — see equations. The more capacitance the better, and a ballpark number from the capacitor equation isn’t a bad idea. When it comes to duty, I would suggest not going over a .9 (230 duty for Arduino pwm) duty. If you already have a diode you want to use, then use the diode’s max current as the peak current and solve for the duty. This will be the maximum duty without damaging the diode.

Important: Mosfet Driver for the IRFP260N is required. This mosfet’s Gate-Source pins have a capacitor in parallel (downside on all mosfets). This capacitance is significant and will tend to resonate with the Arduino’s signal. This may damage the Arduino, and will dramatically reduce mosfet efficiency.

boost converter circuit

Boost converter circuit.

Frequency: My Arduino sample code will be using f = 31250 Hz pwm. It seems like any higher frequency results in a less efficient system, and 31250 hz is inaudible. This will also be using phase correct pwm – more on this in section 17.7.4 atmega328 datasheet.

Feedback: There are calculations to estimate the high voltage output, but in reality there are many factors which affect this output. I found that a feedback system works better. This feedback will output 5v when C3 is at 255 volts, and output 3.3v at 168V. If the feedback voltage is too high for the ADC, adjust the voltage divider! Look at the TI pdf at the bottom (pdf pg 9).

Selecting parts:

Here are the key components that may need to be purchased. I suggest buying from Jameco or Digikey if purchasing in the states.:

  1. Capacitor – There will need to be a high voltage capacitor – larger the better. I used a 330uF 200V capacitor that I found in an old computer Power Supply Unit. Laptop PSU (usually), computer PSU, and CRT monitors will have decent sized high voltage capacitors. Find an old CRT monitor to dig into! Check myEasy High Voltageguide to safely discharge a CRT monitor. Buy some capacitors here, or here!
  2. Diode – A regular 1N4007, but it’s not recommended and will probably fail! A Schottky diode or some other ultra fast recovery diode is much better. There are some nice diodes in CRT monitors. I’ve used the RL4Z, 5JUZ47, 5VUZ47, all scavenged from CRT monitors. Buy some here, these should work too.
  3.  N channel mosfet – IRFP260N available here or here, rated for 200v, 49A.
  4. Neon Light. With DC, the ground is what lights up!

    Mosfet Driver – I’ll be using the MIC4422YN. The MCP1407  or the UCC27424P should work too. If using more than 12 volts, watch the voltage requirements of these guys.

  5. Inductor – Buy or make your own inductor. I’ve used a 120uH, 871uH, 1000uH, and a 5000uH inductor with this circuit. All work fine. Larger inductors store more energy in its inductance which requires less current. The main drawback is that Equivalent Series Resistance (ESR) is higher with inductors that have many windings. When buying an inductor, watch the current rating!

Code for Arduino:

Simple code: boost code

PID code (Arduino pid library 1.0.1): boost code PID

Download .pde files from Rapidshare (down) – I’ll eventually put everything up on github. I know those pdfs are very inconvenient

Other Notes:

With boost converters, core saturation can be an issue with some designs. Remember that this design charges up a capacitor to 200V! This is dangerous and could be deadly if misused! The inductor is a current source when it’s discharging. Beginners are unfamiliar with current sources so I avoided explaining it like that.

Here’s an example of a dedicated buck/boost converter IC from sparkfun!

Handy References:

It’s always difficult knowing how in depth to go in the guides. My guide was written to get the nooblet up and on his feet. If this isn’t enough I’d suggest the links below. The TI boost guide really goes into detail.

Adafruit boost guide

Smps overview (pdf)

TI boost guide (slva061.pdf)

nixie clock from Jameco schematic
Daycounter Boost Converter guide

Wicked Laser

My initial response.

Green laser with shades to block green light.

Just received my, “Flashlight Sample” from Hong Kong. I guess it’s better than calling it a high power laser and losing it at customs. I’m certainly satisfied with seeing a clearly visible beam in just about any light condition! No smoke required! Using it to cut electrical tape like butter, and popping balloons never gets dull! Shining this thing on the ceiling literally lights up the whole room! The only downside is that there are warnings NOT to look at the dot without eye protection… how can I resist!?

Green laser DPSS.

The legality of high power handheld laser pointers is somewhat murky and will likely change in the near future. It may be a federal crime to shine a powerful laser at the sky (who could resist doing this) since it may hit an aircraft.

How they work:

This is a Diode Pumped Solid State laser (DPSS). The actual diode inside is an infrared laser, and the light gets changed to a green color by a rather interesting, yet inefficient process. Anyway I don’t want this post to be too long, so head here if you want to learn more! I’ve read that cheap DPSS lasers don’t have the IR filter in order to have a higher power output. This must dramatically increase danger since shades probably don’t block IR too!

similar laser

Picture of a similar laser.

Future use:

I plan on putting this bad boy on a robot that will drive around popping balloons, and target tank cut outs made out of black flash paper. Another possible use is to buy a simple line camera and make a laser distance sensor.

Where to buy:

Sellers include Laser Glow, Dragon Lasers, and Wicked Lasers. I would be curious to see how well some of the laser modules from deal extreme work. Maybe I’ll get this guy!


After a year and some change the laser diode failed. Disappointing since I never went through a set of batteries! That’s a pretty good indication that the laser diode was being driven far beyond its ratings. Be warned when buying from Wicked Lasers!

Easily measuring inductance with Arduino

bidirectional analog to digital - using LM741 as comparator.

So you need to make or measure an inductor, but you don’t have an oscilloscope or signal generator? Measuring inductance with a handful of cheap common parts is certainly possible. I’ve verified this method is accurate with a scope from 80uH to 30,000uH, but it should work for inductors a bit smaller or much larger. There are some contingencies to keep in mind when it comes to measuring inductors — more on this in “Other Notes:

There are three components that you’ll probably have to buy, but they can be picked up at your local Radio$hack: LM399 and two 1uF non polar capacitors – look at the schematic. If you don’t want to shop at radio$hack, there is a list of products at the end that should work.

No Arduino?

There is 1 digital output and 1 digital input, so this will work with most micro controllers. The output works better with a high current and uses ~33mA at 5V. The only thing left is to measure the rising edge to falling edge time on a square wave. You may want to look at the code if you’re unsure about how to enter the equations, you too can measure inductance with a microcontroller!

LM741, LM339 comparison and a picture showing bell like behavior.

A short lesson on the theory:

An inductor in parallel with a capacitor is called an LC circuit, and it will electronically ring like a bell. Well regardless of the frequency or how hard a bell is struck, it will ring at it’s resonating frequency. We will electronically strike the LC bell, wait a bit to let things resonate, then take a measurement. There is some internal resistance so this is really an RLC circuit, and I’ll talk about this more in the math.

Now micro controllers are terrible at analyzing analog signals. The ATMEGA328 ADC is capable of sampling analog signals at 9600hz or .1ms, which is fast but no where near what this project requires. Let’s go ahead and use a chip specially designed for turning real world signals into basic digital signals: The LM339 comparator which switches faster than a normal LM741 op amp, but there will be a schematic for the LM741 too.

As soon as the voltage on the LC circuit becomes positive, the LM339 will be floating, which can be pulled high with a pull up resistor. When the voltage on the LC circuit becomes negative, the LM339 will pull its output to ground. I’ve noticed that the LM339 has a high capacitance on it’s output, which is why I used a low resistance pull up.


LC equations

Since our wave is a true sinusoidal wave, it spends equal time above zero volts and below zero volts. This means that the comparator will turn it into a square wave with a duty of 50%, and pulseIn(pin, HIGH, 5000); will measure the time in microseconds elapsed from rising edge to falling edge. This measurement can then be doubled to get the period and the inverse of the period is the frequency. Since the circuit is resonating, this frequency is the resonating frequency.

To the left are the equations where f is the resonating frequency, c is capacitance, and L is inductance. Solving for inductance will result in the last equation

Since this is an RLC circuit due to internal resistance, it won’t change any characteristics of the resonating frequency. The RLC will still resonate, but the amplitude will die out. With a low resistance the RLC will tend to latch onto the exact resonating frequency quicker. For you EE’s think of the frequency response of an RLC with low resistance versus high resistance.

Parts that should work:

review the circuit before buying anything. All resistors are 1/4 watt, but anything will work.


Using LM339 (works better at high frequency)

The Circuit:

Pick whichever circuit is better for you, but the one using the LM339 is better. Both the capacitors are 1uf metalized film, but anything that is non polar will work. It will need to be very close to 2 uF though. You can not use a capacitor that marks which connection is ground. One thing you may notice is that the LM741 is geared for analog computing. This means that it requires a negative voltage on it’s V- pin. If you don’t have a power supply that offers this, use two AA batteries to go 3v below ground as shown. The LM339 doesn’t need this and there is no problem inputting a negative voltage. Remember that the LC circuit will vary above and below ground. Here’s a picture of the breadboard.

Using the common LM741 op amp. D2 is a 1N4001 too.


Code for Arduino – With large inductors, you may need to increase the timeout on pulseIn() from 5000 to 10000. If you’re having issues with very small inductors – under 200uH – increase the delayMicroseconds() right before pulseIn() to a larger value ~500uS.

Other Notes:

Not accurate enough? If you look at the equation and you’ll see that the capacitor’s tolerance is key. Expect your results to be accurate within ~10% with a 10% tolerance capacitor. What does this mean? Let’s say you’re using a 10% tolerance capacitor, and the Arduino spits out that the inductor is 1000uH. Well this means that the inductor is in between 900uH and 1100uH. Think of a bell curve if you’ve taken a statistics class – most capacitors with 10% tolerance will be under 10%. (pdf)

If you require a very accurate measurement for a system running at a very high frequency, then this method is definitely not for you due to parasitic capacitance, which isn’t taken into account. This method uses low current to measure inductance, so saturation characteristics will be unavailable (measurements will be taken in an unsaturated state.) This won’t be an issue for most people.

There is this wonderful thing called permeability. Filling an inductor with certain materials changes the inductance without changing the coils. This is similar to mutual inductance in transformers. Ever notice how high frequency transformers are made with nearly non conductive ferrite, and 60hz transformers are made with an iron/steel?

Another method that doesn't work well with Arduino.

You could make a metal detector. Inductors that don’t have closed fields — not magnetically isolated — will change their inductance when something with a different permeability than air is near.

If you have access to fast sampling rates, you can use the method on the right too, but it will require a p type mosfet to really pump some current into the inductor and R1 less than an ohm or so, but greater than the equivalent series resistance of the inductor. This method will probably run into saturation issues if the sample isn’t taken quickly, but if you’re smart about it you should be able to get information about the saturation characteristics.

And there you have it! This is the most difficult part to build on a diy LCR meter.