I am working on a project that will use a 110V AC switch turning on and off as a Arduino digital input. I want to do the debouncing in hardware.
I have constructed the circuit shown below on breadboard. When the AC switch is OFF, my meter reads 4.1 V (at the output of the Schmitt trigger WRT to GND), when the switch is ON my meter reads 0.4 V (again at the output of the Schmitt trigger WRT to GND).
When I put the output of this circuit to an Arduino input using the code pasted below, the HIGH output state of the Schmitt trigger state reads correctly, but the LOW state (as measured on the meter) shows in the Serial Window as constantly fluctuating between HIGH and LOW.
My research seems to suggest a digital input threshold voltages of about 2.5V for HIGH and 2.1V for LOW states.
Am I making some sort of silly mistake?
Thanks in advance!
Here is my code
int switchPin = 10; // switchPin on digital pin 9
int val; // variable for storing state of switchPin
void setup() // begin setup
{
Serial.begin(9600); // set up serial port
pinMode(switchPin, INPUT); // setup switchPin as input
} // end setup
void loop() // start loop
{
val = digitalRead(switchPin); // read state of switchPin
if (val == HIGH)
{ // if it is high
Serial.println("HIGH"); // print HIGH
}
else // otherwise
{
Serial.println("LOW"); // print LOW
}
} // end of loop