Using Analog pins for push buttons?

Hello i always used Digital pins for push buttons but i was wondering if i can use an analog pin for put button to light up an Led?

Sketch

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = A3;     // the number of the pushbutton pin
const int ledPin =  4;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}


Would it work the same way I don't want to try this in case something goes wrong and feeding power in instead of pushing a button?

Well it says here:

The analog input pins can be used as digital pins, referred to as A0, A1, etc.

.... and you have the sketch written: what does it do?

I recommend you use:
14 - A0
15 - A1
16 - A2
17 - A3
18 - A4
19 - A5

Thank you very much for the information just wanted to confirm what i was thinking of doing thank you.

LarryD: I recommend you use: 14 - A0 15 - A1 16 - A2 17 - A3 18 - A4 19 - A5

.... on an Uno anyway.

The Ax numbers should work, and I believe it's even permissible to say this:

const int buttonPin = A3;

.... as OP did, since although "A3" isn't an integer it's actually set to the right number under the hood and is in fact a variable holding an integer.

But yep, if anything doesn't work, try it with 14 or 15 etc directly in the pinMode().

@Jim I should have said on an UNO, thanks.

josephchrzempiec: Hello i always used Digital pins for push buttons but i was wondering if i can use an analog pin for put button to light up an Led?

Sketch

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = A3;     // the number of the pushbutton pin
const int ledPin =  4;      // the number of the LED pin

// variables will change: int buttonState = 0;        // variable for reading the pushbutton status

void setup() {   // initialize the LED pin as an output:   pinMode(ledPin, OUTPUT);        // initialize the pushbutton pin as an input:   pinMode(buttonPin, INPUT);   
}

void loop(){   // read the state of the pushbutton value:   buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.   // if it is, the buttonState is HIGH:   if (buttonState == HIGH) {   
    // turn LED on:        digitalWrite(ledPin, HIGH);    }   else {     // turn LED off:     digitalWrite(ledPin, LOW);   } }

Would it work the same way I don't want to try this in case something goes wrong and feeding power in instead of pushing a button?

Did you try out this sketch?! What happened??!! (Hope it worked fine!) I also have the same doubt and don't intend to implement this unless I'm sure! Thanks

Just use the A* pin names and treat the analogue input pins as normal digital pins and you will be OK. They work as both digital inputs and outputs when the appropriate pinMode() is specified.