CIRCUIT DIAGRAM: This is the led turned on by the push button: this is the led turned off by the push button: COMPONENTS: CODE: int ledpin = 8 ; int buttonpin = 12 ; int buttonread ; int dt = 500 ; void setup () { // put your setup code here, to run once: pinMode (ledpin,OUTPUT); pinMode (buttonpin,INPUT); Serial . begin ( 9600 ); } void loop () { // put your main code here, to run repeatedly: buttonread = digitalRead (buttonpin); Serial . println (buttonread); delay (dt); if (buttonread == 1 ){ digitalWrite (ledpin,HIGH); } delay (dt); if (buttonread == 0 ){ digitalWrite (ledpin,LOW); } } EXPLANATION OF THE CODE: int ledpin =8;` - This line initializes an integer variable called `ledpin` with a value of 8. This variable will be used to store the pin number of an LED that is connected to the Arduino board. `int buttonpin = 12;` - This line initializes another integer variable called `buttonpin` with a value of 12. This variable will be used to store th...
OnlyTronix Tutorials offers beginner-friendly Arduino, electronics, and programming guides with code, circuit diagrams, component selection tips, and troubleshooting help.