Sending an email when an LED turns on

I am trying to utilize the email client example (Arduino Playground - Email) in order to send an email when an LED on an external circuit turns on. I am naming pin A0 as analogPin and the following code is what my void setup and loop is. The rest of the code (other than the email addresses and IPs) remains the same.

int analogPin = A0;

void setup()
{
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
delay(2000);

}

void loop()
{

int analogValue = analogRead(analogPin);
int currentVolt = analogRead(A0);
float voltage = currentVolt * (5.0 / 1023.0);

if(voltage > 1.9)
{
sendEmail();
}
}

Pin A0 is attached to the LED, so that when the LED is on, a voltage (about 1.9 volts) is present. This should be read by the arduino, and the sendEmail command should run.

The code compiles perfectly, but my problem is that whenever I upload this to the Arduino, it begins to send emails constantly, even with the LED is not lit. When I complete the circuit to turn the LED on, the Arduino stops sending emails. I cannot figure out how to get the Arduino to send only one email, as well as why it is doing the opposite of what I want it to.

If anyone could please help that would be great.

Thanks,
Mike

It's probably worth posting your circuit if you want to get to the bottom of what's going on. Alternatively, you could just fix it in software. Serial.print the values you get and observe the ranges that indicate on and off. Adjust your if test accordingly.

The circuit is pretty simple, when two leads are connected the LED turns on. I'm using this for a water level sensor. I've measured the voltage with a multimeter across the LED which is around 2 volts, which is why I chose 1.9V.

I dont think the problem is with the threshold because even when there is no voltage across the LED the Arduino will send emails constantly until I unplug it.

The problem could be that the A0 pin is floating when the led is not turned on. This can lead to wildly unpredictable values from analogRead(). I would add a pull up resistor just like you would if you were attaching any kind of button to the arduino. You can also print the voltage values to the serial monitor to get a better idea of what is happening.

I'm still a little bit confused with what you mean by adding a pull up resistor. I've attached a circuit diagram of my circuit. The connections to the arduino are from the anode of the LED to pin A0.

Also, I am using an external programmer that does not allow for me to print serial values to check what the voltage levels are. Still waiting for an FTDI cable to ship in order to do that.

Thanks again for the help

-Mike