5v water pump controlled by uno r3 input from ds18b20 temperature sensor?

Can anyone help me? I want to run a 5v water pump via a relay powered by a 9v battery and automatically controlled by a temperature sensor. I also want to use a data logger on the r3 to show my results.

uno r3
5v submersible pump
5v relay
9v battery
breadboard
4.7kohm resistor
ds18b20 temp sensor

This is for a project to surface water cool a solar panel automated by its surface temperature.

I want to know if I can straight swap out a soil moisture capacitor from a plant irrigation system project with a DS18B20 sensor?

and if anyone can help me with the code alterations?

I will post this project when completed and acknowledge anyone who helps.

If your 9V battery is of the "fire alarm battery" type, it will not
will provide sufficient current for the water pump.
You will need to use another type of power supply, perhaps 2 Li_Ion batteries in series.

Using the recommended tags, post your code, and also post the schematic of your project.

1 Like

Welcome!

One of these?

Won't run your relay, pump, or Arduino for very long at all.

You'll find we dote on things like schematics, rather than long, wordy descriptions. Please show us your schematic!

1 Like
  • The first thing you need to do is show us a proposed schematic as you perceive it would be.
1 Like

Interesting project but we are not a free design or code writing service. We will be happy help out with your design and or code but first you have to make an attempt to design it, write it, post it and explain what is not working properly.

If there is hardware it is always best to post links to technical information as there are many versions of the same or different items. Since we cannot see your project, my eyes are to weak, you need to post using the language of electronics, an annotated schematic the language of electronics, (best) or a clear picture of a drawing. Pictures never hurt. Frizzing diagrams are not considered schematics here, they are wiring diagrams.

1 Like

camsysca,

thanks for the quick reply. Yes, I am currently experimenting with one of those 9v batteries. I plan to power the circuit from the solar-charged batteries, which are 12v 105Ah lithium leisure batteries. I am looking into step-down voltage regulators on these forum pages.

Schematics to follow.

Schematics to follow.

thank you for the kudos on the project so far.

I understand this forum is not a design or code writing service, I am trying to do what I can myself before asking for help.

temperature controlled water pump.pdf (57.7 KB)

temperature contolled water pump breadboard.pdf (99.8 KB)

About your schematic.

  1. images can be loaded directly to the message in this forum, no need to create PDF and upload it.
  2. what voltage is the output of the buck converter feeding the UNO - because it should be 7V or greater, but no more than 10v
  3. a relay contact won't power a motor. Something wrong there.
  4. in this instance, a single relay, you may be able to get away with powering it from the 5V of the Arduino, but normally it's a horrible practice.

About your software:
Divide and conquer. By that I mean, write codes that simply operate/reports each individual element. That will do two things; enhance your skills with the IDE and the language, and provide you with test modules you can 'fall back to' when things go awry. While the proficient members of this forum will likely skip this step almost all the time except when working with an unfamiliar element, as a newb you owe it to yourself to take baby steps.

When you have a code that exercises an element, save it with a known name and keep a notepad itemizing the codes.
"Motor driven by button"
"LED and motor driven by button"

Please re-read

particularly how to post code. It's very simple. What you've posted is unintelligible, and makes copy-pasting it into the IDE error-likely.
thanks!

My mistake, won't happen again.

1 Like
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
#define RELAY1 8

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

void setup(void) {
  // Start serial communication for debugging purposes
  Serial.begin(9600);
  // Start up the library

  pinMode(RELAY1, OUTPUT);
  digitalWrite(RELAY1, HIGH);

  sensors.begin();
}

void loop(void) {
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures();

  Serial.print("Celsius temperature: ");

  // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  Serial.print(sensors.getTempCByIndex(0));
  Serial.print(" - Fahrenheit temperature: ");
  Serial.println(sensors.getTempFByIndex(0))


if (Celsius temperature >= 40) {
  digitalWrite(RELAY1, HIGH);
  Serial.pirntln("PUMP ON");
}

if (Celsius temperature < 40) { digitalWrite(RELAY1, LOW); }

delay(1000);
}

this is my code so far, I am a beginner to coding and am struggling to make this code work, specifically with lines 37-42. i am aiming to get the temp sensor to operate the relay but don't know how to do this. any help would be greatly appreciated.

looking at your code posted, everything from
if (Celsius temperature >= 40)
is outside of loop(), due to the } above it. That won't compile.

Serial.pirntln("PUMP ON");
Oops. spelling.
Serial.println(sensors.getTempFByIndex(0))
missing semicolon at end

Try this:

  if (sensors.getTempCByIndex(0) >= 40) {
    digitalWrite(RELAY1, HIGH);
    Serial.println("PUMP ON");
  }

  else {
    digitalWrite(RELAY1, LOW);
    Serial.println("PUMP OFF");
  }
1 Like

thank you @camsysca !

That code alteration works!

Now, as expected, the 9v battery cannot power the pump!
I ordered a buck converter to power the uno and pump from the 12v solar-charged lithium battery.

I will let you know how I get on tomorrow.

1 Like
  1. understood, i will do that in future
  2. 5-7v
  3. ok ill have a look
  4. thats plan b then
1 Like






#include <OneWire.h>
#include <DallasTemperature.h>

#define RELAY1 8
#define ONE_WIRE_BUS 4

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

float Celsius = 0;
float Farenheit = 0;

void setup() {
  sensors.begin();
  Serial.begin(9600);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  delay(2000);
}

void loop() {

  sensors.requestTemperatures();

  Celsius = sensors.getTempCByIndex(0);

  Serial.print(Celsius);
  Serial.println("C");


  if (Celsius >= 35) {
    digitalWrite(8, LOW);
    delay(10000);
    Serial.println("Pump On");
  } 
  else if (Celsius < 25) {
    digitalWrite(8, HIGH);
    delay(10000);
    Serial.println("Pump Off");
  }
  delay(10000);
}

Nice project, only a few questions:

  • if I'm not wrong you are cooling one of the panels 'dripping water' on its surface ( as shown in one of the photo )
  • do you see any measurable difference in output power when the cooler is on?

I see from the serial debug you posted that 9 seconds after switching off the pump the surface temperature skyrocketed to 49°C again so maybe a variable, but more steady, water flow could improve the temperature control ( reducing the min/max oscillation )

P.S.
I'm happy you can cool your panels to 25°C, here ( in Italy ) we have 31°C air temperature : - (