#include<CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4,2);
const int ledPin = 12;
int threshold = 1000;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
long sensorVal = capSensor.capacitiveSensor(30);
Serial.println(sensorVal);
if (sensorVal > threshold) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(10);
}
I'm practicing coding on the arduino. Currently at beginner project 13: touchy feely lamp.
After setting up the circuit and running the code.
I notice that the led are blinking instead of fully turn on.
The sensorVal is about 200++ when not touch.
By looking at the Serial mornitor, the sensorVal ranges from 200++ to about 2000++ when in contact with the touch. This will cause the led to blink as it ranges between 1000. The led should not be blinking.
May I now what may be the reason for this to happened? I've check all the connections and they are firmly connected.