Go Down

Topic: Brand New Arduino Ethernet Analog Pins (Read 1 time) previous topic - next topic

myDuino

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

Code: [Select]
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.

AWOL

Quote
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?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

myDuino

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

AWOL

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

Again, please?

Does this help?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

James C4S

From http://arduino.cc/en/Reference/AnalogRead:
Quote
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.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Nick Gammon


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?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

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.
My code looks like this:
Code: [Select]
...
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

AWOL

Code: [Select]
int x=alarm('radars',radars);
Single quotes?
What's that doing?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

myDuino

Code: [Select]
#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!

Nick Gammon

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

Code: [Select]

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

Code: [Select]
data="";
  data+="";

Belt and braces?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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)

AWOL

Code: [Select]
int _timeArray[10];
Code: [Select]
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)

Quote
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?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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.

myDuino

So my code looks like this:
Code: [Select]

  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?

Go Up