Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Ask questions about projects relating to: aerodynamics or hydrodynamics, astronomy, chemistry, electricity, electronics, physics, or engineering

Moderators: kgudger, bfinio, MadelineB, Moderators

shazzzzzz
Posts: 6
Joined: Sun Dec 03, 2023 8:10 pm
Occupation: Student

Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by shazzzzzz »

Hi! I have picked developing an artificial pancreas for my science fair project, but have run into some issues. After I connect the pump to the 5V and GND on my Ardino, the pump works. However in the next step, when I connect the pump to the middle pin on the MOSFET, nothing happens. I have rebuilt the whole thing again, and have tried everything to fix this problem. How do I get the pump to work so that I am able to get the code to work as well?
Thank you!
bfinio
Expert
Posts: 734
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by bfinio »

Hi - to clarify, the pump will not run if it is just connected to the MOSFET without the code running. The pump's behavior is controlled by the code and depends on the sensor input. You need to follow all the other steps in the procedure to get the pump to run. Can you clarify exactly which numbered step of the procedure you are referring to with "the next step"?
aliyahhhhhhhrrrrrr
Posts: 6
Joined: Mon Dec 04, 2023 10:40 am
Occupation: Student

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by aliyahhhhhhhrrrrrr »

Thank you for your response. This is the same person just from a different account. How do I get the code to run? I put the number in the "threshold value" but the pump still didn't work. The next step I am referring to is Step 12
bfinio
Expert
Posts: 734
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by bfinio »

Hi - backing up a bit, is this the first time you have used an Arduino? We recommend going through at least the first three tutorials on our How to Use an Arduino page before starting this project: https://www.sciencebuddies.org/science- ... an-arduino. That way you will be familiar with the process of uploading code for a very simple circuit before you move on to more complex circuits. So, I'll try to answer your questions for now, but if you haven't done those tutorials, I strongly recommend taking a break from this project procedure to do those first.

In step 12, you should have already uploaded the example code from step 11 (in which you set the threshold value) to your Arduino and you should have the serial monitor open. What do you see displayed on the serial monitor? What value did you set for the threshold value?
shazzzzzz
Posts: 6
Joined: Sun Dec 03, 2023 8:10 pm
Occupation: Student

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by shazzzzzz »

This is my code
- /*
* Artificial Pancreas model code
*
*/

int pumpPin = 11; // pin used to control pump
int pumpSpeed = 255; // pump speed, value between 0-255
int conductivity; // conductivity value, this will be 0-1023 from analogRead
int threshold = 923; // conductivity threshold at which pump should turn off

void setup() {
// put your setup code here, to run once:
pinMode(pumpPin,OUTPUT); // set pump pin as output
Serial.begin(9600); // initialize serial communication

}

void loop() {
// put your main code here, to run repeatedly:
conductivity = analogRead(A0); // get conductivity reading
Serial.println(conductivity);
if(conductivity>threshold){
analogWrite(pumpPin,pumpSpeed); // turn pump on if threshold has not been reached yet
}
else{
digitalWrite(pumpPin,LOW); // turn pump off if threshold has been reached
}

}

And my serial monitor is saying - Message(Enter to send a message on 'Arduino Uno' on 'COM3')
bfinio
Expert
Posts: 734
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by bfinio »

Are you selecting Tools --> Serial monitor to open the serial monitor? You should see a series of numbers printing out and the numbers should be in the range of 0-1023. When that number drops below the threshold (which you have set to 923 in your code), the pump will turn off. If the sensor reading starts out below 923 then the pump will never turn on to begin with. Make sure you see the numbers printing out in the serial monitor.
aliyahhhhhhhrrrrrr
Posts: 6
Joined: Mon Dec 04, 2023 10:40 am
Occupation: Student

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by aliyahhhhhhhrrrrrr »

My issue is that when I do Step Number 12, my pump never starts.
shazzzzzz
Posts: 6
Joined: Sun Dec 03, 2023 8:10 pm
Occupation: Student

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by shazzzzzz »

Ok I got the pump to work by moving the mosfet and the wires around it a few rows down. Now I can't get the code to work.
shazzzzzz
Posts: 6
Joined: Sun Dec 03, 2023 8:10 pm
Occupation: Student

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by shazzzzzz »

My code does not show any numbers when I connect the pump.
Is there any video I can watch on how to get the code to work?
I have the serial monitor open and the line under it says:
Message(Enter to send message to 'Arduino Uno' on 'COM3')
It also says New Line and 9600 Baud on the left.
bfinio
Expert
Posts: 734
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by bfinio »

This video at around the 4:00 mark shows what you should see in the serial monitor:

https://youtu.be/Wa8CjGsOFzY?si=NQxxJClPCSX57Ni6

It does say "Enter to send message to Arduino Uno" with the New Line and 9600 Baud drop-down menus, but below that is the text area where it should print out readings from the sensor. This video is about using a potentiometer, but the code using the analogRead command is pretty much the same. I would recommend watching the entire video.

Can you upload a screenshot of what your serial monitor looks like while the code is running? If you have trouble uploading a screenshot to the forum you can email it to scibuddy@sciencebuddies.org. It would also help if you could send us some pictures of your breadboard so we can take a look at your circuit. If things changed when you moved parts around on the breadboard then something might be wired wrong. Please make sure the pictures are clear, well-lit, and in focus, with a top-down view so we can see connections on the breadboard. You may need to take multiple photos from slightly different angles so we can see all the connections. Sometimes tall parts like the MOSFET can block the view.
bfinio
Expert
Posts: 734
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by bfinio »

(please read my previous post, I hit submit on that before I remembered to type this part).

Another change you can make is to comment out the if/else statement in the loop function in your code, and just put a single analogWrite(pumpPin,255); command outside if the if/else statement. Assuming everything is wired correctly, this *should* just make the pump run full speed all the time regardless of the sensor reading. Once you have confirmed that the MOSFET and pump are wired correctly, then you can move on to debugging the sensor. So, in addition to sending the pictures requested in the previous comment, please try running this code and let us know what happens:

/*
* Artificial Pancreas model code
*
*/

int pumpPin = 11; // pin used to control pump
int pumpSpeed = 255; // pump speed, value between 0-255
int conductivity; // conductivity value, this will be 0-1023 from analogRead
int threshold = 923; // conductivity threshold at which pump should turn off

void setup() {
// put your setup code here, to run once:
pinMode(pumpPin,OUTPUT); // set pump pin as output
Serial.begin(9600); // initialize serial communication

}

void loop() {
// put your main code here, to run repeatedly:
conductivity = analogRead(A0); // get conductivity reading
Serial.println(conductivity);

/*if/else statement is commented out - we are ignoring the sensor reading
if(conductivity>threshold){
analogWrite(pumpPin,pumpSpeed);
}
else{
digitalWrite(pumpPin,LOW); // turn pump off if threshold has been reached
}
*/

// instead, just turn the pump on full speed all the time
analogWrite(pumpPin,255);

}
shazzzzzz
Posts: 6
Joined: Sun Dec 03, 2023 8:10 pm
Occupation: Student

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by shazzzzzz »

Thank you for your reply. I have sent the photos to the email you provided. Please review and let me know if it looks right. I really appreciate it. I also sent you a video with the original code showing that even when the pump runs the code does not work.

Also - I tried it with the code you sent and and it worked but it never stops. The code just keeps going and going.
bfinio
Expert
Posts: 734
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by bfinio »

Ok - I reviewed your pictures and video. If the pump ran but never stopped when you ran the most recent code I sent, that confirms that your pump and MOSFET are wired correctly - that is how it was supposed to work. The line "analogWrite(pumpPin,255);" is just telling the pump to run full speed all the time, forever. It does not depend on an if/else statement so it will never stop until you unplug the pump or the Arduino. That helps us figure out that the connections to the MOSFET and pump are NOT the problem. Next, we can keep trying to test things one at a time, to figure out what IS causing the problem.

Next I would like to make sure that your serial monitor is working. Please upload the following very simple program to your Arduino (make sure you click the "arrow" button to upload it and not just the "checkmark" button). This should just print "Hello!" out in the serial monitor over and over again. Please let me know if that works.

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello!");
}
shazzzzzz
Posts: 6
Joined: Sun Dec 03, 2023 8:10 pm
Occupation: Student

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by shazzzzzz »

I put the code you sent in and it worked. The serial monitors kept printing "Hello!"
bfinio
Expert
Posts: 734
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help

Post by bfinio »

Ok - then without changing anything in the circuit, can you re-upload your original code and tell me what happens? Are you seeing numbers printed out in the serial monitor? I have pasted your code here again:

- /*
* Artificial Pancreas model code
*
*/

int pumpPin = 11; // pin used to control pump
int pumpSpeed = 255; // pump speed, value between 0-255
int conductivity; // conductivity value, this will be 0-1023 from analogRead
int threshold = 923; // conductivity threshold at which pump should turn off

void setup() {
// put your setup code here, to run once:
pinMode(pumpPin,OUTPUT); // set pump pin as output
Serial.begin(9600); // initialize serial communication

}

void loop() {
// put your main code here, to run repeatedly:
conductivity = analogRead(A0); // get conductivity reading
Serial.println(conductivity);
if(conductivity>threshold){
analogWrite(pumpPin,pumpSpeed); // turn pump on if threshold has not been reached yet
}
else{
digitalWrite(pumpPin,LOW); // turn pump off if threshold has been reached
}

}
Locked

Return to “Grades 9-12: Physical Science”