Problems driving a digital input from an AC source

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

Yes the silly mistake is trying to read a voltage that is in effect floating. You have no referance or common signal point.
What you need to do is to use an opto isolator.

I'm not quite sure I understand the problem. You realize, of course, that the optoisolator will be switching on and off on each half cycle of the AC signal, when applied.
Edit: is the PS2505 properly grounded (not shown on the schematic)?

Grumpy_Mike:
What you need to do is to use an opto isolator.

I think that's what the PS2505 is....

http://www.mouser.com/ProductDetail/CEL/PS2505-4-A/?qs=OIb2OeIvLKt2Rv6mKKHbmg==

Grumpy_Mike:
Yes the silly mistake is trying to read a voltage that is in effect floating. You have no referance or common signal point.
What you need to do is to use an opto isolator.

I forgot to add in the schematic that the Arduino is supplying the +5V and GND rails, so if I understand this correctly, the input is not floating.
Isn't the PS2505 an optoisolator/optocoupler? My research seems to indicate the terms are interchangeable.

jremington:
I'm not quite sure I understand the problem. You realize, of course, that the optoisolator will be switching on and off on each half cycle of the AC signal, when applied.
Edit: is the PS2505 properly grounded (not shown on the schematic)?

I initially tried a small smoothing capacitor (0.022uF) both in place of and in parallel with the 470? resistor with no change.

I just tried a larger smoothing capacitor (47uF), and it works perfectly now!

Have a look at this thread:

http://forum.arduino.cc/index.php?topic=171399.0