Pages: [1] 2   Go Down
Author Topic: Brand New Arduino Ethernet Analog Pins  (Read 1126 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Because if it don't get any voltage need to sign to me.
Again, please?

Does this help?
Logged

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

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6146
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18764
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int x=alarm('radars',radars);
Single quotes?
What's that doing?
Logged

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18764
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
data="";
  data+="";
Belt and braces?
Logged

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26273
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So my code looks like this:
Code:
  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?
Logged

Pages: [1] 2   Go Up
Jump to: