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 Arduino - The Temperature part is not working
  • 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 Not Answered
  • Replies 9 replies
  • Subscribers 392 subscribers
  • Views 1229 views
  • Users 0 members are here
  • help
  • sensors
  • temperature
  • arduino
  • sensor
Related

Arduino - The Temperature part is not working

Former Member
Former Member over 10 years ago

Hi guys,

The program works perfectly fine though i am not getting the right temperature value. it keeps giving me 127. which is not correct.

i can't seem to understand the problem with the program. Any Help is highly appreciated !!!

Thanks in advance !!!

 

#include <DallasTemperature.h>

#define ONE_WIRE_BUS 24 

// Setup a oneWire instance to communicate with any OneWire devices 
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

int temp;
int temp2;
void setup(){
Serial.begin(9600);
}
void loop(){
  sensors.begin();
  cValve.write(90); 
  delay(10000);
  //getting the average value
  temp = averageTemperature (); 
  cValve.write(0); 
  delay(3000); //3 seconds 
  
  hValve.write(90);
  delay(10000); //giving 10 second, in order to get a precise temperature
  temp2 = averageTemperature (); 
  hValve.write(0); 
  delay(3000); //3 seconds
  }

  int TemperatureRead(){
  sensors.begin();
  temp = sensors.getTempCByIndex(0); //reads the temperature and stores it in temp
  return temp;
  }

//Function for getting average Temperature Values
int averageTemperature()
{
  TemperatureRead(); // discard first sample (never hurts to be safe)

  int averageTemperature; //For holding the running average
  for (int i = 1; i < 10; i++) 
 averageTemperature += ((TemperatureRead() - averageTemperature)/(int)i); .

  return averageTemperature; // return the Average Temperature

  • Sign in to reply
  • Cancel

Top Replies

  • mcb1
    mcb1 over 10 years ago +2
    jerrymz Terry You have some unanswered questions in this post http://www.element14.com/community/message/148721/l/re-arduino--two-inputs-using-the-keypad#148721 Perhaps you could return and answer the…
  • neilk
    neilk over 10 years ago +1
    jerrymz Hi Terry assuming that you are actually reading the temperature and getting a sensible result (have you checked?), then your formula for calculating average temperature looks a bit odd to me -…
  • gadget.iom
    gadget.iom over 10 years ago in reply to neilk +1
    Neil Kenyon wrote: A simple debugging technique is to print out intermediate results of your calculations to the serial monitor: Couldn't agree more...
Parents
  • mcb1
    0 mcb1 over 10 years ago

    jerrymz

    Terry

    You have some unanswered questions in this post

    http://www.element14.com/community/message/148721/l/re-arduino--two-inputs-using-the-keypad#148721

     

    Perhaps you could return and answer the queries before asking the community for more help.

     

     

    Mark

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • mcb1
    0 mcb1 over 10 years ago

    jerrymz

    Terry

    You have some unanswered questions in this post

    http://www.element14.com/community/message/148721/l/re-arduino--two-inputs-using-the-keypad#148721

     

    Perhaps you could return and answer the queries before asking the community for more help.

     

     

    Mark

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • gadget.iom
    0 gadget.iom over 10 years ago in reply to mcb1

    mcb1 wrote:


    Perhaps you could return and answer the queries before asking the community for more help.

     

     

    Feedback is certainly helpful. It's nice to know how you got on, and wether our advice was correct/useful.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 10 years ago in reply to gadget.iom

    I think it is still unresolved since there were some important bits missing to join the dots.

     

    Mark

    • 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