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
    About the element14 Community
  • 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
Arduino Forum timelaps
  • 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
  • Replies 9 replies
  • Subscribers 418 subscribers
  • Views 969 views
  • Users 0 members are here
  • arduino
Related

timelaps

e14 Contributor
e14 Contributor over 12 years ago

Hi

I'm a arduino rookie image

I'm learning using the starter kit arduino uno

I did the tutorial with the tmp sensor

What I want to do is to compute the time difference between the first led 2 and the last one 4

here is the code that I did:

Thanks for any HELP!

 

cheers

D

 

||||||||||||||||||||||||||||||||||||||||||||||||||

 

const int sensorPin = A0;

const float baselineTemp = 23;

//unsigned start, finished, elapsed;

 

 

 

 

void setup (){

  Serial.begin(9600); // open serial port

 

 

  for (int pinNumber = 2; pinNumber< 5; pinNumber++) {

    pinMode(pinNumber, OUTPUT);

    digitalWrite(pinNumber, LOW);

  

  }

}

 

 

void loop (){

  int sensorVal = analogRead(sensorPin);

  elapsed=finished-start;

  Serial.print("MILL elapsed");

  Serial.print(elapsed);

 

 

 

  Serial.print("Sensor Value: ");

  Serial.print(sensorVal);

 

 

  //convert adc readgin to voltage

  float voltage = (sensorVal/1024.00) * 5.00;

  Serial.print(", Volts:");

  Serial.print(voltage);

  Serial.print(", Degrees in C: ");

 

 

  //conver voltage to degrees;

  float temperature = (voltage - 00.5)*100;

  Serial.print (temperature);

 

 

  //convert C to F

  float F =(temperature *1.8 + 32);

  Serial.print(", Volt: ");

  Serial.println (F);

 

 

  delay(500);

 

 

  if(temperature < baselineTemp) {

    digitalWrite(2, LOW);

    digitalWrite(3, LOW);

    digitalWrite(4, LOW);

 

 

  }

  else if (temperature >=baselineTemp+1 && temperature < baselineTemp+2) {

    digitalWrite(2, HIGH);

    digitalWrite(3, LOW);

    digitalWrite(4, LOW);

    //start=millis();

    //Serial.print(start);

    //Serial.print("START  ");

   

  }

  else if (temperature >=baselineTemp+2 && temperature < baselineTemp+3) {

    digitalWrite(2, HIGH);

    digitalWrite(3, HIGH);

    digitalWrite(4, LOW);

 

 

  }

  else if (temperature >=baselineTemp+3 && temperature < baselineTemp+4) {

    digitalWrite(2, HIGH);

    digitalWrite(3, HIGH);

    digitalWrite(4, HIGH);

    //finished=millis();

  }

}

  • Sign in to reply
  • Cancel
Parents
  • jw0752
    jw0752 over 12 years ago

    Hi Dani,

    I am also a new guy so my advice will not be the final word but my first project involved working with time too. The adruino has an internal counter that you can access using  millis().  I would read millis() and assign its value to a variable. later when I wanted to know the elapsed time I would use a statement like Elapse =  millis() - variable. This will give you a value for the difference in the start and the finish. Millis() is an unsigned long so you should use similarly assigned variable when you work with it. The counter in the arduino runs at 1 k hz so you get a thousand counts per second. If we read millis() at one point and then subratct that first reading from a second and the value is 60,000 we would know that one minute has passed. Check the Arduino home site as they have more information on using millis(). Good luck

    John

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • e14 Contributor
    e14 Contributor over 12 years ago in reply to jw0752

    Hi

    thanks

    here is the problem:

    I have a loop

    I need to take the time between led1 ON and led 2 ON (it is just an example)

    the problem is because the variableSTART = millis() is inside the loop, I  overwrite the value inside the  variable every time the led1 is ON

    so that isn't working

    any idea ?

    cheers

    d

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • jw0752
    jw0752 over 12 years ago in reply to e14 Contributor

    Hello again Dani;

    Based on what you have explained I would say to start an incremental variable inside the loop.

    X= 1

    Each time you go through the loop increment the variable by 1

    x= x+1

    Put in a statement like

    If ( x = 1)  { start = millis(); }

    In this way the start will be assigned the value of millis() only on the first pass of the loop, on all subsequent passes the value of x will not be 1 and the "If" statement will fail and drop through to the next statement in the program.

    There are nice ways to set up the incrementing variable. I am very green to "C" programming so some of the others may have a better way of doing this.

    Hopefully I understood your question.

     

    John

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • jw0752
    jw0752 over 12 years ago in reply to e14 Contributor

    Hello again Dani;

    Based on what you have explained I would say to start an incremental variable inside the loop.

    X= 1

    Each time you go through the loop increment the variable by 1

    x= x+1

    Put in a statement like

    If ( x = 1)  { start = millis(); }

    In this way the start will be assigned the value of millis() only on the first pass of the loop, on all subsequent passes the value of x will not be 1 and the "If" statement will fail and drop through to the next statement in the program.

    There are nice ways to set up the incrementing variable. I am very green to "C" programming so some of the others may have a better way of doing this.

    Hopefully I understood your question.

     

    John

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube