Skip to content

Instantly share code, notes, and snippets.

@psychemist
Created December 10, 2025 13:41
Show Gist options
  • Select an option

  • Save psychemist/c0e4e6a370782a9a6b06c863e51e82b9 to your computer and use it in GitHub Desktop.

Select an option

Save psychemist/c0e4e6a370782a9a6b06c863e51e82b9 to your computer and use it in GitHub Desktop.
Arduino Starter Project 9
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