Can you use Arduino Digital I/O pins as GND and +5v?

Hello, I saw a video on YouTube of somebody controlling and LED by plugging his components directly into the Arduino board. I tried to replicate what he did and I plugged in and LED and an IR receiver and I wrote some code but it didn’t work so I was wondering is it possible to use digital pins as GND and +5v and if so how? Code and schematically be linked below.
Please help, thank you!

I am using an Arduino UNO Rev 3
220ohm resistor
1 LED
IR receiver (not sure what model but its the typical small standard ones)

/*
 * Anode of LED connected to pin 13 via 220ohm resistor
 * Cathode of LED pin connected to pin 12
 * 
 * Pin OUT from IR reciver connected to pin 11
 * GND from IR reciver connected to pin 10
 * Vs from IR reciver connected to pin 9
 */

#include <IRremote.h>

int ledPin = 13; // + terminal of LED (dont forget to use resistor)
int ledCat = 12; // - terminal of LED
int irCat = 10; // - terminal or irreciver
int irAnod = 9; // + terminal of irreciver

int before = 0;

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  
  pinMode(9, OUTPUT); // Set the I/O pins
  pinMode(10, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  
  digitalWrite(ledCat, LOW); // Initialize the + & -
  digitalWrite(irCat, LOW);
  digitalWrite(irAnod, HIGH);

  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) { // Value recived
    if (results.value == 0x77E1BA2D) { // <- Change Value to your remotes IR code
      
      if (before == 0) { // This sets up a one click on/off button
        before = 1;
        digitalWrite(ledPin, HIGH);
      }
      else {
        before = 0;
        digitalWrite(ledPin, LOW);
      }
      // End of the one click
    }
    irrecv.resume(); // Receive the next value
  }
  delay(100); // Short delay for stability
}

Apple_Remote_Clean_Look.ino (1.3 KB)

Please explain exactly what you mean by "it didn't work".

Is it possible? Yes, as long as you don't go over the maximum current rating of the pin (absolute maximum on the Uno is 40 mA but you really shouldn't go much over 20 mA). Is there any good reason for doing so in this case? No. You're just wasting 3 pins.

Thank you for replying! So basically the LED did not light up, nor did the IR receiver work. (I tested this by serial printing "IR Received" or "LED on" and it didn't work) Though as soon as i used the GND and +5v pins it started working

And my project only uses 2 pins so using 3 extra pins is not an issue. Also it gives the parts hooked on the Arduino board a cleaner look because no extra wires are needed, just the parts them self

I tested this by serial printing "IR Received" or "LED on" and it didn't work

What?

Time to read How to use this forum
And post your schematic and code, because what you are saying makes little sense.

Hi,
OPs fritzy…
LED and IR connected directly to Arduino.png
Why do you want to power your LED and IR off the I/O pins?
Your LED will perform just a well between an output and gnd, all you are doing is wasting I/O pins.
Tom… :slight_smile:

I've used a led and resistor on 2 IO pins to do the led adjusting itself according to background light level project.
For that one the led brightness is controlled by soft-PWM and every so often the led gets use as a light sensor, but too fast to see. In bright light it's bright, in dark it's dim.

Look for led as light sensor in the Arduino Playground. Then look the Playground over, lots of things to do there.

For some reason my quote buttons won't work

Ok so starting with Grumpy_Mike:

Sorry about that mess, I was in a hurry and don't notice my lack of detail. So every time I did digitalWrite(ledPin, HIGH) or digitalWrite(ledPin, LOW) (found in the if (before) statements) I would also have Serial.println("LED ON") or Serial.println("LED OFF")

if (before == 0) {
  before = 1;
  digitalWrite(ledPin, HIGH);
  Serial.println("LED ON");
}
[code/]

Also schematic is in first post
Thanks for your help and the forum guide 




Now TomGeorge:

Yeah I will have the led anode connected to pin 13 and ground to ground. But just for this purpose I did this so I can see if I can have multiple pins acting as + and - for parts

Also it means no extra wires needed to attach the parts giving it a much much cleaner look



Now GoForSmoke:
Thank you so much I will make sure to check out the playground






Thanks everyone for your help I appreciate it very much

In that code what happens the next time you see that if statement? If you had read the link I posted you would have seen it says post all your code.

What are you expecting to see. That sensor is one for IR data and will only work with modulated IR, the modulation frequency you need depends on the exact part number of your sensor. Only a very few sensors will give a constant output in response to a modulated light, most work of the on / off pulsing of the modulated light.

And one final thing, it is a stupid idea to use the Arduino pins as power and ground, and you have no supply decoupling on that sensor. Make that two final things.

ArduinoLLC:
Hello, I saw a video on YouTube of somebody controlling and LED by plugging his components directly into the Arduino board. I tried to replicate what he did and I plugged in and LED and an IR receiver and I wrote some code but it didn't work so I was wondering is it possible to use digital pins as GND and +5v and if so how?

If you set a pin to pinMode OUTPUT and digitalWrite the pin to LOW, it is GND.

pinMode OUTPUT and digitalWrite to HIGH is equivalent to 5V, when used on a 5V board.

But please be aware of current flowing:

Absolute maximum current for Atmega controllers is 40mA.
Recommended current is 20mA per pin with Atmega controllers.

There are also other limits for the sum of current in different pin numbers.
The current limits are mentioned in the Atmega datasheet.

So when using a pin as a current source or current sink, always keep within the current limits!

You can drive LEDs when using proper in-line resistor values.

You can provide voltage for operating low-current sensors, too.

But you will get into trrouble when trying zo run DC motors or RC servos, powered from OUTPUT pins only, sooner or later. Even most 5V relay coils will draw more than 40mA, so you need a transistor to power a 5V relay coil and stay within the current limit of the Atmega pin.

Hi,

Also it means no extra wires needed to attach the parts giving it a much much cleaner look

You are still using 2 wires for power, what do you mean by cleaner look, draw your configuration in a proper circuit diagram.
How it looks in the physical world is down to how you physically construct your circuits, the way you do it is wasting resources of the UNO.

The LED and the IR only need one I/O each, thats 2 I/O.
Your config uses 5 I/O, a definite waste.

Tom.. :slight_smile:

LOL, so many pins and so few used! How can you waste?

If the habit becomes wasting pins then it can become a problem.

Also, I haven't looked lately but IIRC my IR detectors have two leads.

/*
 * Anode of LED connected to pin 13 via 220ohm resistor
 * Cathode of LED pin connected to pin 12
 * 
 * Pin OUT from IR reciver connected to pin 11
 * GND from IR reciver connected to pin 10
 * Vs from IR reciver connected to pin 9
 */

#include <IRremote.h>

int ledPin = 13; // + terminal of LED (dont forget to use resistor)
int ledCat = 12; // - terminal of LED
int irCat = 10; // - terminal or irreciver
int irAnod = 9; // + terminal of irreciver

int before = 0;

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  
  pinMode(9, OUTPUT); // Set the I/O pins
  pinMode(10, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  
  digitalWrite(ledCat, LOW); // Initialize the + & -
  digitalWrite(irCat, LOW);
  digitalWrite(irAnod, HIGH);

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) { // Value recived
    Serial.println("IR code recived");
    if (results.value == 0x77E1BA2D) { // <- Change Value to your remotes IR code
      
      if (before == 0) { // This sets up a one click on/off button
        before = 1;
        digitalWrite(ledPin, HIGH);
        Serial.println("LED ON");
      }
      else {
        before = 0;
        digitalWrite(ledPin, LOW);
        Serial.println("LED OFF");
      }
      // End of the one click
    }
    irrecv.resume(); // Receive the next value
  }
  delay(100); // Short delay for stability
}

Ok heres all the code

As i said its not dumb to give a protect a cleaner look. I don’t need to use wires, only the Arduino board and parts are required as shown in the picture. This project only uses 2 pins so I am perfectly fine use 3 more extra pins for Vs and GND.

its not letting me post the image :frowning:

ArduinoLLC:
its not letting me post the image :frowning:

This might be helpful:
http://forum.arduino.cc/index.php?topic=364156.0e microcontroller.

As I said before you have no supply decoupling on that sensor. Look at the data sheet you need a resistor and a cap on that sensor, otherwise they are not guaranteed to work.

This project only uses 2 pins so I am perfectly fine use 3 more extra pins for Vs and GND.

The thing you forget / do not know, is that it is not only the voltage and current capacity of a supply BUT also the impedance of the supply and using a pin for power and ground gives you a very crap impedance.

Ok thanks, it works now it want quite what i was looking for but it works now thank you so much everyone have a great day!

Just remember this thread when you run into problems with bigger things.
It has clues about things that do go wrong.

it works now it want quite what i was looking

That is a major problem with electronics. You can get something that works for you but you are making big mistakes.

You publish what you have done and it doesn't work for everybody, reliably and under every possible circumstance. That is why their is a lot of rubbish tutorials on the internet.

ArduinoLLC:
Thank you for replying! So basically the LED did not light up, nor did the IR receiver work. (I tested this by serial printing “IR Received” or “LED on” and it didn’t work) Though as soon as i used the GND and +5v pins it started working

And my project only uses 2 pins so using 3 extra pins is not an issue. Also it gives the parts hooked on the Arduino board a cleaner look because no extra wires are needed, just the parts them self

it should be working fine. I once did this ie connecting three pins of IR to digital pins, and they are working fine, serial output also showing data received from remote control.

it should be working fine.

No did you not read all the thread?

It is a bad thing to do because you don’t get zero volts for a logic zero, you can get anything up to 0.7V. Also you don’t get 5V for logic high.

With that skill level you should be writing Instructables.