The attached file is our schematic for the water pump code. How it works is that a soil sensor in the dirt will detect moisture level of the dirt. If the dirt level is low enough, the pump with water the dirt until it is wet enough. The board is powered by 12v power supply for the motor that goes into Vin
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int thresholdUp = 400;
int thresholdDown = 250;
int mostureSensor = A0;
int Water_Pump = A5;
int sensorVaule = mostureSensor;
void setup() {
// put your setup code here, to run once:
pinMode(Water_Pump, OUTPUT);
lcd.begin(16, 2); //Initialize the 16x2 LCD
lcd.clear(); //Clear any old data displayed on the LCD
}
void loop() {
// initialize the mosture value from the soil sensor
int sensorValue = analogRead(mostureSensor);
Serial.println(mostureSensor);
//If the sensor is detecting 0 to 300 mosture value
if (sensorValue > 0 && sensorValue < 300)
{
lcd.print("Dry Soil!"); // Display the dry soil message on the LCD!
lcd.setCursor(0, 1); //Set the (invisible) cursor to column 0, row 1. delay(2000);
digitalWrite(Water_Pump, HIGH); //water the plant until else if
}
else if (sensorValue <= 300 && sensorValue < 700) //If the sensor value is detecting 300 to 700 mosture,
{
delay(2000);
digitalWrite(Water_Pump, LOW); //stop the water pump
lcd.print("Plant happy!"); // Display a message on the LCD!
lcd.setCursor(0, 1); //Set the (invisible) cursor to column 0,row 1.
}
else if (sensorValue = 0) // if there is no reading, then
{
lcd.print("Please check the sensor!"); // Display the sensor message on the LCD!
lcd.setCursor(0, 1); //Set the (invisible) cursor to column 0, row 1.
}
}
*Please note we have changed the pin to A5 in the schematic.
But couple of things aren't working;
The LCD is displaying just white squares
The pump is on continuously, and won't stop even if the dirt is wet enough.
So the soil sensor is expected to give a reading on a digital input (on/off)? - I would have attached this to an analog input. The code does say A0, but the diagram shows D0 ??? You CANNOT digital write to an anlaog pin like this.
Also the pump is on an analog output with HIGH and LOW values? - I would put that on a digital out.
So remove the digital 0 cable and put it on an analog in and change the code for that. Take the analog motor and move to a digital output.
As for the LCD display... Is there an adjustment on the back for contrast? IF so a very small flat blade screwdriver should be used to adjust this so you can read it. Double check your code too...
The following is part of the bigger circuit. Since It did not work on that circuit, I figured I might as well as break it down to smaller bits to test each part of the circuit.
Uh - to test the motor itself? Just apply 12v to it.
Your diagram shows a P-channel mosfet (and one probably too small to drive most motors), but you have it wired as if it were an N-channel one.
We don't like Fritzing diagrams here - because they encourage people to substitute parts, and then we think that the diagram represents what they have, when it actually doesn't, and thus we waste everyone's time.
The transistor itself is a PN2222A (an NPN). I am pretty sure everything is hooked up correctly.
const int motorPin= A5; //LED connected to digital pin 10
void setup()
{
pinMode(motorPin, OUTPUT); //sets the digital pin as output
}
void loop()
{
analogWrite(motorPin,HIGH); //turns the LED on
delay(1000);
analogWrite(motorPin,LOW);
delay(1000);
}
KiCAD is a fantastic piece of free software to draw circuit diagrams - something you should always do first for all but the simplest of projects, even before you're doing a Fritzing wiring thing (those are pretty unreadable and actual part numbers and values are missing, so great as wiring guide but that's about it).
That you feel your transistor heating up is no surprise. Motors can easily pull 1-3 Amp, and that kind of currents are a problem for many transistors. MOSFETs are more useful, they can switch shocking amounts of current without the need of a heat sink. Your transistor is rated at max 600 mA continuous, and the voltage drop at that current is 1V, which means it'd be dissipating 600 mW in it's tiny TO-92 housing.
Another thing: your transistor's gain is about 50, a 1K resistor between the output pin and the transistor limits the base current to 5 mA (5V output) so maximum current available for your pump will be about 250 mA. Maybe you should lower that value to 470R or so.
So what you could do, to test your pump, is to load good old Blink on your Arduino, and let it "blink" your pump. Then you know whether your transistor is switching it on and off as expected.