const int switchPin = 2;
const int motorPin = 9;
int switchState = 0;
void setup() {
//motor pin as an output:
pinMode(motorPin, OUTPUT);
//pin as an input:
pinMode(switchPin, INPUT);
}
void loop() {
switchState = digitalRead(switchPin);
if (switchState == HIGH) {
// turn motor on:
digitalWrite(motorPin, HIGH);
} else {
//motor off
digitalWrite(motorPin, LOW);
}
}