I have a floating pin issue on D2 which is causing an interrupt to trigger at random times. I have tried using the firmware pull down resistor ( pinMode(TouchPin, INPUT_PULLDOWN); ) but this does not seem to work.
I have also tried 3 wiring options to sort out the problem, of which option 3 is the only one that really works and is stable (no random triggers or triggers when touching the circuit).
I am not an electronics eng, so I am in the dark a bit.
Please could someone with the relevant skills guide me please. The code and the circuits are shown below.
const int LED_OUTPUT = D7;
const int TouchPin = D2;
const int Relay = D0;
bool lighton = false;
void setup() {
Time.zone(2);
RGB.control (true);
Serial.begin();
RGB.color(0,0,0);
RGB.control (false);
pinMode(LED_OUTPUT, OUTPUT);
pinMode(TouchPin, INPUT_PULLDOWN);
pinMode(Relay, OUTPUT);
digitalWrite(LED_OUTPUT, LOW);
delay (60000);
SYSTEM_MODE(MANUAL);
RGB.control(true);
RGB.color(0,0,0);
attachInterrupt (TouchPin, switchLight, RISING);
}
void loop () {
if ((Time.hour() == 19 && Time.minute() == 00 && Time.second() < 5) && ! lighton) {
switchLight();
delay (5000);
}
delay (1000);
}
void switchLight () {
static volatile unsigned long lastInterrupt = 0;
unsigned long currentInterrupt = millis();
if (currentInterrupt - lastInterrupt > 1000) {
lastInterrupt = currentInterrupt;
if (lighton) digitalWrite (Relay, LOW);
if (! lighton) digitalWrite (Relay, HIGH);
lighton = not lighton;
digitalWrite(LED_OUTPUT, lighton);
}
}
The circuit options are: