Simulated v8 engine on elec. gokart-Help

Hi everyone! :o)

I am new to the Arduino world but I am very excited to learn and to get started. I am scouring the internet to learn as much as possible and will eventually figure everything out, but I thought I would start a thread to get some (or a lot:) of guidance since my profession (Flatbed Truck Driver) doesn't allow me much project time. I will TRY to keep this short but still give a full description of my project and what my goals are, however, I tend to be pretty long winded since I am active in other forums, where I tend to be the one giving advice and helping others out, I prefer a full and detailed description so I can better assess and address the situation. Thank you in advance for taking the time to read through this whole thing and helping me out. Future posts will be more concise and to the point.

I am starting a project build thread on another forum so I will use the put up that introduction here so you can get a good idea of what I am doing and my goals for the Adruino part of the project.

THE PROJECT: I am building a homemade electric go kart for my kids. The theme is a miniature "Hot Rod" powered by a 500w 24vdc motor and controller from a Razor Dunebuggy. I am going to put a fake engine in the front to make it look and sound more realistic. This is where the Arduino comes in.

The engine will have a fake GM style supercharger on it with a butterfly to open in relation to the pedal (fly by wire), open headers that I am going to put 1 or 2 LED's in per exhaust pipe to simulate expelled gases like a dragster, a belt pully to spin, 2 small DC motors with off-center mass weights to simulate engine vibration (maybe from an old PS3 controller?), and loud, crisp and realistic dragster type of engine sounds-all of which will vary with the input from the 5v potentiometer accelerator.

I will have a switch to turn on the power, a button to initiate a starter sound and then loop into an "idle" program, which will run an 8 LED array (or 16, 2 colors per exhaust pipe lit very closely together-example: orange and yellow-to better simulate spent exhaust gases) at a lower brightness, spin a stepper motor to spin the pulley belt, pulse power to the vibrator motors, iniate the servo to be ready to control the butterfly and produce a realistic ilde sound to the speaker. I plan on running the LED's in a loop sequence where the time between each light being lit is the same but a longer delay before starting the sequence again, but the delay between the the LED's within the sequence and the delay between the end of the sequence and the beginning to both get shorterAND the brightness of the LED's to get brighter in relation to the voltage increasing of the potentiometer of the accelerator, as well as the engine sounds to increase in pitch and volume.

I am thinking there will be two main modes: an "idle" mode and a "drive" mode. I will run the +5v signal wire of the accelerator potentiometer to a button that will be toggled on/off with a "gear shifter." With buttton "on" will be "neutral" mode and the signal will not reach the motor controller, with button "off" will be "drive" mode and the signal will go to both the Arduino and motor controller. I may need a driver to produce full and accurate +5v signals to both devices.

"Idle" and "drive" modes: In "idle" mode the engine will be more able to "rev up" quickly and able to produce quick idle "blurps". In "drive" mode I want to limit the "acceleration" speed to better correspond to vehicle speed, and for a bonus challenge (as if this project isn't challenging and complicated enough!), I may even throw in a shift sound or two as vehicle speed increases. After each shift the engine rpm sound would drop back down to 25% above idle and increase anain to top speed or another transmission shift sound. Two transmission shifts will be the max. Besides, top speed will likely never excede 10 mph, how many shifts would it take? :0) I'm thinking that I may have to utilize a small encoder wheel and hall effect sensor to guage speed from the axle rotation to control the environment of "drive" mode.

I think that about covers the goals of this portion of the project. I am not breaking it down into smaller parts so as to not feel so overwhelmed... and keep a bit of my sanity. :o)

So this is my current shopping list:

-Arduino Mega2560 R3 with A-B cable

-SainSmart L293D Motor Drive Shield For Arduino Duemilanove Mega

-Hobby servo and servo module-For throttle linkage/butterfly

  • Audio IC Development Tools Adafruit Audio FX Sound Board - WAV/OGG Trigger with 16MB Flash-To handle the audio

-Stepper motor and Stepper drive module

-Hall effect sensor/reed switch (I think I will have to get a magnetic hall effect sensor because it says this measures the magnetic field. I need one that has a magnet in it and pulls to a metal as it goes past. I don't want to add magnets to the tips of the wheel attached to the axle) Oh well, it come with a kit I am getting.

  • Keyestudio Xbee Sensor Shield V5 with RS485 BLUEBEE Interface for Arduino-To be able to activate a remote "kill switch" from my phone.

-(2) ZJchao 9V 1A Power Adapter for Arduino (2-Flat-Pin Plug / 100CM Cable)-To power the Mega and driver shield or breadboard while prototyping

-Big set of 3mm LED's of various colors

-Pack of jumper wires-For prototyping

-Various resistors

-Dupont wites, breadboards, header pins, buttons... and asprin ;0)

I think that should get me started pretty well. I hope I have made the right choices. I am going to try to get some help/feedback from the Arduino community.

More on next comment.....

So, I guess my first question is: Am I on the right track hardware wise? I also ordered an Arduino UNO R3 for another project but I wanted the additional I/O pins and memory of the Mega to be sure I could do what I wanted to do if I expanded to 16 LED's. I assume I can run a single LED off from each pin since they say each can output 20ma/40ma max. Or should I get an LED driver shield to handle the output to the LED's?

-Can you think of any additional hardware I need to get for this project?

-Will I need a driver to split the pin input signal from the accelerator, so I can have a strong and accurate signal going to both the separate motor controller and the Adruino board, or will splicing off from the signal wire going to the motor controller be ok?

-Is there an easier way to get a realistic "drive" mode than sensing the axle speed?

As for the code, I am in the process of getting a handle on how to time events to loop while keeping the processor free to scan for interupts and changes. I have read how to read a potentiometer input from a pin, convert it and print it and read the print to a pin out. But I can't find a tutorial on how to make several adjustments in different events (for instance: sequence adjusts brighter AND blinks closer together AND sequences re-runs quicker AND changes a sound in proportion to an input pin value) all at once while keeping the processor scanning for changes of said input pin value, interrupts, etc. My game plan is to get each process to work correctly and then put it all together.

-As for the sound I am uncertain on how to pull it off correctly. I was thinking of copyingall the sounds on to the " Audio IC Development Tools Adafruit Audio FX Sound Board - WAV/OGG Trigger with 16MB Flash-To handle the audio" module and pulling a different file as it's needed. I figure a starter noise and an Idle loop would work good for the simple stuff but as far as engine acceleration I am not sure what would work. I could load a bunch of snippets of an engine accelerating and call each to play at different reads of the pin with a different rate and max per "idle" mode and "drive" mode but it seems like it would be slow, choppy AND it's likely I would end up with having to have carpel tunnel surgery half way through coding it. Maybe I can configure a couple algorithms to make things easier?

-Do I have to seperate each event change associated with the potentiometer pin read and each pin out event separately or can I group them all together?

-Would I wire the "neutral/drive" buttons in to interupt pins and write seperate actions for all of the enviroments for when they are "high" or write a change/if statement in each process of the declarative output statements in loop?

-I am sorry, I am probably using the wrong terminology and confusing people. I will get better.

-Do I have to do a seperate whole command list for each "mode" (cases dependant on button variables) or can I declare all the pins and write all of the commands for everything in one clump?

Ok, now I confusing myself. It's difficult to get a firm grasp of how to write larger, more complicated code with only short tutorials to go off from, especially when the variables and end goals are so different than the objective of other projects. It's difficult to ascertain the correct way to organize so many variables, actions and changes to get the correct results, make it stable and keep the processor from within the loop cycle. I think I conveyed my concerns correctly...? I will keep reading and learning though.

Any advice or code to get me started would be greatly appreciated! Anyone who helps will get a mention whenever the opportunity presents itself and credit will be noted where applicable in whatever way you deem appropriate.

This sounds like an interesting project but without meaning to sound unkind may I suggest that your posts are trying to cover too much all at once.

Every successful computer project is constructed from a series of small elements. It is virtually impossible to conceive of a solution unless you focus on the individual elements - for example buttons, sound etc. Learn how to do each element separately and only then start the process of combining them.

Also, I suggest that it is difficult, if not impossible to come up with a list of parts without experience. You may make a list at the outset but I reckon as you gain experience you will find yourself changing your mind. So, again, focus on each element of the project one at a time and just get the parts you need as you go along.

And it will be much easier to get help here if you are just focusing on one element of the project.

Maybe have a look at Planning and Implementing a Program although it was not written for a complete beginner.

...R

Thanks for your input and advice, Robin. My plan was to break down the project into individual parts, as I have been doing, but I am getting the sense that When I right the sketch I will need to keep in mind all of the parts in order to write an effective and smooth code, especially taking into consideration the amount of changes to occur from only 2 to 3 inputs. I just wanted to get on the right path of how to go about coding multiple events in the way that my project demands so I can break down the individual parts to correspond and relate with the other events in a way that frees up the processor correctly so it can pick up on interrupts and changes quickly.

I had just noticed that the way I would have to code my project was different than the way I have been learning to code individual components. I figured I would try to get a jump on the situation and get an idea of how to integrate all of the different parts correctly while learning the last bits of intricacies that I need to learn so that I'm not doubling my work load in the debugging process trying to integrate them all together so it works correctly.

I thought it would be best to write out the entire goals of my project so others could get a better idea of what type of interlacing of code I will need in the final stage instead of starting 8 post on different components to get control of the components and then another few posts to alter the code from the first 8 posts in order to get it all to mesh well in one cohesive program. That way, those who know how to properly execute such programs effectively get the whole picture and can give me guidance on how to use the correct functions to make everything work properly. For example:

It would be best to consolidate your "idle" and "drive" modes separately but after you declare all of your pins (change), (millis) and other time statements. Use this type of command to look for changes with this pin with this time statement and this type of command to change these outputs etc. Use (if) statements to change these types of events. And so on...

I am already learning how to control the individual elements but I need some guidance on how to control them correctly all at once. Once I can get a little help on the best way to get them to all run at once I can sort out the details of how to get the right timing and other intricacies with each part so they mesh well.

Thank you for the suggestion of Planning and Implementing a program. I will look into purchasing it. And thanks again in regards to your response.

TruckerDad: Thank you for the suggestion of Planning and Implementing a program. I will look into purchasing it.

What do you mean "purchasing it" ?

Everything is in the link I gave you - for free.

...R

Oh, ok. Thank you for pointing that out for me. :o I didn't even click on the link (obviously). I have been looking in to buying a book to help me along and I thought it was a book that I could buy. I will look at it as soon as I get time. Thanks again.

The basic Arduino doesn't make a very good sound generator because it doesn't have a DAC. (The Arduino Due does have a DAC.) So normally, anything more than a "beep" (which can be a square wave), sounds are usually generated by an add-on audio shield playing an MP3 or WAV file. And with those shields, you won't be able to mix sounds or change the pitch/tempo.

And of course, you'll need a fairly-large speaker & cabinet to generate strong low-frequencies. (The "engine" might make a good speaker-box unless you have other plans for it, like filling it full of batteries or something.0

TruckerDad: I didn't even click on the link (obviously).

It is standard operating procedure here to check links you are given BEFORE responding to a post :) That's why we post the links!

...R

Thanks again, Robin. The post that you suggested (and authored) is very helpful and informative.

DVDdoug: The basic Arduino doesn't make a very good sound generator because it doesn't have a DAC. (The Arduino Due does have a DAC.) So normally, anything more than a "beep" (which can be a square wave), sounds are usually generated by an add-on audio shield playing an MP3 or WAV file. And with those shields, you won't be able to mix sounds or change the pitch/tempo.

And of course, you'll need a fairly-large speaker & cabinet to generate strong low-frequencies. (The "engine" might make a good speaker-box unless you have other plans for it, like filling it full of batteries or something.0

Thank you for your response, DVDdoug. I just saw your post. Somehow I missed it until now. Thank you for the information. I was thinking that I could store a bunch of wav files on the Adafruit Audio FX Sound Board and play each tiny file dependent upon the position of the potentiometer, but I didn't know if it would work or not. I purchased it because I know for a fact that I will use it to play music files with buttons on the "dash" for the kids to listen to if for no other reason. I might just go with converting a wave file of the sounds that I want into tones, loading the tones in the IDE, code it to a sine wave signal instead of a square wave so it has better quality, is louder and is more friendly to the speaker and see how that works. I am open to better ideas, though.

As far as the speaker goes I am planning on building a small tuned enclosure mounted on the floor of the go kart with the speaker firing at the dash and corner loading the vent for maximum effect. I will take the Thiele/Small parameters of a speaker and build a small box with a vent that is tuned to 60-80Hz. I will power it with a small amplifier to get the desired volume. I thought about using the engine as a box and firing the speaker at the ground and using the exhaust for the tuning ports but I don't think it will be suitable because it is pretty small and I am going to be putting vibro motors inside to create the "shake". We will see though.

Thanks again for the great info and ideas! If you have any other ideas please let me know.

For the audio, my idea was to first calculate the maximum frequency that an LED can flash before it either all 8 just stay on or the brain makes you think they are all on constantly. Then chop up three into 20 or so audio files per group: one of the engine noises of idling (which would just be one continuous loop of one large audio file), one group of 20 or so revving up in neutral and one group of 20 or so accelerating in drive. Then I would assign each group of sounds with different file names and make a map corresponding to each environment. The Arduino would send a command to the module to play each file name as it comes up, determined by the input of the pot that was split up in 20 or so blocks of input. I don't know whether it would/could be possible, but I was going to try it until I found a better way to control the audio quality that I am looking for. If it is not possible that way, I will just put music on the module and run it as a stand alone music player with a couple small speakers so the kids can jam out to some music. I am still scouring the internet for the best solution to the audio portion of this project.