Page 1 of 1
Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Sun Dec 03, 2023 8:45 pm
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!
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 6:59 am
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"?
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 10:53 am
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
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 10:58 am
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?
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 4:45 pm
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')
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 6:38 pm
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.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 7:03 pm
by aliyahhhhhhhrrrrrr
My issue is that when I do Step Number 12, my pump never starts.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 7:37 pm
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.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Mon Dec 04, 2023 7:52 pm
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.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Tue Dec 05, 2023 7:13 am
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
[email protected]. 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 bleep 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.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Tue Dec 05, 2023 7:19 am
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);
}
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Tue Dec 05, 2023 10:27 am
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.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Tue Dec 05, 2023 10:51 am
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!");
}
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Tue Dec 05, 2023 3:41 pm
by shazzzzzz
I put the code you sent in and it worked. The serial monitors kept printing "Hello!"
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Wed Dec 06, 2023 5:32 am
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
}
}
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Wed Dec 06, 2023 7:37 am
by aliyahhhhhhhrrrrrr
When I put the original code, I only see random numbers come up. Its usually just random numbers that start with the digit 3. The numbers never reach the threshold. I can send you a picture of what I see if you need it.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Wed Dec 06, 2023 7:57 am
by bfinio
Ok - we've established that your pump is wired properly and the serial monitor is working. If you are seeing "random" numbers then that indicates that bleep may be wrong with how your sensor is set up. If you are seeing three-digit numbers that start with 3, meaning the values are all in the 300's, and your threshold value is set to 923, then the pump will never turn on, since 300 is less than 923.
How did you arrive at the threshold value of 923? What minimum and maximum values did you get earlier in the procedure during the calibration process for steps 5 and 6? The threshold value you choose should be in between those two values.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Wed Dec 06, 2023 8:02 am
by bfinio
Also, I think we need to clarify an important misconception based on your comment "The numbers never reach the threshold." The sensor reading should start high and go down, not the other way around. Meaning, it should start out ABOVE the threshold value you choose, and then according to the if statement if(conductivity>threshold), the pump will turn on from the command analogWrite(pumpPin,pumpSpeed). Once the sensor reading drops below the threshold, then condition in the if statement is no longer true, so the else part of the if/else statement will execute instead, turning the pump off with the digitalWrite(pumpPin,LOW) command.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Wed Dec 06, 2023 8:10 pm
by aliyahhhhhhhrrrrrr
I had taken the readings of my multimeter again, and got a more accurate reading. My numbers came from between 205 and 1023
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Wed Dec 06, 2023 8:14 pm
by aliyahhhhhhhrrrrrr
The serial moniter is showing numbers that are lower than my threshold, and the pump never stops. My biggest concern is gathering all the data, since my project is due tomorrow
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Thu Dec 07, 2023 7:17 am
by bfinio
Hi,
I did not see your post until this morning, so I am not sure if it will be too late if your project is due today. As a last resort, if you cannot get automatic control working for the pump, you could control the pump manually by watching the value on the serial monitor and disconnecting one of the pump's alligator clips when it reaches your threshold.
To clarify about the pump never stopping, you have re-uploaded the original code where the if/else statement is NOT commented out, correct?
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Thu Dec 07, 2023 12:10 pm
by aliyahhhhhhhrrrrrr
Yes, I had uploaded the original code with the If/Else not commented out. Even if I stop it manually, how would I record my data? Wouldn't that mean that the project had failed?
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Thu Dec 07, 2023 12:13 pm
by bfinio
This is a bit of a workaround, but you could either set up your phone to take a video of your computer screen, or use a screen recorder program, and take a video of the serial monitor. You could then play the video back to extract SOME of the data (time stamps and sensor readings) and graph them. It would be difficult to get every single data point, but you could get enough to make a graph.
Going back to the beginning of our discussion a bit, do you have prior experience with an Arduino or is this your first Arduino project? Either way, did you follow any of our intro to Arduino tutorials before trying this project? Information like this helps us make our resources better for our users.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Sat Dec 30, 2023 3:32 pm
by acuze104
Hi I'm having an issue with the code that you provided where the pump is always running. My pump is not running at all. I've attached a picture of my board and arduino.
I've also included the different mosfets I purchased thinking that it was the issue.
Re: Dealing with Diabetes - Developing an Artificial Pancreas - Pump Help
Posted: Sat Dec 30, 2023 3:49 pm
by acuze104
Nevermind I got it. thanks