element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Analog inputs (TMP36) and cable length questions
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 8 replies
  • Answers 2 answers
  • Subscribers 391 subscribers
  • Views 1563 views
  • Users 0 members are here
  • input
  • tmp36
  • arduino
  • analog
  • sensor
Related

Analog inputs (TMP36) and cable length questions

ntewinkel
ntewinkel over 12 years ago

Hi all,

 

I'm trying to do some data logging on my greenhouse, but I'm getting some inconsistent values from my analog pins.

 

Specifically, I have 6 sensors, using all of the UNO's analog pins A0-A5.

I have 2x TMP36 temperature sensors (inside and outside temperature), 2 moisture sensors (nails on wires), a light sensor, and eventually will have a water level indicator for the rain barrel.

 

All the sensors seemed to work well individually when I tested things separately (and with short leads), but now the numbers seem to vary a lot from one reading to the next, at least for my temperature sensors (I think the others need some fine tuning of expected ranges).

 

I take a reading every 15 minutes, and store it in an array. I have a bluetooth adapter hooked up, so I can take my laptop to the room nearest the greenhouse and connect wirelessly to the Arduino that way. I can then type in a command and see the data that was stored, and I can get the current values.

 

To save it from added power drain I thought I would use D12 as my power pin. So D12 is usually low, but just before reading the values I set it high to provide 5V to the two temperature sensors (the other sensors just connect to ground). Come to think of it, I think I'll just keep that set to high to remove that extra unknown image

 

So I'm wondering - do the analog pins need to "settle" at all before I take readings? Right now I set D12 high, wait 1 second, and then read each of the analog pins:

  digitalWrite(power_pin, HIGH);
  delay(1000);
  int insideTemp = readTemp(inside_temperature_sensor);
  int outsideTemp = readTemp(outside_temperature_sensor);
  int moistureLevel1 = readMoistureLevel(moisture_sensor1);
  int moistureLevel2 = readMoistureLevel(moisture_sensor2);
  int waterLevel = readWaterLevel(waterlevel_sensor);
  int sunshineLevel = readSunshine(sunshine_sensor);
  // prints stuff to BTSerial port here
  digitalWrite(power_pin, LOW);

 

The TMP36 sensors are hooked up to 5v, AnalogPin, Gnd (as per the oomlout example).

All of the other sensors are connected just via 2 wires each: ground and analog pin. I'm using the internal pull-up resistors as follows:

  pinMode(moisture_sensor1, INPUT);
  digitalWrite(moisture_sensor1, HIGH);  // use pullup resistor

 

The Arduino is set up in my garage, and uses about 15 feet (5 meters) of CAT-5 cable to connect to the sensors in the greenhouse. CAT-5 has 4 pairs, or 8 wires. I use 1 wire for 5v, 1 for Gnd, and the other 6 are for each of the Analog pins. I soldered a header on the greenhouse end to bring out 6x Gnd connections and 2x 5v connection, so that all sensors can be plugged in that way.

 

So my questions are:

1. Do I need to do anything special for the analog reads, or is my procedure ok? For example, would it make sense to wait between readings, or take 15 readings per pin and use the average?

2. Does the length of the sensor wires cause a problem?

3. Does sharing the GND over that distance cause an issue?

4. I realize that the waterlevel sensor is not connected, but I have a pullup resistor in place which puts it to a constant 5v, or 1023. This wouldn't affect any other pin readings, would it?

 

Thanks!

-Nico

  • Sign in to reply
  • Cancel

Top Replies

  • mcb1
    mcb1 over 12 years ago in reply to ntewinkel +1 verified
    Nico This may give you give the answer. http://forums.adafruit.com/viewtopic.php?f=25&t=11597 I've learned something today so thanks Mark
Parents
  • ntewinkel
    0 ntewinkel over 12 years ago

    Update:

    * keeping D12 at 5v made no difference.

    * adding delays between reads made no difference. Code tried is as follows:

    delay(100);

      int insideTemp = readTemp(inside_temperature_sensor);

    delay(100);

      int outsideTemp = readTemp(outside_temperature_sensor);

    delay(100);

      int moistureLevel1 = readMoistureLevel(moisture_sensor1);

    delay(100);

      int moistureLevel2 = readMoistureLevel(moisture_sensor2);

    delay(100);

      int waterLevel = readWaterLevel(waterlevel_sensor);

    delay(100);

      int sunshineLevel = readSunshine(sunshine_sensor);

    delay(100);

     

    It also seems that the issue is only just with the TMP36 sensors. I'm going through a mess of test data right now to verify the readings from the other sensors.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • ntewinkel
    0 ntewinkel over 12 years ago

    Update:

    * keeping D12 at 5v made no difference.

    * adding delays between reads made no difference. Code tried is as follows:

    delay(100);

      int insideTemp = readTemp(inside_temperature_sensor);

    delay(100);

      int outsideTemp = readTemp(outside_temperature_sensor);

    delay(100);

      int moistureLevel1 = readMoistureLevel(moisture_sensor1);

    delay(100);

      int moistureLevel2 = readMoistureLevel(moisture_sensor2);

    delay(100);

      int waterLevel = readWaterLevel(waterlevel_sensor);

    delay(100);

      int sunshineLevel = readSunshine(sunshine_sensor);

    delay(100);

     

    It also seems that the issue is only just with the TMP36 sensors. I'm going through a mess of test data right now to verify the readings from the other sensors.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • ntewinkel
    0 ntewinkel over 12 years ago in reply to ntewinkel

    I just went through the data - all the other sensor values are stable. It's just the TMP36 that are bouncing all over the place. For example, inside temperature was reading 7, 12, 15, 12, 12, 12, 11, 4, 8, 7 degrees C. My digital thermometer in there said it was actually near 20 C.

    That's not even steady enough that I could do multiple readings on it to get an average.

     

    Any ideas?

     

    Thanks,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to ntewinkel

    Nico

    This may give you give the answer.

    http://forums.adafruit.com/viewtopic.php?f=25&t=11597

    I've learned something today so thanks

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • ntewinkel
    0 ntewinkel over 12 years ago in reply to mcb1

    Thanks Mark!

     

    I made this function so I could easily and cleanly replace all the calls:

    int advancedAnalogRead(int sensor) {

      analogRead(sensor); // dummy read to switch ADC to new sensor

      delay(10); // give the ADC time to settle

      return analogRead(sensor);

    }

     

    The results I'm getting now are super solid, but it looks like I have some more figuring out to do, as it's definitely not 30 degrees outside image

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube