Home 37 Sensor Kit KY004 Momentary Button Module

KY004 Momentary Button Module

by shedboy71

This is a button module. When the button is pressed, it will a high level signal.

KY004 Momentary Button Module

KY004 Momentary Button Module

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]

You may also like