Maker Pro
Maker Pro

I press button, Arduino does nothing. Why?

I have Arduino, it's supposed to take power through a mosfet from a battery pack when I press a button. I'm running the program through the serial monitor to see if it's actvating it's digital out and it's not. I checked to see if it's getting input voltage into the input pin and it is, but for some reason it doesn't want to send voltage out through the output pin. So any idea what I'm doing wrong? This is my first project by the way.

Turns out I had to give it a reference to 0(I'm guessing) by setting my input/outputs as constants and then a "buttonState" as =0 but then when said state goes high(it's reading it's value from the input) then it'll turn on my motor. :)
it was this tutorial that helped me. I read it before and didn't think it applied. Guess I was wrong! lol


Code:
/* A motion sensor, when detecting motion, sends 3.3v to Pin 2
 
 After getting input on pin 2, pin 3 will activate a motor for 1 second.
 
 Then the program will wait designated time before activating the motor again. 
 */

int PIR = 2;
int PUMP = 3;

//initialize Pin 2 as input and Pin 3 as output
void setup()
{
  pinMode(PIR, INPUT);
  pinMode(PUMP, OUTPUT);  
  Serial.begin(9600);
}

//Runs until shutting down. Wait for input, send output, wait designated time, repeat
void loop(){
  //read the output state:
  int outputState = digitalRead(PUMP);
  //print the state of the output
  Serial.println(outputState);
  //if sensing nothing, do nothing

  if (digitalRead(PIR == LOW))
  {
    digitalWrite(PUMP, LOW);
  }
  else
  {
    //if sensing movement activate pump for one second
    if (digitalRead(PIR == HIGH))
    {
      digitalWrite(PUMP, HIGH);
      delay(1000);
    } 

  }
  //wait one minute before looking for movement again
  delay(600);
}
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Amazing how describing the problem to someone else can help you solve it.

Good job :)
 
Top