Help Needed On Creating an Spark App for Artificial Pancreas

@BRT, now we can help! Let’s take the circuit apart see what each part does. First, the 330K and 100K ohm resistors form a voltage divider. The voltage at the junction of the two resistors is calculated as:

Vjunction = 12 * 100,000 / (330,000 + 100,000) = 2.8V

Therefore, one end of the Conductivity Sensor is at 2.8V while the other end goes to a variable resistor AND the gate of the MOSFET. The 2.8V is important because it limits the maximum voltage to the gate of the MOSFET, preventing damage.

Now, we know that the pH of a solution will affect the conductivity of that solution. So the current through the Conductivity Sensor will be affected by the pH of the solution in which it is immersed. The current which will flow through the sensor will go through the potentiometer, or resistor, to the negative side of the battery. We know from ohm’s law that a current through a resistor creates a voltage across that resistor. That voltage is present at the gate (G) of the MOSFET. When the voltage is high enough, it will switch the MOSFET “on” and current will from from its Drain (D) to its Source (S), turning on the pump. By adjusting the potentiometer, the conductivity/pH threshold for turning on pump can be set.

LESSON 1 COMPLETE :smile:

3 Likes

Answers to @Moors7 questions:

  1. Yes, I have someone who has a little experience with Arduino
  2. Yes, I have a person I know who can code and can help me understand how this works.
  3. Yes, the Internet
  4. Yes, I have provided one.
  5. What do you mean by " transmitting". There are so many things that can be transmitted. I will work on the other questions.

@BRT, time for LESSON 2. Instead of having the MOSFET connected to the conductivity sensor, it will now be connected to an ANALOG input of the Spark Core (or an Arduino UNO). An analog input can read voltage and convert them to digital values. In the case of the Spark Core, the maximum voltage at the input cannot exceed 3.3V and since the voltage divider gives us 2.8V, then there is no danger of damaging the Core.

The Core’s Analog-to-Digital Converter (ADC) which converts the analog input into a digital value has a 12-bit range. What that means is the digital value will be zero for zero volts in and 2 to the power of 12 minus one or 4095 when 3.3V is on the input.

The only part missing is controlling the MOSFET. This can be done by connecting a DIGITAL output from the Core to the MOSFET’s Gate (G) to turn it ON or OFF.

You are now ready to write some code for the Spark in the C++ language, which is what you see in the web IDE. The code would, in a loop:

  1. Read the analog input pin which is connected to the Conductivity Sensor.
  2. IF the voltage (represented by a value between 0 and 4095) is above a certain pre-determined level, then the pH of the solution is high so turn ON the pump by writing a HIGH to the digital output pin connected to the MOSFET
  3. ELSE, turn OFF the pump by writing a LOW to the digital output pin connected to the MOSFET

So now you are turning ON and OFF the pump using the Core by reading the voltage produced by the Conductivity Sensor to decide how to control the pump. It should not be difficult for you to see that it would then be easy to know when the pump is ON and count the amount of time it remain on. Furthermore, since you have both the Conductivity Sensor values and the pump status (ON or OFF), you could send that data to a Google Spreadsheet or other data collection site for logging and plotting. That is another lesson. :smile:

2 Likes

Well, that’s at least somewhat positive.

1/2 -Please to ask those persons for help! Your friend’s dad, who can handle JavaScript will most likely be able to help you with the other code as well, so do ask that.

3 - I’m currently taking lessons on a university for these topics, so saying that the internet will suffice is a bit optimistic perhaps. If you can find everything you need, I’m not going to judge though. If however, you can find someone with real-life experience who can help you, then you should definitely prefer that over the internet. Just a tip.

4 - Hopefully you can also understand what’s going on in that schematic. The information @peekay123 provided is very useful in that regard, and so are the explanations on the page you got the schematic from. Please read them carefully, and let us know if anything is unclear.

5 - Transmitting the data from the Core to your receiver. That was more of an example though. What’s important is that you can divide the project into meaningful stand-alone parts. You’re not going to be able to do it all at once, but if you chop it up, it get’s easier.

Your measurement device (Core) doesn’t need to know how the circuit works to be able to measure it. It just measures a voltage. If you know where to measure that voltage, and tell the Core what to do with it, it’s perfectly happy.

It also doesn’t need to know what happens with the measured data once it’s been parsed and transmitted. That’s no longer its concern. Much like that, the receiving end doesn’t care where the data comes from. As long as you tell it what to do with the data it’s getting, it’ll be perfectly happy.

You can already make out some individual parts in here, that work independently of each other. Try to make a diagram of this from first measurement, up to a graph. This is also good for your presentation, since it shows you understand what’s happening.

@Moors7 Thanks for the help !!!!!!!!!!!!!!!

But can you elaborate a little on this part? I am in a perplexed state because this doesn't make sense.

Also, can I make the Google Spreadsheets show data before the application was made? In other words, can I input previous timings of pumping activity?

This topic is now closed. New replies are no longer allowed. Given the recent number of reported posts in this topic I have decided to temporarily close this topic pending review. Review should last no longer than 24 hours. If you would like to voice opinions on this topic or its review please send me a PM.

3 Likes

After review, and a bit of pruning, I have decided to open this topic back up to replies. I would like to remind everyone, including new comers, to remain as civil as possible. The search tool is your friend and really try to do your research before posting. One line posts like “thanks” or “how do I do x?” are not really appropriate. A thanks can be replaced by a like of the post and your question about doing x should also include the work you’ve done to try to do x yourself.

I want to thank everyone who has replied in this thread. I may have removed some of your posts. Most of them were removed in my attempt to remove off-topic or ultimately fruitless conversation paths. The current state of this thread represents my attempt to streamline the conversation so that the original poster, his team, and those that come after can get the most help possible.

5 Likes

The project you like to do consists of several, stand-alone smaller parts. You can look at them as a sort of 'magic boxes' where you input one thing, and out comes another. The box in question doesn't care where its input came from, as long as it's compatible.
The pancreas, for example, doesn't care where you stick the conductivity sensor in. It doesn't know whether it's orange juice, of concentrated chloric acid. It also doesn't care. The only thing it does is take an input of one type, and convert it to an output (of another type). Your input is a resistance, and your output is a voltage.
The Core also couldn't care less where its input came from. It just needs a voltage to measure. If you hook it up to a battery instead of the pancreas, it's just as happy. It doesn't know, and doesn't care. It takes a voltage as input, and then you can tell it what to do with it, and it'll give you that output, assuming no errors where made.
Google docs also doesn't care where it gets its data from. It just needs some data to work with. Whether it gets that automatically with a script, you input it manually, or you send it smoke signals, it doesn't care. It just needs a valid input. You can then tell it what to do with that data, and it'll give you the output.

The point is that these three things work independently. You don't need the others to get one working. If you can make them work individually, and make sure the output of one is compatible with the input of the next, you should be able to just 'link' them together. If you make sure the pancreas outputs a voltage compatible with the input of the Core, then the Core will be able to deal with it appropriately. Much like if you make sure the output of the Core is compatible with the input of Google, then it should work without much problems.

To get a better overview of what components produce/require things, you could put them in a flow chart. This'll give you a better idea of what's going on, and what needs to be done. Going against my principles of "I'm not going to do your work", I decided to make an example as to prevent that I have to explain this again. I did watermark it because you should really make your own version, and well, because I'm not going to make your work :wink:

Could you, using the above schematic, use simple keywords to tell what the whole is doing?
Following the above schematic, which things would need to be edited in order to get as close to a live representation as possible?


I've never really used it a lot, but it's essentially an online version of excel. So yes, you could manually input values. I suggest you just actually open Google spreadsheets, and just try some things out. If you can't figure out how that works, there's always Google to help you out. This forum isn't really the place to answer questions about Google stuff.


Have you already gotten a Spark to work with? It's hard to explain things, if you can't try them out. There's no use of us sharing code if you've got nothing to try it with. If you haven't already, I'd suggest you order one a soon as possible, since it'll also take some time to get to you. If you want to start immediately, you'll need to order the Core, and not the Photon, since those will take some more time.


Now that you've gotten all this information, what do YOU think should be the next step for you to take?

2 Likes

@Moors7

I have a very important question:

So if you connect the Spark Core with the Usb to the computer, will it immidiately start blinking blue?**
Also since you have experience with the Spark Core, how long does it take to ship. I ordered it on Saturday, when do you expect it to come?
Sorry, if I am rushing you, but good news:
I got the Spark Core coded and connected it to Google, all by myself and when the Spark Core comes I can connect the Core to the code!!

Thanks for the help, right now I am just waiting for the Core.

@Moors7
@Moors7
@Moors7

1 Like

So if you connect the Spark Core with the Usb to the computer, will it immidiately start blinking blue?

did you check this? spark docs / getting started ?
There is a section "The RGB LED could show the following states" which may help you.

3 Likes

I would like to personally thank @Moors7 and @peekay123 for their help. Do not post on this topic anymore. If you would like to reply then send a pm.

Thanks to the Spark Community, this is @benclough signing off :blush:

1 Like