Inspiration

Falling asleep is hard, and waking up is even harder. We've learned the hard way as students that getting a good night's sleep is vitally important to staying healthy and well.

There are already many solutions for falling sleep better, such as medication like melatonin or sleeping aids, meditation/mindfulness techniques, ASMR/relaxing music, aromatherapy, etc. There are also already many solutions for waking up better, like nice soothing alarm clocks that sync with your sleep schedule, loud annoying alarm clocks, and caffeine. But so far, to our knowledge there is no sleep solution that harnesses the all-natural power of electricity, both to help you fall asleep and wake up!

(TENS units are cool and we wanted to build one and experiment with it. TENS stands for Transcutaneous Electrical Nerve Stimulation, essentially high voltage low current pulses delivered to the human body via skin contact).

What it does

A react app allows users to set their desired wake up time. When they select the go to sleep option, the wearable hardware unit will deliver relaxing high-frequency electric pulses to the wearer's upper back. Within ten minutes or when the user's heart rate / heart rate variability fall to a sleep level, those electric pulses will stop. At the wake up time, a low frequency pulse will jolt the user's arm/fingers into movement, such that the user slaps themselves awake.

How we built it

High frequency signals at sent to the human body at high voltage and low current can create a sort of relaxing sensation (and at higher voltages... a painful sensation). Low frequency signals sent to superficial muscle groups at higher voltage can make them visibly tense up, i.e. make parts of the body move.

System architecture diagram

The react web app connects to the Firebase Realtime database to set a wakeup time and a go to sleep trigger. Listener functions on the Raspberry Pi look at these variables and activate PWM signals accordingly. We do data analysis on the input ECG data to determine when sleep occurs and turn off the high frequency relaxation signals (or after they have been on for 10min, whichever happens first).

We use a boost converter to increase the voltage from our power supply to upwards of 15V, while limiting the current to a safe level (<15mA). For added safety, we use optocouplers to protect the low voltage electronics (Raspberry Pi) from potential issues on the high voltage side. They have the added benefit of limiting current to 50mA, in case the boost converter stops limiting current as it claims to. And for extra safety, because safety first, we put an LED in series with the electrode as a janky fuse, so that if more than ~20mA attempt to flow through the body, the LED will blow up and we will stay alive. This proved to be a very good idea!

The ECG is just an AD8232 chip that we connect to an analog to digital converter shield from Grove. It works great most of the time but is a bit sensitive to noise.

Challenges we ran into

The first boost converter we tried didn't work as expected - we couldn't get it to deliver less than 7 amps, which is extremely lethal. We spent four hours troubleshooting it and still couldn't get it to work, so we tried building our own... that did work at low voltages, since we only had components for low voltages.

We had to extensively test our setup before we could connect it to our bodies, so we came up with some interesting improvised solutions. Notably, we use an LED to "limit" the current going through the electrodes to 20mA. However, we had one seemingly regular 5mm LED that was truly immortal - all the others would get fried at 15V and >6A but this one just... worked?!

We tried putting the breadboard circuit onto a soldered perfboard to clean things up and have a more wearable/portable formfactor. The circuit seemed to work. Then we added the analog to digital converter for the heart rate monitor and the whole things stopped working and our Raspberry Pi Zero fried. We had to go back to a breadboard setup.

We tried training machine learning models on the heart rate data to determine sleep phases, with pretty good success, but in the end we weren't able to get that quite connected to the rest of the system so we left it out of the project.

Accomplishments that we're proud of

  • Not killing ourselves!
  • It worked end-to-end

What we learned

This was our first time working with a TENS unit, boost converters, and Google Cloud Realtime Database. We learned not to trust perfboards.

What's next for Melavoltin

  • Finish implementing sleep phase detection
  • Improve reliability and form factor
  • Fix bugs

Built With

Share this project:

Updates