I'm working on a project where I'm simply reading the amount of light emitting from an IR led with an IR sensor.

For some reason, after the IR led reaches full luminosity, it takes a minimum, whopping 500ms for the IR sensor's readings to drop from 65536 (16 bit resolution) to ~0.

This is my circuit:


simulate this circuit – Schematic created using CircuitLab

Figure 1. OP's schematic redrawn by @Transistor (for verification).

This is my code:

#include <ADC.h>

ADC* adc;

int ir_led = A8;
int ir_sensor = A9;

void setup() {
    pinMode(ir_led, OUTPUT);
    pinMode(ir_sensor, INPUT);


void loop() {
    digitalWrite(ir_led, HIGH);
    delay(10);  // wait for ir led to reach full luminosity

    int start_time = millis();
    digitalWrite(ir_led, LOW);
    while (adc->analogRead(ir_sensor) > 50); // wait for LED to turn completely off: a reading of 50 out of 65536 is equivalent to 0 with environmental noise
    int end_time = millis();
    Serial.print("DELAY TIME (ms): ");
    Serial.println(end_time - start_time);


void configureADC() {
    adc = new ADC();

    adc->setAveraging(16); // set number of averages
    adc->setResolution(16); // set bits of resolution

    adc->setAveraging(16, ADC_1); // set number of averages
    adc->setResolution(16, ADC_1); // set bits of resolution
    adc->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED_16BITS, ADC_1); // change the conversion speed
    adc->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED, ADC_1); // change the sampling speed


Serial output:

enter image description here

Plotting the sensors readings:

enter image description here

Some delay is expected, but 500ms does not make sense. Can someone help me figure out where this delay is coming from and why?

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Voltage Spike
    Jun 8, 2020 at 2:37

1 Answer 1


Your problem is for your Opamp. As I see, your RC value is 100nF and 1MOhms is 0.1 seconds, and your plot is a nice 1/0.1s+1 plot. So everything is OK based on your circuit. if you want to increase speed, lower C or R to get a better speed. Your 500 ms delay is a 5 time of time constant of this circuit, which is also shows me that it's a first order transfer function. your exact equation in time based system is 1 - e^(-t/RC) where R and C is your capacitor and resistor in your Opamp.

  • \$\begingroup\$ Since I obviously would want to fastest possible response time, is there a minimum or optimal capacitor and resistor value that I should choose? \$\endgroup\$
    – Ietpt123
    Mar 29, 2020 at 0:05
  • \$\begingroup\$ @letpt123 In that case, remove capacitor, or simply reduce Resistor to 1K for .1ms response time as a low value for this. \$\endgroup\$ Mar 29, 2020 at 0:20
  • \$\begingroup\$ Is there any incentive for me to keep the capacitor? Why not go lower to 1 ohm or just remove the resistor as well for the fastest theoretical response time? \$\endgroup\$
    – Ietpt123
    Mar 29, 2020 at 0:23
  • \$\begingroup\$ Your diode needs to be biased, so you need resistor and must use of a rather big one, so you can only play with capacitor, to make the circuit without delay, you can remove C but can't reduce R lower than 10K i think, where current through sensor is increased and cause sensor burning \$\endgroup\$ Mar 29, 2020 at 0:31
  • \$\begingroup\$ Okay good to know, Thank you for your help \$\endgroup\$
    – Ietpt123
    Mar 29, 2020 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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