Created
September 20, 2017 10:03
-
-
Save Jolievw/9dfde2c7049505469d5549e079e08db1 to your computer and use it in GitHub Desktop.
This file contains 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 cs_4_2 = CapacitiveSensor(A4, A2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired | |
int threshold; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() | |
{ | |
long reading; | |
for(int i = 0; i < 4; i++) { | |
reading = reading = cs_4_2.capacitiveSensor(30); | |
delay(5); | |
} | |
reading = reading /4; | |
if(reading > THRESHOLD) { | |
digitalWrite(LED_BUILTIN, HIGH); | |
} else { | |
digitalWrite(LED_BUILTIN, LOW); | |
} | |
Serial.println(reading); | |
delay(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment