Go Down

Topic: Capacitive Sensor not working (Read 406 times) previous topic - next topic

HunkyMcHunkins

Jun 14, 2019, 04:46 pm Last Edit: Jun 14, 2019, 04:57 pm by HunkyMcHunkins
Hi!

I've been using this code on The Things Uno to light up a LED when I touch a coin and it has worked perfectly fine:
Code: [Select]
#include <CapacitiveSensor.h>

#include <CapacitiveSensor.h>
CapacitiveSensor cap = CapacitiveSensor(4,2);

const int ledPin = 10;
const int threshold = 80;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  long sensorValue = cap.capacitiveSensor(30);

  Serial.println(sensorValue);

  if (sensorValue > threshold) {
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
  }

  delay(20);

}


But when I'm switching board to the Rev2 and changed board and port on the IDE I'm not getting the same response. Is there anything I don't know that I should?

Thank you for your help!

HunkyMcHunkins

Bump. The values on the Serial monitor shows "-2"

Go Up