element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
Blog Arduino beginner
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 3 Nov 2013 8:48 PM Date Created
  • Views 1889 views
  • Likes 0 likes
  • Comments 11 comments
  • Math
  • help
  • arduino
  • advice
Related
Recommended

Arduino beginner

Former Member
Former Member
3 Nov 2013

I'm a complete beginner when it comes to electronics and programming, so I decided to help educate myself I would buy an Arduino starter kit. This kit arrived yesterday and came with an Arduino Project book which is jam packed with information and tutorials (great for learning and inspiration!!).

 

So far I have read the first few pages of the book and followed along with the first few examples. It's a lot of fun but I'm concerned about the mathematical aspect of electronics and programming (I skipped a few chapters to see what i would be doing and saw a few daunting parts that i could not get my head around). If any one has any advice for the Mathematical side I would be glad to hear from you in the comments section (i did not do very well at maths in school image but I don't want to give up) 

  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 12 years ago in reply to kjhart0133 +1
    Erny Don't get too hung up on the maths. It wasn't my strong subject, but hasn't stopped me. There is certainly a time when you need to roll your sleeves up and get stuck in, but I sense you aren't there…
  • mcb1
    mcb1 over 12 years ago in reply to Former Member

    Erny

    Okay after some more searching I found the explanation here on page 115

    Arduino - Free Download eBook - pdf

     

    Ladada also confirms it

    http://learn.adafruit.com/tmp36-temperature-sensor

     

    The datasheet here also confirms it.

    image

    const float get_temperature(){
    - const int sensor_voltage = analogRead(TEMP_SENSOR_PIN);
    - const float voltage = sensor_voltage * SUPPLY_VOLTAGE / 1024;
    - return (voltage * 1000 - 500) / 10;

     

    Hence their example gets a reading of 154 which works out to be 25.19

     

    The issue with yours is that a reading of 900 seems very high.

    I would suggest checking your connections, in particular the earth/ground to ensure its making it all the way to the tmp36.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to mcb1

    that kind of helps, but this is what confused me even more, when i tried to work it out on a calculator line 6 seems fine i get a figure that looks correct then as soon as you do line 11 which is supposedly turning the voltage you have got from line 6 to degC  you get a very odd number which seems too high for degC

     

    for example if sensorVal = 900 then its (900/1024.0) * 5.0 = 4.39453125

     

    then line 11 says (4.39453125 - .5) * 100 = 389.453125

     

    that seems wrong to me :/ but like i said not good with math so i could be being stupid

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 12 years ago in reply to Former Member

    Oops

    replying to the thread dumps it above the latest ....

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 12 years ago in reply to Former Member

    Erny

     

    Looking at this link Math for Project 3 Love-o-Meter - Arduino Forum

    They have the following code.

    void loop(){
      int sensorVal = analogRead(sensorPin);
      Serial.print("Sensor Value: ");
      Serial.print(sensorVal);
      //convert the ADC reading to voltage
      float voltage = (sensorVal/1024.0) * 5.0;
      Serial.print(" , Volts: ");
      Serial.print(voltage);
      Serial.print(", degrees C: ");
      //convert the voltage to temp in degrees
      float temperature = (voltage - .5) * 100;
      Serial.println(temperature);

     

    The ADC value is 1024 steps, with 1024 being 5v and 0 being 0 v.

     

    So at line 06 they are dividing the reading to work out the voltage

    They have swapped the figures but essentially its 5/1024 * SensorVal/1

    (I never was good with that .... but with 5v as the reference you have 4.88758 mV/step)

     

    The datasheet for a tmp36 says it is 10mV/degreeC.

    Hence once you know the voltage you should have the temperature.

     

    I cannot understand why they do line 11, as the datasheet doesn't mention any offset voltage

    It states that it is 10mV/degC and is 250mV at 25 degC.

     

    There are lots of reasons why I don't use the analogue temp sensors and prefer the Dallas One wire devices.

    The comments here  https://www.sparkfun.com/products/10988 support my decision.

     

    Hope this helps.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to kjhart0133

    const int sensorPin = A0;
    const float baselineTemp = 20.0;
    
    void setup(){
      Serial.begin(9600);
      for(int pinNumber = 2; pinNumber < 5; pinNumber++){
        pinMode(pinNumber, OUTPUT);
        digitalWrite(pinNumber, LOW);
      }
    }
    
    void loop(){
      int sensorVal = analogRead(sensorPin);
      Serial.print("Sensor value: ");
      Serial.print(sensorVal);
      float voltage = (sensorVal/1024.0) * 5.0;
      Serial.print(", Volts: ");
      Serial.print(voltage);
      float temperature = (voltage - .5) * 100;
      Serial.print(", degrees C: ");
      Serial.println(temperature);
      
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
    
      if(temperature >= baselineTemp + 2){
        digitalWrite(2, HIGH);
      }
      if(temperature >= baselineTemp + 4){
        digitalWrite(3, HIGH);
      }
      if(temperature >= baselineTemp + 6){
        digitalWrite(4, HIGH);
      }
      
      delay(1);
      
    }

     

    that's the code and I don't understand these parts:  float voltage = (sensorVal/1024.0) * 5.0;  float temperature = (voltage - .5) * 100;

      i mean i know what they are there to do but i don't quite understand the maths (i hope i make sense)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • 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