Created
January 30, 2020 08:57
-
-
Save suadanwar/57a99ad7de1ef474fb4048eb39a50727 to your computer and use it in GitHub Desktop.
This sample code is for Solenoid Door Lock with Relay on Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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