Heidi Wang

Libraries and Capacitors

Goal

Schematic

schematic

The capacitive surface for the sensor is the end of a wire.

The capacitor and ground for the sensor are the body of the person interacting with the circuit.

Resistance of 1 MOhm was chosen for the capacitive sensor based on the library guidelines for resistor choice to activate on touch contact.

Circuit

circuit

Firmware

link to code file

Notes

  1. voltage over time for voltage divider
  2. We can address erroneous readings by only changing the output if the reading was not an error code.

    CapacitiveSensor error codes are -1 or -2, and >= 0 otherwise.

                
      // read in the capacitive sensor value over 30 samples of measurement
      long sensorValue
    
      // do not change the output if the read value was an error code
      if (sensorValue >= 0) {
        // rotate the servo depending on whether the sensor value passed the threshold
        if {} else {}
      }
                
              
  3. If the measurement is noisy and deviates from the true measurement by +/- 10%, we can take multiple readings and average them before each adjustment to get a smoother output.

                
      // average 5 readings of the capacitive sensor value over 30 samples of measurement
      long sensorValue = 0;
      for (int i = 0; i < 5; i++) {
        sensorValue = (sensorValue*i + cs_4_2.capacitiveSensor(30))/(i+1);
      }