Search Code

Lesson 07: Getting Additional 5V and GND from Arduino | Arduino Step By Step Course

Lesson 07: Getting Additional 5V and GND from Arduino | Arduino Step By Step Course

In this lesson from the Robojax Arduino Step By Step Course, we explore a practical solution for a common problem: running out of 5V and GND connections on your Arduino board. Whether you're building a project that requires powering a servo motor, an LCD display, an ultrasonic sensor, or a combination of devices, the limited number of power pins on an Arduino Uno or Nano can quickly become a bottleneck. This guide demonstrates how to creatively use any digital I/O pin as an additional 5V source or as a ground connection, providing you with the flexibility to power multiple components without needing an external power supply for low-current devices.

This technique is particularly useful for several real-world applications, including:

  • Powering a small OLED or LCD display alongside a servo motor in a single project.
  • Supplying power to multiple sensors, such as an ultrasonic sensor and a PIR motion detector, simultaneously.
  • Creating temporary test setups on a breadboard where you need a quick and easy power source for a new module.
  • Driving low-power LEDs or logic-level circuits that require a clean 5V reference.

Understanding Arduino Power Limitations

Before we dive into the solution, it's crucial to understand the power architecture of your Arduino board. On a standard Arduino Uno, you typically have a single dedicated 5V pin. Some third-party boards, as noted in the video, may feature a second 5V pin, but even then, you might need more (in video at 00:26).

The amount of current you can draw from these pins depends on your power source. If you are powering the board via USB, the current is limited by the USB port or charger you are using—for example, a 1A charger will allow up to 1A, while a 2.4A charger will allow more (in video at 01:55). If you are using the barrel jack with a 7-12V supply, the current is regulated by the onboard AMS1117 voltage regulator chip, which has a typical current limit of 1.1A (in video at 02:20).

It is also important to note the ICSP header on the board. As explained in the video, this header provides access to the SPI (Serial Peripheral Interface) pins, and the pin on the right side is actually VCC (5V), while the last pin is GND (in video at 00:54). This gives you another physical location to tap into the 5V rail.

However, the most critical limitation to remember is for the digital I/O pins. According to the official Arduino documentation, each digital pin can supply or sink a maximum of 20 milliamps (mA) (in video at 03:30). This is more than enough for LEDs, logic circuits, and many sensors, but it is insufficient for high-current devices like motors or high-power servos. For those, you should always use the main 5V pin or an external power source.

Hardware and Components

For this demonstration, you will need the following components:

  • 1x Arduino board (Uno, Nano, or similar)
  • 1x LED (any color)
  • 1x 1kΩ resistor
  • 1x Breadboard
  • Jumper wires
  • (Optional) An LCD 1602 Display or a Relay module for demonstration

Wiring Guide

The wiring for this project is straightforward, as it primarily involves connecting a digital pin to your component's power rail and another digital pin to its ground. In the video, the instructor demonstrates this by powering an LED.

Here is how to set it up:

  1. Connect the LED: Connect the anode (longer leg) of the LED to digital pin 5 on your Arduino through a 1kΩ current-limiting resistor.
  2. Connect the Ground: Connect the cathode (shorter leg) of the LED directly to digital pin 2 on your Arduino.

This simple circuit allows pin 5 to act as the 5V source and pin 2 to act as the ground, completing the circuit (in video at 06:05).

For a more scalable approach, you can use a breadboard to distribute the power, as shown in the video. By connecting the red power rail of the breadboard to pin 5 and the blue/black ground rail to pin 2, you can easily power multiple components by plugging them into the respective rails (in video at 06:59).

Code Explanation

The code provided for this lesson is exceptionally simple, as its only purpose is to configure two digital pins to act as power supply pins. The key to this functionality lies in the two configuration constants defined at the top of the sketch.

Here is the user-configurable part of the code:

#define VCC2  5 // define pin 5 or any other digital pin here as VCC2
#define GND2  2 // define pin 2 or any other digital pin as Ground 2

These two lines are the core of the customization. The #define directive is a preprocessor command that tells the Arduino compiler to replace every instance of VCC2 with the number 5 and every instance of GND2 with the number 2 before the code is compiled. This makes it incredibly easy to change which pins you are using for power. If you want to use pin 8 as your 5V source, you simply change the 5 to 8 in the first line. Similarly, you can change the ground pin by editing the second line.

The rest of the code is just the initialization logic within the setup() function. It sets the pin defined as VCC2 to be an OUTPUT and then writes it HIGH, which outputs 5V. Conversely, it sets the pin defined as GND2 to be an OUTPUT and writes it LOW, which makes it act as a ground connection. Once this is done in the setup(), the pins will maintain their states for the entire time the Arduino is powered, and you can add your main program logic to the loop() function.

Live Project Demonstration

In the video, the instructor demonstrates the concept by loading the code onto the Arduino. Once uploaded, the LED connected between pin 5 and pin 2 immediately turns on, proving that pin 5 is supplying voltage and pin 2 is sinking current as a ground. To further illustrate the point, he shows that moving the LED's power connection to a different, unconfigured digital pin results in the LED not turning on, as that pin is not set to output 5V (in video at 06:37).

The demonstration also includes a practical example using a breadboard. By connecting the 5V pin to the breadboard's power rail and the ground pin to the ground rail, he powers up a 1602 LCD display and a relay module simultaneously. This shows how you can use this technique to create a small, dedicated power distribution bus for your low-current components, keeping your wiring clean and organized (in video at 06:59).

Conclusion

This lesson provides a simple yet powerful trick to expand the capabilities of your Arduino board. By redefining digital pins as power sources, you can solve the common issue of limited 5V and GND connections. Remember the critical 20mA limit per pin, and you can safely power a variety of sensors and small modules in your future projects.

Chapters

  • [00:00] Introduction and Overview of 5V Pins
  • [00:54] Understanding the ICSP Header and SPI Pins
  • [01:55] Current Limitations Based on Power Source
  • [03:30] Digital Pin Current Limits and Use Cases
  • [04:51] Code Explanation for Creating Extra 5V and GND
  • [06:05] Wiring Demonstration with an LED
  • [06:59] Scaling Up with a Breadboard Power Distribution

Images

Arduino UNO R3 compatible development board
Arduino UNO R3 compatible development board
538-Lesson 7: Getting Additional 5V and GND from Arduino
Language: C++
/*
 * S01-07 Additional 5V or GND pin.
If your Arduino board voltage is 3.3V, then we will get 3.3V and GND pin

 * Arduino Sketch to give you extra 5V pin from Arduino
  Please watch video instruction here https://youtu.be/pQKrl5Kpi50
 This code is available at http://robojax.com/course1/?vid=lecture07

with over 100 lectures Free On YouTube. Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339 
 * Written by Ahmad Shamshiri for Robojax, robojax.com http://youtube.com/robojaxTV
 * on Jan 01, 2019 at 08:54 in Ajax, Ontario, Canada
 * 
 */
#define VCC2  5 // define pin 5 or any other digital pin here as VCC2
#define GND2  2 // define pin 2 or any other digital pin as Ground 2

void setup() {
    
  pinMode(VCC2,OUTPUT);//define a digital pin as output
  digitalWrite(VCC2, HIGH);// set the above pin as HIGH so it acts as 5V

  pinMode(GND2,OUTPUT);//define a digital pin as output
  digitalWrite(GND2, LOW);// set the above pin as LOW so it acts as Ground  

}

void loop() {
	//Robojax Step By Step Arduino Course http://robojax.com/L/?id=338


}

Files📁

No files available.