0
\$\begingroup\$

I've been thinking about a question and haven't been able to find an answer. The question is that:

For instance, an Arduino has a 5V output pin to feed any electronic component. When you code something as "giving nonzero voltage to the output pin", the Arduino provides power to the 5V output pin.

Here, my question is how does this work? It's not a mechanical process, but how can the code control voltage or current?

Someone told me that the transistors do that, but how? How does the code become energy?

Thanks for your time

\$\endgroup\$

closed as too broad by Transistor, winny, Chris Stratton, R Drast, Maple Aug 29 '18 at 20:58

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ The "5v output pin" of the Arduino is not controllable. The signal pins are controllable, but they are only designed to source tiny amounts of power for exchanging information. They should not be used to power things with the exception of those having very little draw, such as low current LEDs, piezo elements, etc. \$\endgroup\$ – Chris Stratton Aug 25 '18 at 22:47
  • 1
    \$\begingroup\$ There's zillions of tiny electrical switches inside the main chip of the Arduino, just some of them are connected to the outside of the chip... \$\endgroup\$ – immibis Aug 26 '18 at 9:45
  • \$\begingroup\$ Thanks for your replies. The question was asked by my friend for me. But unfortunately i couldn't take an enough answer. it's my intention to learn the basics of the electronic components i'll try to explain my question with an example. it suppose that you launched a flashlight application on your phone. Actually if you touch the flashlight icon you are writing any code. So, how is it that a code consisting of letters provide current flow on electronic card or components ? How do the commands we give with letters or numbers work on the cpu ? \$\endgroup\$ – Mert Sönmez Aug 27 '18 at 0:49
  • \$\begingroup\$ This leads to a very philosophical question: What is code? \$\endgroup\$ – immibis Aug 27 '18 at 1:10
  • \$\begingroup\$ Code is the state of switches, of course :-) Quite seriously, code is stored in electronic systems as the state of little switches. Controlling bigger switches is just... little switches controlling big switches. \$\endgroup\$ – Chris Stratton Aug 27 '18 at 2:26
2
\$\begingroup\$

I think you are not aware that just by executing any code, there are tiny switches inside the CPU flipping, making current flow. That's how the CPU works internally.

On CPU level, code is just a preset arrangement of tiny switches to start with as soon the reset switch is released.

The difference between any code and code that gives nonzero voltage on an output pin is just that there's an additional switch flipped which leads to an output pin rather than only those which are connected only internally.

\$\endgroup\$
  • 2
    \$\begingroup\$ I just want to add that a CPU is a device that is almost entirely made of switches, and an incredibly large number at that. As of 2017 there was a single chip processor with 19.2 billion gates. \$\endgroup\$ – K H Aug 25 '18 at 23:43
  • \$\begingroup\$ So, tiny components on CPU represent any code and the way of executing themselves are letting the switch on and off? Did I understand right? \$\endgroup\$ – Fatih M. Aug 26 '18 at 2:08
  • 2
    \$\begingroup\$ The tiny components on the CPU are called transistors. If you have a CPU with integrated program memory —as the AVR microcontroller used on the Arduino is— there is a special sort of those transistors put into an array —a Flash ROM, short Flash — on that very same chip. They can be set on/off from outside and retain their state even when the power is cut. Those transistors contain the software as switches flipped on or off. The other "normal" transistors on the CPU get these states copied one instruction after another, along with the data from the inputs of the chip. \$\endgroup\$ – Janka Aug 26 '18 at 2:56
0
\$\begingroup\$

The code does not become energy. The code instructs the Arduino how to behave, just as written instructions given to a person would. Except the Arduino is much less intelligent than (some) people.

Inside the main Arduino chip are lots of transistors that switch on and off according to these instructions. A transistor is a solid-state (i.e. no moving parts) component that will allow power to flow - or not allow it - depending on the state of its input. So, when you write code, you are essentially giving these transistors instructions.

If you don't understand what transistors are, it's probably best to think of them as a controllable valve, such as may control the flow of water.

Some of these transistors are connected to the output pins of the Arduino. When they are instructed to let power flow, power is allowed to reach the output pins and will power anything connected there.

As mentioned in comments above, the amount of power capable of reaching the output pins is very small. You can use it to power low-current devices like LEDs (with a suitable resistor!), but if you draw too much power you will kill the Arduino.

To power high-current devices, you would use a transistor of your own.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.