Skip to content

Instantly share code, notes, and snippets.

@suadanwar
Created January 30, 2020 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suadanwar/57a99ad7de1ef474fb4048eb39a50727 to your computer and use it in GitHub Desktop.
Save suadanwar/57a99ad7de1ef474fb4048eb39a50727 to your computer and use it in GitHub Desktop.
This sample code is for Solenoid Door Lock with Relay on Arduino.
#define BUTTON 2 // the number of the pushbutton pin
#define RELAY 3 // the number of the relay pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(RELAY, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(BUTTON, INPUT_PULLUP);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(BUTTON);
// check if the pushbutton is pressed.
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(RELAY, HIGH);
} else {
// turn LED off:
digitalWrite(RELAY, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment