Skip to content

Instantly share code, notes, and snippets.

@psychemist
Last active December 10, 2025 13:12
Show Gist options
  • Select an option

  • Save psychemist/4667b69cbc236d2f67fb1874c509661c to your computer and use it in GitHub Desktop.

Select an option

Save psychemist/4667b69cbc236d2f67fb1874c509661c to your computer and use it in GitHub Desktop.
Arduino Starter Project 13
#include <CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4, 2);
// set up lamp capacitance threshold
int threshold = 400000;
const int ledPin = 12;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
// sense touch and print value to serial monitor
// 30 is a good midway value for number of values to read
long sensorValue = capSensor.capacitiveSensor(30);
Serial.println(sensorValue);
// control lamp based on sensor value relative to threshold
if ( sensorValue > threshold ) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment