Created
December 10, 2025 13:41
-
-
Save psychemist/c0e4e6a370782a9a6b06c863e51e82b9 to your computer and use it in GitHub Desktop.
Arduino Starter Project 9
This file contains hidden or 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
| const int switchPin = 2; | |
| const int motorPin = 9; | |
| int switchState = 0; | |
| void setup() { | |
| // declare pins' directions | |
| pinMode(switchPin, INPUT); | |
| pinMode(motorPin, OUTPUT); | |
| } | |
| void loop() { | |
| // check switch state | |
| switchState = digitalRead(switchPin); | |
| Serial.print("Switch State: "); | |
| Serial.print(switchState); | |
| // complete motor circuit based on switch state | |
| if ( switchState == HIGH ) { | |
| // turn motor ON | |
| digitalWrite(motorPin, HIGH); | |
| } | |
| else { | |
| // turn motor OFF | |
| digitalWrite(motorPin, LOW); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment