1

Basically, my circuit contains only 1 resistor(like the basic LED circuit).This is my circuit and my code

I tried to know what is the actual voltage of digitalWrite(High). I don't understand why the value of analogRead does not fix to 1023 but instead decreases when I decrease the value of the resistor. Moreover, the value comes to zero when my resistor value comes to 1 ohm. Really appreciate any helps here.

2

2 Answers 2

0

A digital output pin can only provide a specific current: 20mA max recommended, 40mA absolute max. When you get near and over that these values the voltage will go down, as the internal driver hardware cannot provide enough current to hold the voltage.

With the resistor you are providing a direct current path to ground. For high values of R it doesn't make much different (as the current through the resistor to ground is lower than the max current of the digital pin drivers max current). When you lower R the current through it to ground gets bigger. Thus the digital pin driver has to provide more current to hold the voltage. When it gets too low the driver cannot provide enough current, the voltage will fall.

With R at 1Ohm you are basically shorting the digital output pin to ground as 1Ohm really isn't much resistance. At 5V (which is the output voltage of the Uno) you will get U/R = 5V / 1 Ohm = 5A current through it. The driver cannot provide this. In real life the pin driver would most likely be killed by this current draw.

2

As a complement to chrisl's answer, it is worth noting that the datasheet of the microcontroller (here the ATmega328P), under a section named “Typical characteristics”, has a subsection named “Pin Driver Strength”. This subsection has some typical voltage-vs-current curves showing that:

  • the curves are not quite linear, although the non-linearity is small at 5 V supply voltage
  • they depend strongly on temperature
  • near ambient temperature, the pin behavior is close to an ideal voltage source in series with a 25 Ω resistor.

The curves go only up to 20 mA, as the behavior for higher currents is not characterized.

From this, you can guess the voltage reading you expect. For example, if you use a 470 Ω resistor (which is safe), the output pin resistance and the external resistor make a voltage divider. The expected voltage you read is

(5 V) × (470 Ω) / (470 Ω + 25 Ω) = 4.747 V

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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