Brand New Arduino Ethernet Analog Pins

Hello!

Yesterday a wrote a code to my arduino ethernet board and everything works fine.
But today all of analog pin get a horrible value...

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(0));
  delay(250);
}

The result always between 1023 and 940.. I don't know why because nothing connected to the board!

Please help me!

Thanks a lot.

I don't know why because nothing connected to the board!

So, connect something.
Why would you want to read something from an unconnected pin?

Because if it don't get any voltage need to sign to me.

Because if it don't get any voltage need to sign to me.

Again, please?

Does this help?

From http://arduino.cc/en/Reference/AnalogRead:

If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

In other words, if nothing is connected, the value returned will be random. That's normal. The pin is floating, so it has to return something.

myDuino:
Because if it don't get any voltage need to sign to me.

Didn't we answer that already today? Anyway I'm not sure what this means. Maybe an unconnected input to the keyboard?

So my project is the following:

I have an alarm system and I connect the zones response led (wich is 1,3 volt work) parallel to my arduino analog pins.
My code looks like this:

...
int anHeight=50;

  radars="";
  for (an = 0; an < 6; an++){
    if (analogRead(an)>anHeight){
      radars+="1|";
    }else{
      radars+="0|";
    }
  }
  int x=alarm('radars',radars);

Radars string I post to a web server database and I have a monitor web page to visit my alarm status.

Yesterday I get always 0|0|0.... Today just 1|1|1... And i don't know why

int x=alarm('radars',radars);

Single quotes?
What's that doing?

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0xDE, 0xBF };
IPAddress ip(192,168,2,200);

int an;
int pin;
boolean _intArray[10];
int _timeArray[10];
String radars;
boolean emailIt=true;
int anHeight=50;
int resp;
int isOnlineTime=0;

void setup() {
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  for (an = 1; an < 6; an++) {
    _timeArray[an]=0;
    _intArray[an]=true;
  }
  for (pin = 2; pin < 4; pin++) {
    pinMode(pin, INPUT);
    _timeArray[pin+5]=0;
    _intArray[pin+5]=true;
  }
  for (pin = 5; pin < 9; pin++) {
    pinMode(pin, OUTPUT);
  }
}

void loop() {
  if (analogRead(0)>anHeight && emailIt==true){
    for (an = 1; an < 6; an++){
      if (analogRead(an)>anHeight){
        if (_intArray[an]==true){
          String myString = String(an);
          int z=alarm('email',myString);
        }
        if (3<_timeArray[an]){ 
          _intArray[an]=true;
          _timeArray[an]=0;
        }else{
          _intArray[an]=false;
          _timeArray[an]++;
        }
      }
    }
  }
  radars="";
  for (an = 0; an < 6; an++){
    if (analogRead(an)>anHeight){
      radars+="1|";
    }else{
      radars+="0|";
    }
  }
  int x=alarm('radars',radars);
}

char alarm(char typ1,String zone){
  EthernetClient client;
  String data;
  data="";
  data+="";
  switch (typ1){
    case 'email':
      data+="zone=";
      data+=zone;
    break;
    case 'radars':
      data+="radar=";
      data+=zone;
    break;
  }
  Serial.println(data);

  if (client.connect("_________.com",80)) {
    client.println("POST _________________.php HTTP/1.1");
    client.println("Host: __________________.com");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("Connection: close");
    client.println(data.length());
    client.println();
    client.println(data);
  }
  delay(25);
  client.stop();
}

Here is the complete code, but the question doesn't change!

I advise against using variable names with a leading underscore. Why do it?

char alarm(char typ1,String zone){
  EthernetClient client;
  String data;
  data="";
  data+="";
  switch (typ1){
    case 'email':
      data+="zone=";
      data+=zone;
    break;
    case 'radars':
      data+="radar=";
      data+=zone;
    break;

typ1 is a char, which is one byte long. There is no way it is going to have 'email' or 'radars' in it.

data="";
  data+="";

Belt and braces?

Ok thank you for the adveices, I will coretct the fails, but now i don't know how can I measure the 0 volt (standby state of alarm zone response led)

int _timeArray[10];
for (an = 1; an < 6; an++) {
    _timeArray[an]=0;
    _intArray[an]=true;
  }

You're only setting five of the ten elements of the array "_intArray" to "true" - is that what you intended?
(_timeArray already was all set to zero so you didn't need to do that at all)

but now i don't know how can I measure the 0 volt

I don't understand your question.
Are you saying you have some open switch connected to an analogue input without a pullup or pulldown?

myDuino:
So my project is the following:

I have an alarm system and I connect the zones response led (wich is 1,3 volt work) parallel to my arduino analog pins.

If the Led (zone) not active, the current voltage is zero, so I need to post an 0| string to my webserver.

So my code looks like this:

  int anLow=200;
  int anHeight=290;

  for (an = 0; an < 6; an++){
    if (anHeight>analogRead(an)>anLow){
      radars+="1|";
    }else{
      radars+="0|";
    }
  }

It response 0|0|0... but how can I be sure that the random numbers does not fall into this range?

if (anHeight>analogRead(an)>anLow){

Are you aware of the left-to-right evaluation rule?
Should there be two comparisons and an "&&" there instead?

It works like this too.. But not this is the question.

myDuino:
Ok thank you for the adveices, I will coretct the fails, but now i don't know how can I measure the 0 volt (standby state of alarm zone response led)

If you are getting random voltages when the alarm output is 0, add a high value pull down resistor (maybe 50k or 100k) with one end of the resistor connected between the alarm output and the arduino analog input pin, and the other end of the resistor connected to the arduino ground.

if (anHeight>analogRead(an)>anLow){

myDuino:
It works like this too.. But not this is the question.

It should be. That won't do what it looks to you like it is doing. Fix it, I suggest.