/* 4-21-2011 Spark Fun Electronics 2011 Nathan Seidle This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). This code uses the Power Shield to drive up to 6 MOSFETs. You'll need a computer power supply to power the MOSFETs. The solenoid from SparkFun works with 12V and uses around 650mA when it's turned on. */ int statusLED = 13; int solenoid = 11; //The solenoid is on D11 void setup() { pinMode(statusLED, OUTPUT); pinMode(solenoid, OUTPUT); Serial.begin(57600); } void loop() { char option; while(1) { Serial.println(); Serial.println("Solenoid Tester"); Serial.println("1) Turn on/off solenoid"); Serial.println("2) Cycle the solenoid"); Serial.print(": "); while (!Serial.available()); option = Serial.read(); if(option == '1') { if(digitalRead(solenoid) == LOW) { Serial.println("Solenoid ON!"); digitalWrite(solenoid, HIGH); } else { Serial.println("Solenoid Off"); digitalWrite(solenoid, LOW); } } else if(option == '2') { Serial.println("This is usually not a good idea. Are you sure?"); while(!Serial.available()); if(Serial.read() == 'y') { while(!Serial.available()){ //Cycle until we see serial input Serial.println("Solenoid ON!"); digitalWrite(solenoid, HIGH); delay(250); Serial.println("Solenoid Off"); digitalWrite(solenoid, LOW); delay(250); } } } else if(option == '3') { Serial.println("Hi there!"); } else { Serial.print("Choice = "); Serial.println(option); } } }