Hi everyone, I have probably an easy question for many. I am new to this site it’s GREAT! I have searched many answers/questions with no luck and components an boards an still need a little help. I was wondering what components/equipment I would need to activate a motor after x amount of times a sensor is alerted such as a piezoelectric/accelerometer sensor or a type of sensor detects high intense movements or knocks/Impacts? Example would be a button pressed x amount of times, that sets/programs the motor to activate after the sensor sends input or is alerted x amount of times the program button was pressed, to activate the electric motor to engage momentarily. Then auto reset an activate every time the programmed number of sensor alerts is reached to re-activate the motor? Also I would need it to use no power until sensor signals first input.? That’s why I keep thinking I need the piezoelectric after much research it seems like this does a 2 an 1 sleeps then when senses starts the count to activate the motor after x amount of inputs is reached to re-activate the motor. Trying to add accessory to my R/C hobbies 8) fun to customize always have lol PLEASE let me know what components I would need to achieve this?! Or any input is Greatly appreciated!! Thanks
I’m still not sure what you’re trying to do but a micro-controller would seem to be the simplest way to count the input triggers and time the output pulse. Depending on the input sensor, you’d likely need some other conditioning circuitry. And to switch the motor on and off (? and reverse direction ?) might require more “driver” circuitry.
No doubt you might be able to do the task with a counter of some sort followed by a timer of some sort (555/556) but that would likely be more circuitry than a simple MCU.
As for no power … that’s not going to happen. But it can be very very very little power while waiting to “wake up” due to the triggers.
Thank’s for the input! I appreciate it. Yes I agree the microcontroller is best fit for this. the reason for the external button to program the device all self contained is to count x amount of impacts on the R/C cars, when the sensor gives input lets say the hobbyist pressed the button five times so when five impacts were detected the one directional small motor would engage to disperse a smoke or visual signal. The motor would only need to engage for lets say 3 secs. to achieve this so other contestants could be aware of it. Now if they want to do a 10 any number impact race that is why the external button is needed to be pressed to match how many impacts are sensed to engage the signal motor. I think a shock sensor might be the best or im still thinking of maybe a piezo electric that acts as a accelerometer/shock sensor the 3 thin layered ones that produce a voltage when an event takes place to activate them. The device would also need to auto reset once the number of preset sensor inputs were reached to engage the small one directional motor. So the contestant could resume without interference. A 3-5v battery I believe would achieve this in the device. Know you have a better understanding. If you can set me in the right track to through components needed to achieve this it would be awesome for us hobbyist looking for a little Hollywood effect an to determine points for the better racers. They don’t like there custom setups to draw juice from the car they get competitive believe me like real nascar! An what better than the Hollywood effect. Any help in finding the right components to achieve this is greatly appreciated Mac or anyone?? Thanks
OK, some sort of microcontroller (MCU) is a given then. What’s best to use depends on the sensors chosen but the MCU only needs to be very simple and small, as the code needed to accomplish the tasks you’ve outlined will be simple and small. The I/O needed will also depend on the sensors but roughing it out it looks like ;
-
a single pin to make the output smoke happen
-
a single pin to set the number of hits
-
some number of pins to get the sensor info, perhaps 2 or 3 ??
-
another output pin to indicate the above button presses, to give the user some feedback ??
Because it’s going to be in an RC car, the whole setup needs to be small or at least easily packaged into perhaps several small volumes.
So it comes down to sensor choice really. I can envision 3 possibilities off the top of my head. The first is some sort of piezo sensor. These are quite sensitive, perhaps too sensitive and you don’t want them triggering as the car drives over rough surfaces. (?is this a concern?) They can produce very high voltages and so other signal conditioning circuitry is needed to interface them to the MCU. For that reason that type of sensor is on the bottom of my list.
Next up is a vibration sensor that another frequent poster here has used (I haven’t). He’s said they’re quite sensitive and the website lists a variety of “flavors” of them. They are the simplest sensor to interface to the MCU, they are just open/closed switches !
https://signalquest.com/product/components/sq-sen-200/
Perhaps you can get away with just one of them, perhaps you need 2 to sense back/front and side/side hits. And perhaps you need to suspend them to keep them from triggering just due to rough surfaces. When I last looked to buy some, I couldn’t find a trusted vendor serving the hobbyist. Since I just don’t know enough about them, they’re my second choice. But well worth a look. In $$ cost, they would be between piezo’s and the following.
Given the looseness of my knowledge of how hard the collisions need to be to trigger a “hit” but still avoid false triggers due to the road, I think using a 2 axis (or 3 axis) accelerometer is the best choice. I’d get one that interfaces digitally to the MCU (vs having analog outputs) and that will require either an I2C or SPI interface (2 or 3 pins). Most of these can also be “programmed” to trigger all by themselves when an acceleration > than the preset is sensed. This is communicated to the MCU via another interrupt pin or pins. This means the MCU programming can be very simple as it just sits there counting the interrupts until the user set number happens. Then it’s smoke time followed by a counter reset. Even if interrupts aren’t used, it’s still simple to read the accelerometer 20 to 50 times/sec to catch and evaluate any hit and it’s strength. The below is the least $$ one SFE sells and so I’d start with it. I’d think it more than capable for your usage.
https://www.sparkfun.com/products/12756
Since that accel runs on 3.3V, your MCU should also. Four choices, in increasing capability and cost would be ;
[Adafruit’s Trinket - It has only 5 I/O pins. It’s a little harder to debug code on it (vs some others) as it’s not easy to get data collected by it to a user readable display (ie - your PC). Still it’s capable of doing the job and being (mostly) an Arduino, easy to program for the beginner.
Adafruit makes a [Trinket Pro for a few $$'s more. It’s got many more I/O pins but still no dead easy way to get data from it to your PC. Perhaps worth consideration if you ever want to expand beyond the functions above.
SFE sells (for the same $$s) a barebones [Arduino Pro Mini. This, like the Trinket Pro, has more I/O than you strictly need. It’s “drawback” is that you need a “special” external device to talk to and program it. That is a USB/TTL serial (3.3V in this case) adapter, either as a board or as built-in to a cable. That adds perhaps $15 to the overall cost but you only need 1, as it can be used for all the Pro Minis you care to have. But given you have it, you can now (easily) program the Arduino MCU to also send data to the PC. FWIW if you wanted to send data to the PC from a Trinket or Trinket Pro, you’d need one of these as well. Frankly for any of these MCUs, you’d need one. I’d want to collect and see some data during the development process.
https://www.sparkfun.com/products/9717
https://www.sparkfun.com/products/9873
Lastly you could use a “real” Arduino, like a [SFE Pro Micro. This talks to the PC via a normal USB cable (w/the proper connector types, be careful) and so is the easiest to use or to start with. Code written for any of the last 3 will be compatible with amongst them. And most likely, w/just a few, if any, changes also compatible with the Trinket. So you could buy and develop on a “Cadillac” and use “Chevys” in the production pieces. For that matter if you’re only making onsies - twosies of these, the cost differences between any of the above is pretty small. If you’re making a lot, you’ll probably want to make your own custom PCB and mount the accel (and other stuff) on it. Still I’d develop the system using something from the above.
FWIW there are other MCUs you could use (PICs and TI MCUs) but code to talk to that sensor from an Arduino has already been done so …
As for the output … You mention a small motor. My thought, not knowing any better, is that you need a simple transistor (2N2222a) “driver” circuit to run it (on/off). That means you also need some small area to put the circuit. That circuit would look like this (but the resistor should be 330 ohms, not 3.3K ohms.
http://www.thebox.myzen.co.uk/Workshop/ … mage_2.png
A simple normally open push button switch could be connected to an input pin, as shown here, to set the number of hits needed to make “smoke”.
http://arduino.cc/en/Tutorial/InputPullupSerial
You may also want to debounce the switch. Then comes the question of how the user knows that his push was “seen” by the MCU. Perhaps another pin could drive an LED ? Perhaps the motor could be briefly run ? That needs some more thought. Recall that a Trinket has but 5 pins; 2 to talk to/from the accel, 1 for the button, 1 for the motor, 1 left … for the LED or interrupt or ??? (something we forgot). Of course this becomes a non-concern w/all the other MCUs.
Lastly, what to do for power … All of the above MCU boards have a voltage regulator on them and so could take a higher battery voltage to run off of while also sending 3.3V to the accel board. So you could run them off the car’s battery, so long as it’s less than 12V (??). Otherwise a single small “3.7V” LiPo might work. I’d have to check the regulator spec, as a LiPo starts at about 4.2V fully charged (too high for the accel) and runs down to 3.3 - 3.0 V before you should stop using it.](Pro Micro - 3.3V/8MHz - DEV-12587 - SparkFun Electronics)](https://www.sparkfun.com/products/11114)](Adafruit Pro Trinket - 3V 12MHz : ID 2010 : Adafruit Industries, Unique & fun DIY electronics and kits)](Adafruit Trinket - Mini Microcontroller - 3.3V Logic [MicroUSB] : ID 1500 : Adafruit Industries, Unique & fun DIY electronics and kits)
Thanks, testing an soon. I will let you you know how it goes. Or if anything comes up in between.
I have spent a few days trying to get the coding right for this project. Everytime I go to verify it in the Arduino compiler I get a reference of bugs or change definition? I have been using the Arduino wright and implement the code but it is severely buggy. Could someone if they know any give me a code reference I’m using the Pro Trinket with all the Arduino drivers for isb tiny so it is all relevant. If anyone could give me a base sample to code this would be great an well appreciated!
I also have the FTDI from mini breakout board, for feedback or bootloading the pro mini’s. I was wondering if this might be a better approach to getting the code correct? Thanks
I’ve not used the Trinket or Pro Trinkets but my understanding is that they program through the USB port, similar to most Arduinos. I don’t know what definitions Adafruit gives you to modify the Arduino IDE to be able to recognize and program the Trinkets. If you can copy and post the error messages the IDE spits out at you. You might be better off asking that question at the Adafruit forums (or to Adafruit tech support).
As far as using an FTDI board, I don’t think it’ll help you unless you wipe out the Adafruit bootloader. It must be using some version of V-USB to get the program over the USB link.
HI, I was wondering if you could direct me to a code sample or sketch to further help in getting the programming right, to achieve the above actions. I went with the signalquest accelerometers they our normally closed with the linear, radial, and shock. I just put together a simple code to get everything to work. I am new to programming so I know there is a lot better way to go about this to achieve the desired result. If anyone has a moch sketch to do this or library something close I would greatly appreciate it so I can improve, and build upon it, or set me on the right track. Thanks, B
Code for a standard Trinket. Will turn on pin 1 when pushbutton on pin 0 is pushed three times.
Not tested, but should work.
#define LIMIT 3
void setup()
{
/* add setup code here */
pinMode(1, OUTPUT);
pinMode(0, INPUT_PULLUP);
// Motor off
digitalWrite(1, LOW);
}
void loop()
{
static int count = 0;
delay(50);
if (digitalRead(0) == LOW)
{
count++;
if (count == LIMIT)
{
digitalWrite(1, HIGH);
}
}
}
There’s some similar Arduino/Trinket code [here that has been tested. Code controls a motor driver board to switch a solenoid valve.](http://www.cedarlakeinstruments.com/blog/archives/219)