Pump isn't stopping at the treshold

Please help we have a pump that we are trying to stop at a conductivity threshold of 400. The pump runs but it will not shut off. I am very new to this and am trying to help my student. Thanks


  • Always show us a good schematic of your proposed circuit.

  • In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
    Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.

  • What is the transistor part number ?

I agree with @LarryD , in order to help we need to see your schematic, your actual wiring, and your code. The code and the schematic are most important.

At first glance though, it looks like your code calls for an analog reading from A0, but the photo of your setup doesn't have a wire attached to A0.

Hope this helps!

Sorry, but the schematic is not readily readable to me. The best thing you can do for your student, especially if they plan to continue working with electronics, is to teach them how to create a proper schematic. A good CAD (Computer-Aided Design) program, like KiCad, is available for free download. KiCad allows you to go from design capture to generating the Gerber files needed to fabricate a PCB. However, it’s not a program you can master overnight—it requires time and practice to become proficient.

Understanding the Importance of Schematics Over Fritzing Diagrams:

Your understanding is partially correct if the reader is using the exact same parts, but Fritzing diagrams are mainly wiring diagrams showing how to connect specific components. They do not provide a complete picture of what the circuit does or how it functions, especially for power supplies, converters, and other crucial components that are often not included in Fritzing diagrams.

Common Issues with Fritzing Diagrams:

  • Often, we see components labeled as "same as" or "similar to," which can lead to confusion.
  • Misaligned lines and pins make the diagrams difficult to interpret, especially when switching to a different processor.
  • Common mistakes include buttons rotated incorrectly, missing pull-up resistors, and other subtle errors that are not visible in Fritzing diagrams.

Why Schematics Are Essential:

A schematic, or schematic diagram, is a symbolic representation of the components of a system, using abstract symbols rather than realistic pictures. These symbols are consistent across different designs and users, making schematics universally understandable. Once you learn to read schematics, it’s much faster and more accurate to understand a circuit’s function compared to interpreting Fritzing diagrams.

Appreciating the Value of Schematics:

For fun, try drawing a circuit with 10 ICs and about two dozen resistors, especially in the analog domain. You’ll quickly see why schematics are considered the "language of electronics" and why they are far superior to Fritzing diagrams for understanding complex designs.

Helpful Resources:

Im doing the same project and encountering the same problem. The Arduino won't stop at the threshold. Here is the code:
@LarryD @anon51466201

/*
 * 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 = 210; // 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 you are not showing a schematic of your project, either. So you will get the same help.

I sat in on a couple of classes like this where students are learning Arduino for the first time, and I've seen a couple of mistakes that are the most common, which I will try to outline here.

First of all, this is very simple code and it probably works fine, so the question is, why is it not doing what you expect? Some possibilities include:

  1. You are never reaching the threshold value, so the pump is never turning off. Check your sensor or potentiometer.
  2. Your motor is directly connected to power, so even if the Arduino is toggling the transistor correctly, it is not interrupting the power to your motor.
  3. You have other wiring mistakes. Review how a breadboard works and make sure that you aren't accidentally shorting things out or thinking that they are connected when they are not.
  4. Check your power circuitry. Is the right voltage powering your Arduino and on the right pins? Are you using a different power source for your motor? Is the GND connection to the Arduino and every power supply connected so that everything shares a common ground?

Show us a picture of your schematic, and show us a picture of your physical setup. The problem here is almost certainly a ground wire that isn't connected or another wire that is improperly connected.

I hope #1 has been ruled out:

  conductivity = analogRead(A0);  // get conductivity reading
  Serial.println(conductivity);

@new2thegame @essa21288 are the printed numbers plausible?

a

I'm sorry, my knowledge on Arduino is zero to none. My schematic is very messy and I don't even have the correct color wires. Here is a photo but I understand it you are unable to comprehend what's going on (I definitely don't). I appreciate any help I can get, thanks!

The sensor is reading the values correctly. The only issue is that the motor won't stop at the threshold value.

Are you printing the threshold value so you know what the program is looking for?

  1. You have an extra wire just sitting on top of the Arduino. Very dangerous as you can short two points on the Arduino together by accident and not even realize how just just fried the board.
  2. You are missing the pulldown resistor on the gate of your transistor. There should be a resistor going from that pin of the transistor down to GND. This keeps the gate from accidentally turning on or accidentally staying on when it shouldn't. This seems like a likely culprit for your problem.
  3. Is that black box in the bottom right corner a power supply? Check the polarity of the voltage coming out ot it. Typically red wire will be positive and black wire will be GND. In your case, I see the red wire attached to the GND power rail on the breadboard and the black wire attached to the + power rail on the breadboard, which would mean you might be applyinh the voltage backwards.
  4. I see you want to use the power rails on both sides of the breadboard, but they don't seem to be connected. Maybe that orange wire is connecting the (-) rail? I don't see any wire connecting the (+) rail on one side to the (+) rail on the other side. I don't understand how your Arduino is even getting power.
  5. How does that sensor even work? I would suggest setting up a test in your code where the serial monitor tells you what the value of that sensor is ever second. See if the sensor value ever changes. Can you see it start low and grow to eventually become bigger than the threshold value.

Final notes: Clean up your setup. Get that wire off the unprotected Arduino board. Draw the schematic by hand, then make sure that each and every wire in the schematic is connected in the circuit. Add a pulldown resistor to the gate of the transistor. If you want anyone else's help here, you will definitely need a schematic.

Thank you SO much! I finally got it to stop at the threshold. I think the problem was the pull down resistor. Thank you Thank you Thank you!! @chromorphous

  • In the future, show us a schematic.

I've never done anything with Arduino, hence my knowledge is really, really limited and probably clueless. I will make sure to make a schematic before my next project. Thanks for all the tips!

I would like to know how much information your teacher has given you

No disrespect to the group at all...not looking for a short cut, just trying to help out of my area. The problem was resolved...thanks for everyones advice.

How did you know how to assemble the circuit?
Where and what information did you use the assemble your project?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

It is a project from sciencebuddies.org it gives the initial code and circuit layout, but it needed a few tweeks to work.