Heidi Wang

Input Output

Goal

Schematic

schematic

The sensor is a photocell, with power provided by the 5V pin and analog reading through pin A5.

The output device is made up of 3 LEDs.

Each diode is wired to its own pin providing power through analog write.

The calculation below yielded the minimum resistances needed for each LED.

Calculation

Red and Green LEDs:

calculation for resistance needed for Red and Green

Blue LED:

calculation for resistance needed for Blue

Resistor in Voltage Divider with Photocell:

The calculation below yielded the target resistance for R2 in the voltage divider with the photocell as R1.

The photocell was measured to have a resistance of around 38 Ohms in the brightest environment and around 300k Ohms in the darkest environment for its intended operating range, so the needed resistance for R2 was calculated with around halfway brightness resulting in around half of voltage in as voltage out.

calculation for resistance needed for non-sensor resistor in voltage divider

220 Ohm resistors were used for all 3 LED resistors.

For the photocell, a resistor with the calculated resistance of 100k Ohms was used.

Circuit

circuit

Firmware

link to code file

Notes

  1. In this voltage divider, the variable resistor is currently R1 and R2 is constant, and the sensor value is inversely mapped to the output value in the firmware.

    If the variable resistor is R2 and R1 is constant, then the sensor value must be directly mapped to the output value in the firmware to achieve the same behavior.

    For example, if Vin=5, R2=100k:

    • If R1=5k:
      • Vout = R2/(R1+R2)*Vin = 100k/(5k+100k)*5 = 4.76V
    • If R1=200k:
      • Vout = 100k/(200k+100k)*5 = 1.67V

    However, if the values for R1 and R2 are switched, ie if R1=100k:

    • If R2=5k:
      • Vout = 5k/(100k+5k)*5 = 0.24V
    • If R2=200k:
      • Vout = 200k/(100k+200k)*5 = 3.33V

    This shows that if the variable and constant resistors are switched, then the mapping of input to output value must be inverted to achieve the same behavior.

  2. voltage over time for voltage divider
  3. map() for 10bit read to 8bit write is used as map(value, 0, 1023, 0, 255). 16bit is 65,536, which shifted 1 down to start at 0 instead of 1 is 65,535, so map() for 16bit read to 10bit write would be used as map(value, 0, 65535, 0, 1023).