Menu Close

NodeMCU Switching Using Transistor on Arduino IDE

This tutorial of Robo India explains how to a transistor as a switch on NodeMCU using Arduino IDE.

Detailed Tutorial

1. Introduction:

A very less current consuming device like LEDs can be controlled directly through an Node MCU. Other devices can be controlled by an Node MCU signal using a transistor. In such case a transistor is there between an Node MCU and the device. The transistor takes signals from the Node MCU and controls the device as per the signals. This chapter deals in using an NPN transistor as a switch.

1.3 Hardware required




S.No.
ItemQuantity
1NodeMCU 1
2Breadboard 1
3LED 1
4Resistor 1k 2
5Jumper Male to male 6
6nPn Transistor 1

2. Building Circuit

Schematic of circuit.


Layout of circuit

3. Programming:

Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run this circuit on NodeMCU.

You may download this code (Arduino Sketch) from here.

// Robo India Tutorial 
// Digital Input and Output on LED 
// Hardware: NodeMCU

const int transistor = 4;  // Assigning name to Trasistor 

void setup() {                
   pinMode(transistor, OUTPUT);     // Assigning pin as output
}

void loop() {
  digitalWrite(transistor, HIGH);   // making pin high
  delay(1000);               
  digitalWrite(transistor, LOW);    // making pin low
  delay(1000);               
}


4. Output

The LED blinks at a time interval of 1 second.

5. Troubleshooting

LED is not blinking: Check polarity of the LED and the transistor as shown in the circuit.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply