• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!


Switch and Flashing Output

Page history last edited by PBworks 16 years, 9 months ago



MOSFET output


This was the example shown in class to switch high current loads using a MOSFET connected to one of the Arduino digital pins. Remember, connecting more than 2 LEDs to a single pin may damage that pin or the microcontroller itself. The LEDs shown could be just as easily added to in parallel or replaced by other non-inductive loads such as the cold cathodes I used in my example or other el wire light sources (the resistor would not be needed for other light sources). The following example blinks whatever is connected to the MOSFET 1 second after the switch is pressed.


NOTE: The pins of the chip will not line up with the schematic in the way you might think. Refer to the picture at right when connecting in your circuit.


/*  In class, this example was hooked to a MOSFET

    to quickly blink some white cold cathode lights

    when a switch was pressed.



int whiteLight = 13;            // output pin for the LED

int switchPin = 2;              // input pin (for a switch)


void setup()


  pinMode(whiteLight, OUTPUT);  // declare LED as output

  pinMode(switchPin, INPUT);    // declare switch as input



void loop()


  if (digitalRead(switchPin) == HIGH) // check if input is HIGH



    for(int i=0; i<10; i++)


    digitalWrite(whiteLight, HIGH);   // turns the LED on

    delay(50);                        // pause for 1 second

    digitalWrite(whiteLight, LOW);    // turns the LED off






Comments (0)

You don't have permission to comment on this page.