Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Why don't I get output voltage when I press my button? Arduino code problem?

Status
Not open for further replies.

red913

Newbie level 5
Joined
Mar 28, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,370
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 switch. :)
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:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top