Connect with us

I press button, Arduino does nothing. Why?

Discussion in 'Microcontrollers, Programming and IoT' started by red913, Apr 7, 2013.

Scroll to continue with content
  1. red913

    red913

    23
    0
    Mar 22, 2013
    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: Apr 7, 2013
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,497
    2,838
    Jan 21, 2010
    Amazing how describing the problem to someone else can help you solve it.

    Good job :)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-