Pages: [1]   Go Down
Author Topic: Sending an email when an LED turns on  (Read 569 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to utilize the email client example (http://playground.arduino.cc/Code/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
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 67
Posts: 3679
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* photo.JPG (97.74 KB, 640x480 - viewed 18 times.)
« Last Edit: July 16, 2013, 12:15:21 pm by incmike » Logged

Pages: [1]   Go Up
Jump to: