Voltage divider for photoresistor without any other components

Hi, you want advice from genius? :slight_smile: You can create voltage divider from internal pullup resistor and photoresistor! Set digital pin as input pullup by pinMode (D5, INPUT_PULLUP), then connect photo resistor between ground and A0 and connect D5 to A0. Then measure A0 with analogRead(A0). There you go!

void setup() {
  // put your setup code here, to run once:
  Serial.println("Photoresistor test");

  pinMode (D5, INPUT_PULLUP);
  Serial.println("Pin D5 pulled high");


void loop() {
  // put your main code here, to run repeatedly:

  int sensorValue = analogRead(A0);
  Serial.println("Analog: "+String(sensorValue));


Nice trick ..But you may not get the best range across the analog input depending upon the resistance of your sensor and the light levels to be measured .

Example - if the sensor goes from 1k to 10k , you will get a better range of voltages with a 5k pull-up than say an input pull-up of 100k plus .

The value of the pullup resistor is unknown, and has very wide tolerance.

Surprise: there is a pullup resistor on the analog inputs of most AVR-based Arduinos, so no need to use another pin. When that resistor is inadvertently enabled, it can lead to large, mysterious errors in the ADC reading.

Thanks for the accolade. So you haven't been reading my posts, have you?

Apparently not, but I don't really blame you. :grinning:

The nominal value of the internal pullup "resistor" is 47k. I really do not know to what extent it differs from device to device or from pin to pin in a given device. Perhaps I should check this out. Has someone actually measured it? I better go find a Nano and a "terminal adapter" ...

Aliexpress example

Since pins A0 to A5 on an ATmegaxx8 are actually digital pins with an additional analog function, you can simply set them to INPUT_PULLUP and use their own internal pullup. A6 and A7 on the SMD version as in the Nano and Pro Mini are not digital pins so you do have to provide some other pullup.

The internal pull-ups are not linear resistances, they are pFETs with long thin channels,
which have non-linear resistance - so this trick is no use for measurements, just for
thresholding and rough and ready situations. Only in analog chips would you see actual resistors
as they are very bulky due to the low resistivity of doped silicon, typically having lots of folds
and meanders to get to suitable resistances. A FET channel is the cheats way to have resistance
on a CMOS chip.

Well now, the context here is for use with a LDR ("photoresistor").

The internal pullup is just fine for this purpose if its effective "resistance" (I deliberately put this in quotes) matches the situation and it often will, particularly for a low light threshold.

The non-linear behaviour of the pull-up tends toward a not-really-constant current source which is probably better than a resistor for the purpose and a LDR will always require calibration of the code to the particular situation.

Wow - genius! Converting the curent from the photodevice to a voltage with a resistor is astonishing.

However Georg Ohm has beaten you to this discovery (1827)

Hi, you want advice from genius? :slight_smile:

I refuse to use LDRs once I found out they have some sort of AI or memory effect for history of illumination. Scary stuff. :astonished:

Just out of curiosity, what is the application for this 'genius' trick ?
What is the advantage ?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.