/* headset_NPN Version 2.0 Use Arduino to simulate cellphone headset clicks via NPN transistor The use of Arduino pin D12 is a little tricky. We set it to "input" mode with digitalWrite LOW to make the pin high-resistance, essentially taking it out of the circuit. To drive the transistor gate pin, we leave D12 in "input" mode but connect the internal pull-up resistor with digitalWrite HIGH. */ #define LEDPIN 13 #define NPNPIN 9 #define openPin(pin) digitalWrite(pin, LOW) #define pullupPin(pin) digitalWrite(pin, HIGH) void setup() { pinMode(NPNPIN, INPUT); // Set NPNPIN to high resistance input pinMode(LEDPIN, OUTPUT); } void loop() { delay(1500); click(40); } void click(int length) { digitalWrite(LEDPIN, HIGH); pullupPin(NPNPIN); // Connect pull-up resistor; allows "input" pin to act as weak output to drive transistor delay(length); openPin(NPNPIN); // Back to high resistance digitalWrite(LEDPIN, LOW); }