How does Arduino convert specified input voltage to required output voltage?

Consider the example where I use a 9V input battery. How does it give supply to a LED connected to it? How does the voltage vary according to our code?

our code

What code?

Have you looked through the forum for a section for your language?

gastlyyoi:
Consider the example where I use a 9V input battery. How does it give supply to a LED connected to it? How does the voltage vary according to our code?

Your topic says "How does Arduino convert specified input voltage to required output voltage?"

The meaning is unclear. Do you mean that you're powering the arduino with a 9V battery, and you want to use one of the arduino output pins to output (generate) a desired voltage (for driving an LED circuit)?

I just deleted another post with this exact same content.

Don't do that again.

I'll assume you have an Arduino Uno, and you hooked up one of those little rectangular 9 volt batteries with a cable that clips onto the battery terminals on one end, and to the barrel jack on the Arduino board on the other. Then you ran the first program "blink.ino" and wondered how the voltage went from the 9 volt battery to the on-board LED, which runs on maybe 2 volts, right?

If so, here's what happens to the voltage:

The battery jack goes to a voltage regulator, which converts the 9 volts to 5 volts, which runs the Arduino's processor and all of its pins. If you feel the area of the board where the battery plugs in, it will be warm. The regulator turns the extra 4 volts into heat.

From the pin, pin 13 in this case, a light emitting diode drops the voltage (changing the voltage into light this time, instead of heat) and some voltage gets passed through. The specifications for any LED say how many volts are needed to make light, so then subtract this number from the supplied voltage to find out how much voltage is left. In the case of a typical small, red LED, about 2 volts are used by the diode, and 3 volts get by it.

Now if you let that 3 volts run right into the ground, the current will get very high, and the LED will generate heat, lots of it! To prevent the LED from going over the operating current, put a resistor in line with it. You can calculate the exact resistance needed using Ohm's law and the voltage passed by the diode, Or just guess. I use a 330 resistor for a bright LED, and 1K ohm for a moderately dim LED.

Experiment with a battery, LED and some resistors. When using an Arduino, you need to be certain that the current stays at or below 20mA.

gastlyyoi:
Consider the example where I use a 9V input battery. How does it give supply to a LED connected to it? How does the voltage vary according to our code?

Taking the Uno as an example, 9V on the Vin or the barrel jack feeds a 5V linear voltage regulator
that outputs 5V for the rest of the board. The Arduino runs at 5V.

If you connect an LED you also must use a series resistor to limit the current that flows as 5V will
overload a directly connected LED and the Arduino output pin too.

LEDs are not controlled by voltage, PWM is used via analogWrite, which alters the duty cycle.