How to get only 1,5 Volts output by using PWM

Hi everyone,

I need to make a really simple circuit. I am going to light a LED up but LED works between 1,2 - 1,5 volts, so I need to get an output from Arduino and set the output up as only 1,2 volts.

I do not want to use any resistors or something else, I aim to get it via coding.

Will anyone help me by showing an example code or something like that?

Thanks whoever interests.

If you connect an LED to a port output pin without using a resistor, you will burn out the port pin, sooner or later.

Use a resistor, 150 Ohms minimum on a 5V Arduino.

PWM does not reduce the output voltage, only the time during which the voltage is present.

But it does not make sense as far as I know that if you get it the exact voltage like 1 or 2volts, why it would burn the pin out ?

I will do it, connect a 150ohm resistor but it won't prevent burn the led. I still need to reduce any PWM pins' voltage.

Thank you

fkydln:
I still need to reduce any PWM pins' voltage.

You can't. Believe me.

I still need to reduce any PWM pins' voltage.

That is the purpose of the resistor. Look up Ohm's law.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

Can you tell us your electronics, programming, Arduino, hardware experience?

These links may help you understand.

[https://www.arduino.cc/en/Tutorial/Fading[/iurl]

](https://www.arduino.cc/en/Tutorial/Fading)Fade an LED: Arduino Basics - Hackster.io

You need to understand that the PWM is 5V pulse and you need the resistor to limit the current when 5V is output.

The fading takes place because of the ON/OFF of PWM, the longer it is ON compared to OFF the brighter the LED will be, and vice versa.

It is standard practice to include a current limit resistor, rather than try and make the output voltage exactly what the LED is rated at.

Not all LEDs are the same, even if they are from the same batch.

Also if you have excessive current flowing through the LED from the Arduino, not only will you destroy the LED but the output of the Arduino, as it has a maximum current rating of 40mA.

Tom... :slight_smile:
PS. Why don't you want to use a resistor?

I do not want to use any resistors or something else, I aim to get it via coding.

You can't do everything in software... Some things take special hardware.

An analogy - You can't dim a light in your house without a dimmer. A regular light switch only goes on & off and you can't control it with your computer. Or, you can't get sound of a computer without a soundcard.

I will do it, connect a 150ohm resistor but it won't prevent burn the led. I still need to reduce any PWM pins' voltage.

The voltage gets divided among the series components and the voltages will sum-up to 5V.* The "magic" of LEDs is that they are non-linear (their resistance changes with voltage) and with a resistor the voltage "falls into place".

The resistor limits/controls the current. Resistance is the "resistance to current flow". More resistance = less current, less resistance = more current (Ohm's Law).

  • The output voltage may not be exactly 5V, but the series voltages must sum to the total voltage.

fkydln:
I am going to light a LED up but LED works between 1,2 - 1,5 volts, so I need to get an output from Arduino and set the output up as only 1,2 volts.

You drive a LED with CURRENT, not with voltage.

If you drive a fixed current through a LED, then as a result you have a volt drop across the LED.

A resistor in series with the LED is an easy way to set LED current.

If you power the LED/resistor from a 5volt Arduino pin (PWM or not), then you can calculate LED current if you know Vf (working voltage) of the LED. In your case about 1.25volt (infrared LED or opto coupler?).
So 5-1.25= 3.75volt is going to drop across the resistor.
If you choose a 220ohm resistor, then you will have 3.75/220= ~17mA LED current.
Leo..

fkydln:
I need to make a really simple circuit. I am going to light a LED up but LED works between 1,2 - 1,5 volts, so I need to get an output from Arduino and set the output up as only 1,2 volts.

As long as the voltage is >Vf, your LED will act like a short.
As long as the voltage is <Vf, your LED will block.
This of course is a simplification of the reality which is less black and white (or block and short in this case) but that's roughly how an LED works and why your idea won't work to begin with.

You can use pulse width modulation and varying frequencies to generate a given voltage via a digital pin using a simple low pass filter. However, this requirement rules that solution out:

I do not want to use any resistors or something else, I aim to get it via coding.

6v6gt:
You can use pulse width modulation and varying frequencies to generate a given voltage via a digital pin using a simple low pass filter.

Even so you won't be able to drive an LED with such a filtered output. That would need a buffer, such as an OpAmp in unity gain, and that still doesn't solve the current issue of the LED.

fkydln:
. . .
I will do it, connect a 150ohm resistor but it won't prevent burn the led. I still need to reduce any PWM pins' voltage.
. . .

You can vary the brightness of the LED (fading etc.) with PWM (but not the voltage, hence you need the resistor).
Are you trying to achieve a concrete goal or is this a school exercise ?

The fading takes place because of the ON/OFF of PWM, the longer it is ON compared to OFF the brighter the LED will be, and vice versa.

Worth mentioning - just to make life more difficult, the dimming will be non-linear...!

The simplest way to get a smooth fade from 0-255 is to use a byte lookup table that corrects the LED brightness to match the flat-slope of the 0-255 span.

I do not think it feasible to do without resistors and stuff. At the very least you'll need a capacitor. Try looking up 'audio capacitor, 10 Volts, 100 Microfarad'. You blip that with 5V not ten, often enough and briefly enough to stay near enough to your desired LED voltage. To protect your Arduino from damage dumping into an empty capacitor, you should have a resistor. I'd use 3.3kOhm, expecting 1 mA steady and less than 2mA during the initial turn on surge. If 1mA is not enough for the brightness of LED which you want then use either an NPN or NFET below the LED and 10 kOhm from the arduino to its base or gate. The capacitor still goes parallel with your LED. Further improvements from here are possible.

PWM never does 1.5V at the arduino output pin; It does 0 and 5 V and spends about a third of its time at 5 V.

At the very least you'll need a capacitor.

No, at the very least you need a RESISTOR.

Please do not confuse beginners with misinformation.

ad2049q:
It does 0 and 5 V and spends about a third of its time at 5 V.

Rubbish. The amount of time it spends at 5V is determined by the value you use when you call the analogWrite function.

@OP - Like the others have said a pure software is not possible.

I am going to light a LED up but LED works between 1,2 - 1,5 volts, so I need to get an output from Arduino and set the output up as only 1,2 volts.

Basically you are misunderstanding how an LED works, you don't put a voltage on it to drive it. When it is driven by the recommended current then a voltage of 1.2 to 1.5 volts will appear across it, not the other way round.