Schets not working

ani body wat do i wrong
const int mSensor = 2;
const int mPump = LED_BUILTIN ;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(mSensor, INPUT); //setpin#2 as input
pinMode(mPump, OUTPUT); //setpin#13 as output

}

void loop() {
// put your main code here, to run repeatedly:
int mState = digitalRead (mSensor); //read the value of sensor
Serial.println (mState);
delay (10);

if (mState == HIGH) { //if the moisure sensor is dry equal to logic 1 or high
digitalWrite(mPump, HIGH); //the water pump will relase water
delay (10);
}
else {
digitalWrite(mPump), LOW); //if the moisure sensor is wet equal to logic 0 or low
delay(10); //the water pump will stop releasing water
)
}

Why not add some prints to your sketch to get it to tell you what it is doing?

Please remember to use code tags when posting code.

If you would put code tags (</>), you sketch would appear like below and the task of finding errors would be easier.


const int mSensor = 2;
const int mPump = LED_BUILTIN ;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(mSensor, INPUT); //setpin#2 as input
  pinMode(mPump, OUTPUT); //setpin#13 as output
}

void loop()
{
  // put your main code here, to run repeatedly:
  int mState = digitalRead (mSensor); //read the value of sensor
  Serial.println (mState);
  delay (10);

  if (mState == HIGH)
  { //if the moisure sensor is dry equal to logic 1 or high
    digitalWrite(mPump, HIGH); //the water pump will relase water
    delay (10);
  }
  else
  {
    digitalWrite(mPump), LOW); //if the moisure sensor is wet equal to logic 0 or low
    delay(10); //the water pump will stop releasing water
    )
  }

What does your program do?

It doesn't compile.

It would have been good for you to have told us that, rather than "it doesn't work".

The syntax is:
digitalWrite(arg1, arg2);

You posted in the wrong section, one that was NOT for your own project. I have moved it here.
Please take time to read the "getting the best out of this forum " sticky post at the start of each section.

A few possibilities:

  • Components wired up wrong
  • Inadequate power supply
  • Inadequate or no driver for pump
  • Using an analog sensor and expecting it to work OK with digitalRead();
  • Oscillation between pump on and pump off, resulting in erratic behavior
    ....etc. etc.

It's a turkey shoot without more information.

Please read this (ALL of it), in particular what kind of information you need to supply: How to get the best out of this forum

See the next to last line.

const int mSensor = 2;
const int mPump = LED_BUILTIN ;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(mSensor, INPUT); //setpin#2 as input
pinMode(mPump, OUTPUT); //setpin#13 as output

}

void loop() {
// put your main code here, to run repeatedly:
int mState = digitalRead (mSensor); //read the value of sensor
Serial.println (mState);
delay (10);

if (mState == HIGH) { //if the moisure sensor is dry equal to logic 1 or high
digitalWrite(mPump, HIGH); //the water pump will relase water
delay (10);
}
else {
digitalWrite(mPump), LOW); //if the moisure sensor is wet equal to logic 0 or low
delay(10); //the water pump will stop releasing water
)         <<-------------------------------------------------------------------this needs to be }
}

Oké JR ITS werking now thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.