Class Home

Lab reports

Work

Class details

Physcomp Home
Wiki help
Edit sidebar

Very Basic Transistor

////SIMPLE TRANSISTOR
////October 16th, 2007

//////setup alias for the pin names
int transistorPin = 2;    // connected to the base of the transistor
int switchPin = 3;  //connect a switch as input for the arduino
int ledPin = 10;    //blinky led to tell you when arduino has started up

//////declare my variables
int switchState; //will record whether my switch is open or closed


void setup() {

    pinMode(transistorPin, OUTPUT);
    pinMode(ledPin, OUTPUT);
    pinMode(switchPin, INPUT);

    blinky();     //run the blinky function once
}


void loop() {
 switchState = digitalRead(switchPin);  // read input value from the switch

 if (switchState == HIGH) {         // check if the switch is closed ie. HIGH
    // set  the transistor pin as output:
    //////turn the transistor Base pin on and off to control the laad.
    digitalWrite(transistorPin, HIGH);
    delay(2500);
    digitalWrite(transistorPin, LOW);
    delay(2500);
  }

}

///////FUNCTIONS//////////////////////////////
void blinky(){
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}
  Edit | View | History | Print | Recent Changes | Search Page last modified on October 16, 2007, at 01:24 PM