Introduction: Led
here I'm going to teach you how to make a button turn a led on and stay on until pressed again
Step 1: Componets
you will need
one led
one button 4 jumper wires
and one arduino
Step 2: Wireing
button gnd and pin 6
led gnd and from resistor pin13
Step 3: Done
code
boolean flag = true;
int b3 = 6; int b2 = 7; int b1 = 8; int button = 0; int led1 = 13; void setup() { // put your setup code here, to run once: pinMode(b3, INPUT_PULLUP); pinMode(led1, OUTPUT); } void loop() { if (digitalRead(b3)==LOW){ // check the state of switch1 every time we run through the main loop delay(5); // I don't REALLY know why this delay helps, but it does. flipflop(); // hops out of main loop and runs the flipflop function }// end of check for button press. // other sketch code here } // end of main loop. void flipflop(){ //funtion flipflop flag = !flag; // since we are here, the switch was pressed So FLIP the boolian "flag" state (we don't even care if switch was released yet) if (flag == HIGH){ // Use the value of the flag var to change the state of the pin digitalWrite(led1,HIGH ); // if the flag var is HIGH turn the pin on } if (flag == LOW) { digitalWrite(led1,LOW); // if the flag var is LOW turn the pin off } while(digitalRead(b3)==LOW); // for "slow" button release, keeps us in the function until button is UN-pressed // If you take out this "while" the function becomes a flipflop oscillator if the button is held down. delay(50); // OPTIONAL - play with this value. It is probably short enough to not cause problems. deals with very quick switch press. }
now where do thanks for your help

Participated in the
Make it Glow Contest 2018
Comments
5 years ago
Welcome to Instructables. Thanks for sharing your tutorial with the community.