KY004 Momentary Button Module
This is a button module. When the button is pressed, it will a high level signal.
Connection
Pin – = GND, connect to Arduino Gnd
Pin (middle) +5 v, connect to Arduino +5v
Pin S signal, connect to Arduino pin 10
Code
[codesyntax lang=”cpp”]
int Led = 9 ;// define LED int buttonpin = 10; // define the button module int val; void setup () { pinMode (Led, OUTPUT); pinMode (buttonpin, INPUT); } void loop () { val = digitalRead (buttonpin); if (val == HIGH) { digitalWrite (Led, HIGH); } else { digitalWrite (Led, LOW); } }
[/codesyntax]