How does a closed loop artificial pancreas work when you DIY? Or: #DIYPS closed loop is working!

We closed the loop with #DIYPS and now have a DIY closed loop artificial pancreas running right now (for me, aka n=1.)

Here’s what a closed loop #DIYPS artificial pancreas looks like:


(A raspberry pi powered with a battery (shown) or via an outlet; a Carelink USB plugged into the Pi and in close proximity to the pump; a Medtronic insulin pump (an older version, thanks to a family from CGM in the Cloud for sharing it!); and of course my CGM and Android uploader phone that’s sending my data into the cloud/#DIYPS)

Here’s how a closed loop artificial pancreas or “#DIYPS closed loop” works:

Over the past year, we’ve been using #DIYPS to process BG, insulin on board and carbohydrate decay in real time. This yields real-time predictive alerts of three kinds: more insulin needed (X.X units of bolus insulin); less insulin needed (temp basal to zero insulin for X minutes); or carbs needed. Using this algorithm and my data entered (insulin taken or reduced; carbs ingested); we’ve seen significant results not only for the first 100 days, but also sustained over an entire year for improved average glucose, improved a1c, and improved time in range.

Closing the loop with #DIYPS

Three weeks ago, we mentioned at D-Data Exchange 2014 that we were planning to close the loop with #DIYPS…by August 1 (our wedding date :)).

The FDA was even in the room.

Two weeks later…we closed the loop.

It was this simple:

  • Thanks to Ben West’s awesome work, we plugged the Carelink USB into the Raspberry Pi. Thanks to a generous family from the CGM in the Cloud Facebook group, we acquired an old 522 insulin pump that could talk to the Carelink USB. (My current pump is too modern to work with this setup.)
  • Once we established that the Pi/USB setup could read from the pump, we started connecting #DIYPS to the system to close the loop.
  • Normally, #DIYPS provides 3 types of recommendations (see above). We reconfigured it so that while “looping”, it only enables the pump to do temporary basal rates instead of boluses. If #DIYPS says I need more insulin, it tells the pump to begin a temporary basal rate for 30 minutes above my normal basal rate. If #DIYPS says I need less insulin, it tells the pump to begin a temporary basal rate lower than my normal basal rate for 30 minutes, effectively reducing my net insulin.
  • When something changes and I need to do more or less insulin, #DIYPS tells the pump to increase or decrease the temporary basal rate, or resume my normal basal rate.
  • Note: there is a maximum basal rate that the pump can provide. This is a safety check so that #DIYPS cannot recommend a seriously dangerous basal rate. In fact, if I need more insulin than #DIYPS closed loop can safely provide using a 30 minute temp basal, the system will alarm and alert me to that state (although I usually already know about it). Same for if I was dropping fast and needed carbs in addition to reducing insulin; it would alarm and recommend carbs above and beyond reducing insulin.

I’ve been ‘looping’ (using #DIYPS closed loop) for a little over a week. Here are some of my overnight results:

As you can see, the outcomes are awesome. In fact, they are better than I expected!

#DIYPS closed loop results are significant

Here’s a break down that shows on an example night (Sunday night, 12/14 through Monday morning, 12/15) of how #DIYPS performed:

You can see that around 10:30 (not pictured, but in the graph), I was running low and needed some temp basals to zero, then later some higher temp basals to accommodate the resulting rise in BG. Later, my normal basal rates sufficed until another point overnight when I needed less insulin to prevent a low.

While this is 1/9 or so example nights, this is pretty much how it works every night. BGs drift up? Temp basal higher (usually 1.6 or 1.8, which is <=.5u above my normal). BGs drifting low? Temp basal lower or in extreme cases to zero to prevent a low.

What happens if the closed loop artificial pancreas fails/stops working?

If the loop stops working*, #DIYPS continues to work normally (processing all data and pushing recommendations), and my pump goes back to my normal basal profiles after any existing temp basal rates expire (which would be a max of 30 minutes). No big deal and no more dangerous than I would be walking around with my pump acting normally.

*I’ve found numerous ways to make the system stop working: no battery power; being too far away from the USB stick so the pump can’t communicate; no cell signal to provide wifi as a hotspot to the Raspberry Pi; if the pump battery goes low, RF gets turned off and the USB can’t talk to the pump; if there’s no cell signal or wifi at all, I can’t upload CGM data to #DIYPS anyway; if the SD card gets corrupted inside the Raspberry Pi; etc.

So, there’s many points of failure. But it doesn’t matter. #DIYPS closed loop is safer for me (disclaimer: just me! I’m the only one doing this as a personal experiment to my own body) than if I just had a pump and a CGM, because it can reduce insulin and prevent lows. And it can increase insulin slightly and prevent rebounds.

After about a week’s worth of data, here’s the results of #DIYPS (what I’ve been using for the past year) versus the week of closed loop #DIYPS:


The target BG is especially awesome, because we have the closed loop targeting a BG of 115!

It’s also worth noting the reduction in alarms. Remember, I sleep through CGM alarms, so we built #DIYPS. #DIYPS makes a lot of alarms – sometimes upwards of 40 a night (those are really bad nights!). With the closed loop nights, there are very few alarms..and they’re usually alerts about things #DIYPS closed loop is taking care of on it’s own (see all of those no-hitters above!).


What’s next with #DIYPS closed loop

We’re going to continue and iterate on the closed loop and keep making it better. I’m definitely going to keep using it overnight – it’s like having a working pancreas, the kind where you can go to sleep without fear.

We’re also adding this to the ‘things we’ve learned while working on #DIYPS’ list:

  • Calculating the carbohydrate absorption rate for an individual – how many carbohydrates your body absorbs in an hour
  • Tracking “carbs on board” or “carb decay” – how many carbohydrates are still being digested in your body and impact BG levels
  • “Net” IOB – tracking net IOB by incorporating “negative” boluses from temporary basal rates to zero
  • Preventing post-meal BG spikes/drops with early meal boluses and better understanding of insulin activity
  • and you can control overnight BGs solely using simple adjustments of insulin rates.

Thanks to everyone who made it through a really long post, and for the MANY people who have contributed in various ways to helping us close the loop with #DIYPS! Also, let us know what questions come to mind that we haven’t managed to answer above about how the system works, results, etc.

32 thoughts on “How does a closed loop artificial pancreas work when you DIY? Or: #DIYPS closed loop is working!

    1. Thanks, Ben! Big thanks to you and the many others who’s shoulders we’re standing on..you, John, Ken Stack, Gustavo, Stephen, etc.!

  1. Congratulations, this is a huge step for n=1+x. I merged iob-cob a week ago and my numbers are running significantly lower than I have ever achieved before. So much much of my ratios were proved wrong in the first 3 tests I ran. I needed the data/tools to figure it out. Thank you.

  2. I am floored by both your bravery and ingenuity in putting this system to real life practice and obtaining such positive results. A friend shared the link to your post with me this morning and reading this absolutely made my day. Thank you for your honorable work.

  3. I recently found out about #wearenotwaiting and have spent the last week reading everything I can about all the amazing work that’s been going on. You guys are truly amazing!! I still struggle to understand why there has been so little progress in the world of diabetes tech, anyways rather than ranting about that for an eternity I just wanted to congratulate you on what you’re doing. You’ve given me some much needed hope in a diabetic world that has otherwise always seemed illogically against me!

    Are you planning on sharing any info on how others could make a closed loop system, I for one would be mare than happy to self test this?

    1. Thanks, Matt! (Don’t worry, we still rant on occasion, too ;)). Glad to help share some hope!

      Yes, there are a few others (mostly abroad at this point) also working on other DIY versions of these types of system, and we’re all sharing knowledge broadly about what we’re doing and what’s working/not. Can you jump over and ping me on Twitter (@DanaMLewis) and/or to the Nightscout channel on Gitter, and I can introduce you?

    1. Thanks, Tim! You might be interested in checking out OpenAPS.org – we’re encouraging people to start working on their own n=1 implementations using the #OpenAPS reference design, see if it’s something you’re interested in!

  4. Hello Dena,

    congratulate – fantastic news !!! I am a Type 1. Diabetic from germany and we follow your testing #DIYPS closed loop here and hope we can make the same way too. We are not waiting – too here in Europe.

    Thanks Dena

  5. This is fantastic! I have been doing as much research as possible on all types of closed-loop systems. I am just about to graduate college with a degree in Human Physiology, and I hope to go on to T1D care in the medical field. I’ve been telling my dad for a while (he’s a software engineer) that the greatest graduation gift would be a do-it-yourself artificial pancreas, or an algorithm at least! Problem is, I have a t:slim pump and dexcom sensor. Do you have any recommendations on where to start my own closed loop DIYPS with my dad?

    1. Emma, awesome! You should check out OpenAPS.org! :) The easiest road to get it working more quickly involves an older Medtronic pump, but there are a few people working to get other pump communication protocols figured out. Sign up on the openaps-dev list if you’re interested, there’s more info in addition to a spreadsheet where people have logged which devices they’re working with in regards to #OpenAPS.

  6. When people are using their own “DIY Artificial Pancreas” (DIYAP) systems are they using Humalog ( or similar ) Insulin? If the drug companies were to develop a rapid on-set, but shorter duration acting time, would this help with DIYAP? I have been a diabetic for nearly 50 years, and have been using my own primitive multi test, multi inject, multi eat system, since home testing became available some 30 odd years ago. I think I am too old to do what some younger diabetics are doing with this DIYAP, but I am fascinated with it. I think the fully commercial systems are taking too long to get regulatory approval. It is only recently that I became aware of these recent developments.

    1. Harry, I’m using Humalog. And yes, faster insulin would be a huge help for artificial pancreases! Part of the challenge with diabetes & current insulin, as you know, is treating current BG #s and trends with insulin that peaks in 60-90 minutes. And by the way, I don’t think anyone is too old to take advantage of new tools and technologies :) but definitely agree commercial systems are taking too long. Hopefully, we won’t have to be #wearenotwaiting for too many more years!

  7. Few questions as I’m about to enter the pumping world after 24+ years of normal injections and just began using cgm ~ week ago.

    ‘things we’ve learned while working on #DIYPS’ list” may I ask how you figured these items out as working a bit with development I’m not one who likes to reinvent the wheel and would one day after I understand the process of doing this manually would like to try to replicate what you’ve done here. That is start with an open loop and eventually close it.

    1. Brandon, congrats on switching to a pump (and CGM)! This is the best background post probably that explains more of our thinking especially as it relates to before and during mealtime and here’s the post where we talk about determining your carbohydrate absorption rate. I think the other key is starting to realize one big difference between injections and pump therapy: with injections, once the insulin is in, it is in and you can’t get it out. With a pump, you’re microdosing constantly (basals) as well as bolusing. You can effectively decrease the microdosing (by suspending or reducing your basal rates with a ‘temporary basal rate’ for 30 min or more), which is great – but you need to be able to track the reduction of insulin compared to what your body is used to. That’s what we started doing with #DIYPS (showing/tracking the *net* IOB), because the pumps only show IOB as a result of bolus insulin given, and totally disregards any changes in basals. So if you even loosely keep in mind that suspending your pump (like if you get in the shower without it) for 30 min will impact your BGs in another 60-90 minutes, it helps you be aware of the impact; even better would be to use #OpenAPS-style tech to automatically calculate your net IOB, so you don’t have to do all the work constantly to track it! If you’re interested, hop over to OpenAPS.org and read more (and more here on #DIYPS about the various pieces we’ve worked on, more so than this one post) plus sign up for the OpenAPS-dev mailing list after you get comfortable with your pumping. Good luck!

  8. I would love to be n*2. I have a dexcom G4 CGM I wear it all of the time. I run 3 versions of Linux at home and feel comfortable at the command line for the raspberry pi. I use a t-slim insulin pump. I was wondering what you use to deliver glucagon (another pump or is there a new solution since the group from Boston did this at a Diabetic camp). I feel like I could help a little with this whole effort. I would love use all of my equipment to close this for myself. Have a super day. Karl R. Steenblik SLC Utah

    1. Hi Karl, we’re not using glucagon. You can learn more in the reference design at OpenAPS.org, plus look through the docs and join the openaps-dev Google group if you’re interested in jumping in! As of Jan. 14, 2016, #OpenAPS is currently (n=1)*25!

    2. Karl, contact me on Facebook if you’re interested in pursuing the closed loop. We’re FCYD camp alums who have closed in Feb.

  9. Hi, This is awesome, and I’d like to build one for my daughter. Problem is, she has a Tandem T Slim pump. No possibility of changing right now. Any advice or anyone else working on an openAPS with the T-Slim?

  10. i have know a little bit about this for about 2 months since my friend who is a diabetic and actually is a network engineer has been working with RPI’s for about a year and stumbled on what he called hacking your pump and tweaking it. So thats the first part of my story. Heres my second part My uncle who was diagnosed at 40 years old with type 2 about 4 years ago was told last month that he was misdiagnosed and actually has type 1 so he is now on a lantis regimen and will probably be on humalog or noavalog soon, he was at a diabetic mixer last night the the University of Utah and heard Dana talking about her closed loop system and a little about hoe she was able to do it. My uncle called me last night and was telling me all this and without knowing all that much about the system I said “well ahe probably used a raspberry” he said ya i think she did. So i started looking it all up on the internet and realized that i have everything to build this as we speak in my basement with the exception of the carelink usb. (sorry to make a long story miserable but my question is do you know anything about if this would work with the built in CGM of the minimed pumps?

Leave a Reply

Your email address will not be published. Required fields are marked *