Last active
December 10, 2025 13:12
-
-
Save psychemist/4667b69cbc236d2f67fb1874c509661c to your computer and use it in GitHub Desktop.
Arduino Starter Project 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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