Skip navigation


1 Post authored by: nmmbeginer

ok so i am new to arduino. i am trying to have one button turn on the led witch is in pin 13 and another button to turn it off but im having problems. when i press the button it turns on when i let off the button it goes off.  here is my code so far.


const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  13;      // the number of the LED pin

const int buttonPin1 = 3;

// 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); 

  pinMode(buttonPin1, INPUT);




void loop(){

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);

   buttonState = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) {   

    // turn LED on:  

    digitalWrite(ledPin, HIGH);



    delay(100);  // Wait 0.5 seconds before re-checking button states


    if (buttonState == HIGH) {   

    // turn LED on:  

    digitalWrite(ledPin, LOW);






if some one can tell me what im doing wrong please tell me.i just started programming and i dont know much i can read and under stand code but i am not good at writing code.

Filter Blog

By date: By tag: