how to code for an accelerometer and a ESC

Hello all, my name is Stephen and I just bought an arduino kit in hopes of winning the outlaw class for my son's pinewood derby.

So I bought a brushless electric ducted fan (EDF) that will be controlled via an electronic speed controller (ESC) hooked to the Arduino nano. I also plan to attach an accelerometer to the car.

The theory is to activate the EDF for one second or so after the car starts to move down the ramp, once the gates are opened. I want variables for time after motion is first sensed (in case of gate clearance timing/issues) and a variable time for the "on" time for the EDF (so it turns off automatically before it runs off the ramp. I also would like a variable for the speed of the ESC so I can play with the throttle percentage.

Problem is the derby is this weekend and I'm having trouble learning how to code that quickly.

Is there anyway someone could help walk me through the coding to do that?

You know, the next time I have problems with a brushless motor or acccelerometer, I'm going to search for a thread titled "hello". I'm sure that there will only be a million of them. You can go back and edit your title. Using a good title helps attract people with that specific knowledge to click on it and answer your question.

The first problem is using an accelerometer to detect motion. They don't detect speed. Only acceleration. What is the acceleration going down the ramp? Less than 1 G.

First get the accelerometer hooked up and run whatever example code came with the library. Can you get good-looking numbers out of it?

Ok I'm sorry I didn't know that. Thanks for the knowledge I'll remember that in the future.

The way the pinewood derby is step up is there is a ramp the cars go down and a gate that releases them. Once the gate opens and starts to roll down and forward. I thought the accelerometer would sense that movement and then activate the EDF.

I have not gotten the accelerometers yet. They will be arriving tomorrow.

Keep in mind that an accelerometer senses the acceleration due to Earth's gravity, in addition to any accelerations produced by other forces.

You will be thus be measuring "g" along the accelerometer axis that points up and down, when the sensor is not moving or accelerating.

ok. It can still be used for what I'm wanting to do though correct?

Yes, but interpreting the acceleration measurements will probably not be as simple as you imagine, because "g" is quite a bit larger than any acceleration the vehicle will experience on the ramp.

Pretty sure the car will experience an acceleration parallel to the ramp of 'g * sin(theta)' where theta is the angle of the ramp: theta = 0 is flat, theta = 90 is pure vertical. Neglecting friction, of course.

Ok thx. I guess I was not clear on what I was originally asking. I am a newbie and have no idea the order in how to input all this data. Imagine you are telling a 12 year old how to input the code into IDE

I hope this isn't considered soliciting here by saying this, but I would be willing to pay a small tip to someone via Square$ or Paypal that can do a video explaining the process to me or something like that.

When the car is on the ramp, static and unmoving, it will see accelerations due to gravity in at least two axes per this diagram:

When the car starts moving down the ramp the Fg component will decrease while the car is accelerating. You might be able to detect that. Or maybe you could detect the "jolt" associated with the gate falling...

I don't know much about EDFs but suspect that one capable of producing a decent thrust will require some time to spool up. If it does spool up very quickly it may also produce a torque that may cause a yawing of the car in reaction (similar to what happens when a Cessna goes to full throttle at take-off...)

I was planning on writing a code that would just take any signal from the accelerometer (greater than normal vibrations). it can just be on the x-axis or the z-axis and when that signal is given a variable time would start, then the EDF would turn on for a variable time.

Nothing fancy

And the EDF takes no time to spool up. 0.5 sec at most. it produces 213 grams of thrust according to the webpage. The car isn't gonna weight much different than that. Just 2-18650 batteries, the EDF, ESC Arduino nano, accelerometer, wiring and a basic 3d printed frame.

1 second of thrust on a typical 4 second race will be more than enough to put us ahead of the rest without flying off the track.

Mechanics I got, coding I do not

Vibration detection sounds good. That's pretty easy to pick up with an accelerometer.

Blackfin, I like your diagram. But it looks like maybe a suffix got lost in your explanation. Fgx will change depending on whether the car is held on the track or released.

Pretty sure the car will experience an acceleration parallel to the ramp of 'g * sin(theta)' where theta is the angle of the ramp: theta = 0 is flat, theta = 90 is pure vertical. Neglecting friction, of course.

True. The odd, nonintuitive thing about using accelerometers mounted in the moving object is that, in the case theta=90 (that is, the car is in free fall), the measured acceleration is zero.

Sorry, I admit I just found that on the web.

I did create a sketch with an ADXL345 and tried a few experiments with it; breadboard on a plastic ramp at about a 30-degree angle, held steady and then released (initial wiggles near center; following squiggles were the mess of breadboard and wires landing on my coffee table...)

  • blue = resultant, red = x, green = y, orange = z
  • board/accelerometer was oriented with X facing up/down the ramp, z normal to it and y perpendicular

It looks like if you have a button on the project that "zeros" or calibrates it to the start angle you could easily sense the initial acceleration and fire an ESC. Most the code is already there, in theory though I haven't scoped anything...

I don't mean to be rude, but I came here to seek help in coding, not to ask for the math help. If no one here knows how to code, then I must be in the wrong place. Please correct me if I'm wrong

But, you haven't presented any code to get help with. Hence, the conversation is drifting.

You've not exactly given us a lot to work with.

Which Arduino?
Which ESC? Mfr and PN.
Which accelerometer?

The discussion you're seeing here is pretty normal fare for a new project: How can a given sensor be used to detect a particular condition. You don't want to see the math but it's a crucial part of making your project work.

I've got some test code started to determine what an accelerometer output would look like when released on a ramp. Even posted a plot of its output. Yet you seem uninterested in anything but the final result.

Why you would wait until the very last minute before undertaking a project like this is a mystery. Things like this typically evolve over a number of iterations and debugs and retries. You've left virtually no time even for seasoned coders to get something together.

gfvalvo:
But, you haven't presented any code to get help with. Hence, the conversation is drifting.

I don't know how to start with any code. All I know is what I'm wanting it to do. I'm asking for help on how to make it do it.

Blackfin:
You've not exactly given us a lot to work with.

Which Arduino?
Which ESC? Mfr and PN.
Which accelerometer?

The discussion you're seeing here is pretty normal fare for a new project: How can a given sensor be used to detect a particular condition. You don't want to see the math but it's a crucial part of making your project work.

I've got some test code started to determine what an accelerometer output would look like when released on a ramp. Even posted a plot of its output. Yet you seem uninterested in anything but the final result.

Why you would wait until the very last minute before undertaking a project like this is a mystery. Things like this typically evolve over a number of iterations and debugs and retries. You've left virtually no time even for seasoned coders to get something together.

I'm sorry for being ignorant, but I don't understand why I need to provide a model # and stuff like that. I was able to download a standard sketch for a ESC and got it to work with a potentiometer without needing to know models, amperes, voltage or anything like that. I just need the input to be a timer started by the accelerometer rather than a potentiometer.

There again if I knew how to code, I don't see how it would be more than just a few lines of code. I just want a few variables put together. Not trying to design anything that will be working at the LHC or anything like that

I am using the arduino nano as stated in the beginning