Need help in programming

Hi I’m a 4th year ece student, and we have this project due on monday, its an automatic plant watering system, but even though the moisture is already high the motor is still running but its suppose to stop, can you please help me? I don’t know what to do in the codes, I’m new to this type of project thank you in advanced

here is the code i’m using

const int VAL_PROBE = 0; //Analog pin 0
const int MOISTURE_LEVEL = 250; // the value after the LED goes on

void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(7, OUTPUT);
}

void LedState(int state)
{
digitalWrite(13,state);
}

void loop()
{
int moisture = analogRead(VAL_PROBE);

Serial.print("Moisture = ");
Serial.println(moisture);

if(moisture > MOISTURE_LEVEL)
{
LedState(HIGH);
digitalWrite(7,HIGH);
}
else
{
LedState(LOW);
digitalWrite(7,LOW);
}

delay(500);
}

To use your A0 entry, try to define:

const int VAL_PROBE = A0;

is it normal when I plugged in my arduino in my laptop the TX led is on?

Jeff_85:
To use your A0 entry, try to define:

No that’s not the problem with analogRead, you can pass the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)

—-

Describe what is connected where and how is the motor powered (what type of motor)

Right. Then I also saw that as long as the condition is greater, everything continues HIGH.

Yep - that is why it would interesting to know how things are connected

we are using a submersible pump, and here’s our connections

is it normal when I plugged in my arduino in my laptop the TX led is on?

As far as I know, while Arduino is sending things to his Monitor It would, yes!

From your image, you're not using pin 2. Do not you use it?

if(moisture > MOISTURE_LEVEL)

{ LedState(LOW); digitalWrite(2,LOW); }

const int VAL_PROBE = 0; const int MOISTURE_LEVEL = 250; // the value after the LED goes on

void setup() { Serial.begin(9600);

pinMode(13, OUTPUT); //pin 13 pinMode(2, OUTPUT); //pin 2 }

void LedState(int state) { digitalWrite(13,state); Serial.print("Pump: "); Serial.println(state); }

void loop() { int moisture = analogRead(VAL_PROBE);

Serial.print("Moisture = "); Serial.println(moisture);

if(moisture > MOISTURE_LEVEL)

{ LedState(LOW); digitalWrite(2,LOW); Serial.println("Outuput 2 LOW"); } else { LedState(HIGH); digitalWrite(2,HIGH); Serial.println("Outuput 2 HIGH"); } delay(500); }

If you need output 2 to be HIGH when pump is off, change HIGH. Or the other way around.

I am not sure about the current and capacitance of the UNO board (even though it is just a bridge between the battery and the pump).

pin 2 is for the pump? and pin 13 is for the led?

Jeff_85: As far as I know, while Arduino is sending things to his Monitor It would, yes!

From your image, you're not using pin 2. Do not you use it?

If you need output 2 to be HIGH when pump is off, change HIGH. Or the other way around.

I am not sure about the current and capacitance of the UNO board (even though it is just a bridge between the battery and the pump).

i tried using this code but the motor is still running even though the pot is full of water

pin 2 is for the pump? and pin 13 is for the led?

Yes, it may be in 2, but in the image it is in 7.

See an example of how to control soil moisture. Uses 3 status indicators. The pump is switched on when the ground is dry and switched off when it is wet.

#define inputAnalog A0
#define red_led 5
#define yellow_led 6
#define green_led 7
#define pump 2

int analog_value;

void setup()
{
Serial.begin(9600);
pinMode(inputAnalog, INPUT);
pinMode(red_led, OUTPUT);
pinMode(yellow_led, OUTPUT);
pinMode(green_led, OUTPUT);
pinMode(pump, OUTPUT);
digitalWrite(pump, LOW);
}

void loop()
{
// Le the value of sensor pin A0
analog_value = analogRead(inputAnalog);

// Displays the value of the analog port on the serial monitor
Serial.print("Analog Value: ");
Serial.print(analog_value);

//Check that the earth is wet enough
if (analog_value > 0 && analog_value < 400)
{
Serial.println("Wet ");
off_leds();
digitalWrite(green_led, HIGH);
digitalWrite(pump, LOW);
}

//Moderate humidity, maybe presice to water
if (analog_value > 400 && analog_value < 800)
{
Serial.println("Moderate humidity ");
off_leds();
digitalWrite(yellow_led, HIGH);
}

//Dry land. Throw water
if (analog_value > 800 && analog_value < 1024)
{
Serial.println("Just dry ");
off_leds();
digitalWrite(red_led, HIGH);
digitalWrite(pump, HIGH);
}
delay(500);
}

void off_leds()
{
digitalWrite(red_led, LOW);
digitalWrite(yellow_led, LOW);
digitalWrite(green_led, LOW);
}

i used the program you posted but still the motor keeps running when the soil is very wet, I don't know where the problem is, its our first time doing this kind of project

Would suggest you read how to properly drive an inductive load (your pump) from an arduino and what flyback diodes are for (here is an example of what to read and there are plenty more like this too)

Your transistor may be dead by now and I’m not sure how much current your pump needs but driving that current through your arduino board through Vin is probably not a good idea in general. Power things separately, your arduino from usb since your use Serial I suppose you are connected to your computer anyway and use the 12v power supply only for the motor (joining grounds of course)

Hi, What are the readings you get in the serial monitor?

Have you adjusted the pot on the moisture sensor board so it changes output when the moisture level changes?

You are expecting an analog series of values to come from your sensor, check that it might just output a HIGH or LOW when wet or dry?

A link to where you purchased the sensor will help.

Also check specs of 2N5557? N-ch MOSFET

If its a 2N5551, its an NPN transistor 600mA rating, what is the current rating of your pump?

Thanks.. Tom.. :)