Newbie Needs Help Building A Timing Device

I am as new as they come in regards to building projects with Arduino. In fact until yesterday I never even heard about this. What got me here is I am in the process of building a simple timing version of a race shock dyno. Ideally I would like to be able to transfer that data from the device to my laptop and somehow apply it to a chart. Here is how the system would work. I would have pneumatic cylinder that compresses and retracts the shock. The timing device would measure when the downstroke begins and ends and then have the ability to reset the timer. The same process would apply for the upstroke. Sending these times to my laptop would be nice but not necessary. I will be using a manual control valve to activate the up and down stroke. Also will be using a manual valve to set different air pressures for testing. Not sure if there is a way to have the Arduino control these functions as well. Thanks in advance for the help!

Read for some time on these fora and you will see that your project is entirely possible.

So first you need to figure out how the Arduino can sense the things to be timed.

Are there electrical signals that might be eavesdropped upon? Or can you add a mechanical switches to indicate the travel?

As for controlling things, you need to say what kind of signal would be usable to get things happening. Usually a few parts or a moduke of some kind can help the Arduino run anything in the world.

In the abstract, very simple. Watch for it to start going up, start a timer. When it is up, consult the timer and print it (for now).

Rinse and repeat for the downstroke.

So say more.

You might also just start playing with some of the example sketches. This can be done without spending any money at all by using the simulator at www.wokwi.com, currently the best for this exact purpose.

a7

1 Like

Have you ever written software before?

No I have not written software before. If there is a way to learn how too I can assure you I will dedicate the time to do so.

I'm thinking on using a simple switch as the limiters and some sort of wheel to trigger the up and down stroke. My main goal is to have a timer to measure the up and down stroke time and the ability to reset the timer at each position. Anything extra like an air pressure valve that runs off the Arduino and transferring data would be wonderful but not necessary. I will check out the site you mentioned. Thank you

What would be the best Arduino to get started on this project?

I'll say the UNO, and depend on ppl who just think another board is better for whatever reason to say.

From a resources point of view any of the old common Arduino boards would have plenty.

I like the Nano (not the Nano Wvery, the original).

Whichever, for convenience get a board that, like the UNO and the Nano, uses a USB cable for uploading.

HTH

a7

1 Like

Just pick one, it won't matter. I can assure you that any arduino made can do what you describe.

However, you will need to start from zero and learn how to program it. There are tutorials galore online and if you get stuck, you can ask for help here.

I'd suggest not buying any hardware to start, but using the free Wokwi simulator instead. Once you have your program working there, you can buy a $2 Nano clone or something.

I borrowed bits and pieces from other sources and put together this stopwatch. I just wanted to get my feet wet in the process but ran into troubles when I tried to run the simulation. Can anyone tell me what I did wrong in regards to the errors in the screen shots?


It looks like a simple error, but many ppl like me cannot squint just right on the device we use and would prefer to see the code.

Post it here, use the <CODE/> button from the message composition window, you will get

type or paste code here

leave the ticks you will see before and after when you do in place; paste your code over "type or paste code here"

I see an error nevertheless, mismatched or missing { braces }.

Put that code into the Arduino IDE and apply the autoformat tool, this often helps point up where you've managed to,lose (or acquire) a brace.

a7

I would suggest using an UNO or classic NANO. These are the simplest Arduinos and have what you need to do the job.

I think a major part of the job will be mechanical, where you figure out how to detect the start and end positions and how to detect when to start timing. When you start using switches you will run into real world situations where you need to deal with switch contact bounce. Another possibility is optical sensors where you don't need direct contact with the device. This is an area where you probably have a better idea of what is needed then we do.

As far as programing there are a lot of tutorials and books on the web. It has been decades since I taught introductory programming, so I no longer have the beginner mind set. I am sure some of the newer people can tell you what they found useful.

Here is the first code with an error.

if (timerMode == 1) {
    lcd.setCursor(0, 1);
    lcd.print ( (millis() - startTime)  /  1000.0);
  }

Here is the second code with an error.

if (timerMode > 1) {
    delay(2000);
    timerMode = 0;
    lcd.clear();
    lcd.print("Press to Start");
  }

The optical sensors would probably be a better choice. I didn't think of using those. I think those would be more consistent. That's why I came here to get advice from the more knowledgeable. The programming will be the hard part for this old guy but I'm sure willing to give it a try. Is it possible to have the data transferred to a laptop instantly and put on a chart or is that another whole programming deal?

There are no obvious errors in either code section.

Often error messages are difficult to interpret and sometimes point confidently at the code where an earlier error becomes a problem.

This is why the request for code is always for a complete sketch. Context is everything and as said often around here the problem is likely to be in the code you did not post.

Posting your entire sketch also means ppl like me with no life will take the trouble to actually compile, fix if necessry and run it for ourselves.

a7

#include <LiquidCrystal.h>

#define button 2

int timerMode = 0;
long startTime;

//initialize the library with the numbers of the interface pins
LiquidCrystal lcd (7, 8, 9, 10, 11, 12);

void setup()  { 
// set up the LCD's number of columns and rows;
lcd.begin(16, 2);
lcd.clear();
pinMode(button, INPUT_PULLUP);
lcd.print("Press to Start");
}

void loop ()  {  
  lcd.setCursor(0, 1);
  if (digitalRead(button) == LOW) 
    startTime = millis() ;
    timerMode++;
    delay(400);
  }
  if (timerMode == 1) {
    lcd.setCursor(0, 1);
    lcd.print ( (millis() - startTime)  /  1000.0);
  }
  if (timerMode > 1) {
    delay(2000);
    timerMode = 0;
    lcd.clear();
    lcd.print("Press to Start");
  }

Possibly a slot type like these on Amazon (obviously also available other places).
https://www.amazon.com/optical-limit-switch/s?k=optical+limit+switch
Back when floppy drives roamed the earth these were easy to get from scrapped drives :grinning:.

I will check them out. It amazes me how cheap everything is and what you can all do with it.

This is the code you posted after applying the auto format tool as I suggested.

# include <LiquidCrystal.h>

# define button 2

int timerMode = 0;
long startTime;

//initialize the library with the numbers of the interface pins
LiquidCrystal lcd (7, 8, 9, 10, 11, 12);

void setup()  {
// set up the LCD's number of columns and rows;
	lcd.begin(16, 2);
	lcd.clear();
	pinMode(button, INPUT_PULLUP);
	lcd.print("Press to Start");
}

void loop ()  {
	lcd.setCursor(0, 1);
	if (digitalRead(button) == LOW)
		startTime = millis() ;
	timerMode++;
	delay(400);
}
if (timerMode == 1) {
	lcd.setCursor(0, 1);
	lcd.print ( (millis() - startTime)  /  1000.0);
}
if (timerMode > 1) {
	delay(2000);
	timerMode = 0;
	lcd.clear();
	lcd.print("Press to Start");
}

We see the loop() function, the if statement that is actually { inside } the loop function controls the execution of only the subsequent line of code.

After the closing brace } of the loop function, we see two lonely if statements living where they cannot (outside a function).

I'll let you fix it as I did. You will need to read the code very carefully, it is something you will get better at and practice makes perfect. Eventually. :expressionless:

I removed from my version all use of theLCD and used Serial.print and Serial.println instead, so I could focus on the logic. Plus I have no LCD.

I suggest you also leave things separate - get some buttons printing the elapsed time of interest, worry about adding the display later.

You will find that the code kinda sorta works. If you stab the button, you will see time counting up. If you stab it again, it will stop counting up, which on the LCD means it will be left displaying the elapsed time between the two stabs. A stab lasting longer than 400 milliseconds will be seen as both the beginning and ending of the timing period. The 400 milliseconds delay is what that is measuring.

So you are on the way. Button handling can be done so the timing can start when the switch goes down, no matter how long you hold it down, and stops when you press it down again, or indeed as I think you will aim for, it could stop when a second button is seen to become pressed.

a7

Sorry been away from this project for a while now. I am completely confused on what you are telling me is wrong. Can you explain this in another way for someone that has no idea what he is doing yet? Lol

I second the UNO for complete beginners and would like to add - order the UNO R3, not the newer R4 since the vast collection of info online and in any books one may read, refer to the UNO R3 if I had to guess, 80% of the time.

The second board a new user should purchase imo, is a Mega. I'm all for the smaller form factor of boards like the Nano but the additional features of the Mega, particularly the extra hardware UARTs, are worth the extra $20 or so all day long.

For projects that are finished on an UNO, yes for sure, transfer those to a Nano though and save the dev board for prototyping.

(@alto777 , no love for the Nano Every? It's like, my favorite board and I almost never run into instances where it doesn't work the same as an AVR-based board)

To @gary1975 listen to @alto777 over me though, to stay helpful and on-topic. He knows way more about this stuff than I do, no sarcasm.