Help me design and track my twitchy leg while I sleep.


I’m planning a project on a “grand scale” and I need some help.

I’ve got a periodic limb movement disorder where my leg twitches about while I sleep (fine while I’m awake) this interferes with the quality of sleep that I get.

Here’s a little animated gif of me kicking a goal in the world cup this year. :smiley:

I’m planning on using some accelerometers to track my leg movements so I can quantify the movements, then I’ll try to incorporate adjustments in lifestyle, diet etc to see if anything helps.

My plan is to use one accelerometer on my foot and one around my waist to track position. (I’ll need to know when I change positions to omit that movement data.)

I’m still trying to get my head around Arduino, I’ve completed a temperature logger logging to a SD card. I see a very similar system being used with the accelerometer data being written to a SD card.

I was thinking the accelerometers are connected to the Arduino via a length of wire, the foot one mounted on a sock or something of the like and the one around my waist something like a heart rate monitor.

So I have a few questions if anyone would like to help me, and please chime in with any ideas that I might not have thought of.

  1. Connecting the accelerometers via a length of wire (1 to 2 meters) would there be any issue with connecting this way ie voltage drop across the wire etc?

  2. Any ideas how could I protect the accelerometers, it must be light weight. I was thinking heat shrink or tape - even epoxy?

I have a Arduino Uno.

Thanks in advance.

The length of the wires can be a problem for the digital I2C or SPI bus. Voltage drop is not a problem.

Analog acceleration sensors can have longer wires, but I2C sensors are cheaper.
For I2C, the SDA and SCL should be far away from eacht other, so use a cable with thicker insulation between them.

I would connect the wires and use some hot melt glue to prevent them to break. Then heat shrink around it. If they break, who cares if the MPU-6050 modules is only 3 dollars on Ebay. You can break one every week.

I don't like the wires. What if you get up, half asleep, the wire around your leg, the Uno flying through the bed room, you stumble over it, and break.. you know... a leg ?
At least use some release for the wires, perhaps on both sides of the wires. You can use those black headers that are on the Uno and a row of pins. I cut those black header to length, solder wires to a row of pins and wrap construction glue around the soldering. I do that for years, works perfect.

You must power the Uno with a battery pack. Never have a path from the mains to your body when you are sleeping. Never. Even when you have good quality things, a lightning can strike the mains and go anywhere it wants to.

Maybe some kind of EMG sensor might be an alternative - - particularly, an Acceleromyograph sensor - - quoting from that last link:

Acceleromyographs measure muscle activity using a miniature piezoelectric transducer that is attached to the stimulated muscle. A voltage is created when the muscle accelerates and that acceleration is proportion to force of contraction.

Thanks Peter,

Looks like I have some homework to do - no idea what “I2C, the SDA and SCL should be far away from each other” is just yet.
What would be the problem with the long wires? Would you recommend a length?

Thanks Roger,

I looked into
It’s expensive and out of the box but I wanted to try and throw myself in the deep end and make something from scratch using the very limited knowledge I have already.

All else fails I might go down this route. (unless I can find some way to plug in and measure the sensors without the expensive shield)

Rather than having sensors on your leg, have you considered putting sensors on the bed at different locations.

The accelerometers in devices like the mpu 6050 or 9150 are ultra sensitive

You can start with an accelerometer, it is cheap. But I like the idea of an EMG sensor a lot.
I also like the idea of rogerClark, you can start by attaching an accelerometer on top of the mattress under you leg. See if you can get useable data out of that. At least it prevents flying Arduino Uno boards through the room.

The I2C bus is a 'bus' with digital signals between the Arduino Uno and a sensor (with I2C interface).
It uses three wires, GND, SDA, SCL. The SDA is some kind of serial data in both directions, and the SCL is some kind of clock. The clock is often 100kHz, but it is not a real clock. There are a number of signals between the Arduino Uno and a sensor that involve both the data and the clock in both directions.

The library for Arduino for I2C is called the "Wire" library.

You can read about I2C on Wikipedia and the reference of the Wire library. It is not that hard.

The problem is that when a pulse on the SCL or SDA crosses over to the other one and causes a short glitch, the I2C is no longer working. So you should not have SCL and SDA close to each other in a cable.

Thanks for confirming that, the ideal is not having anything external. I've just found this:
But I don't think it has the capability to log the data.

Otherwise I just might fork out for the sensors, they are still wired.

I've done sleep studies before so I'm ok with sleeping with wires.


Adafruit is the best place for wearable electronics, but I don't know if there is a wearable Arduino with a SD card socket.

Use that logging shield and connect a sensor and start collecting some data.
You can always make it better with wireless, smaller, more sensors, battery powered, and so on.

And other option is to use a (night vision) camera and a laptop. There is open source image processing software. I forgot the name: Open...something.

I read about the Jawbone UP3, recordings data for a week.