Hello! We have followed the hardware schematic and code for the Touchy-Feely Lamp, and have not been able to turn on the LED nor read a different sensor value when using the suggested setup. We have exchanged all of our hardware in case we were working with a faulty piece, but this did not help. We also tried putting different thresholds into the code ranging from 1-10,000.
In trying to figure out what was wrong, we unplugged the wire that is connected to pin 2 from where it was connected to the 1 Mohm resistor. When we touched the end of this wire, the circuit worked as expected.
We have attached our a picture of our original circuit (made with Nano Every) and code. Please help us figure out why it is not working as it should according to the project instructions.
//Import a library from the Arduino folder
#include <CapacitiveSensor.h>
//Select the two pins that will act as a capacitor
CapacitiveSensor capSensor = CapacitiveSensor(4,2);
//Insert the minimum value provided by the sensor to detect the touch
int threshold = 1;
const int ledPin = 12;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
//Read the sensor value
long sensorValue = capSensor.capacitiveSensor(30);
Serial.println(sensorValue);
//Touch detected
if (sensorValue > threshold) {
//Turn on the led
digitalWrite(ledPin, HIGH);
}
//Touch undetected
else {
//Turn off the led
digitalWrite(ledPin, LOW);
}
//delay(10);
}
