Will 5V toy motor + flex sensor = fried flex sensor?

Hi. I’m just starting with my first Arduino kit.

I’ve run the example that controls the servo with the flexible sensor, and the example that runs the toy motor&transistor with a write loop.

I’d like to combine the two and vary the speed that is written to the toy motor based on the flexed resistance of the flex sensor.

If the flex sensor is branched from the same 5V source that the transistor is using to power the toy motor, will I fry the flex sensor? I’m concerned that the transistor will pull more current than the flex sensor (0.5 watts continuous) can handle.

First are you refering to the flex sensor in [this kit, which is to say [this part ? Assuming so let’s work it out. The datasheet says the flat, unflexed resistance is ~ 25k ohms and the flexed resistance varies (on the amount of bend obviously) from 45k to 125k ohms. The power handling is given as 0.5W continuous. The sensor will draw the most current and dissipate the most power when it’s unflexed so let’s calculate the power used for that situation.

Power is voltage times current or equivalently voltage^2/resistance. Current through a resistor is voltage/resistance (Ohms law). A little math will show how the aforementioned relationships are equivalent and suggests a third equation for power that’s left to the reader to discover. :mrgreen: So with 5V and 25000 ohms the power dissipated in the sensor is :

P = 5^2/25000 = 25/25000 = 0.001 W or 1 mW.

You’re safely under the max power rating. Go forth and flex !

BTW the calculations above are the worst case situation, where the whole 5V would be across the sensor. In usage I don’t think this will be the case. To measure the flex, I think you’ll create a resistor divider using the sensor and another resistor so as to feed the voltage between the 2 into the Arduinos A/D. Thus the sensor won’t be exposed to the whole 5V in “normal” usage. Still it’s better to be safe than to let the magic smoke out.](Flex Sensor 2.2" - SEN-10264 - SparkFun Electronics)](SparkFun Inventor's Kit for Arduino (Old Stock) - KIT-10173 - SparkFun Electronics)

Well, that is a great answer. I was trying to work it out with current division. Looks like a great reminder to trust the math instead of ‘common sense’.

Thanks very much.

Well, I got that working. The flex sensor as part of a voltage divider, analog in to the Arduino, and then map the low and high to 0-255 to write to the transistor. Worked great!

The motor eventually stopped responding, though. I think I may have burned it out. Is that likely?

I initially mapped the write values too high, so the transistor/motor was being written with values between 600 and 800 rather than 0-255. Does that actually do anything different than just writing 255?

The CIRC03 project instructions could be a little more clear about the diode, also. It was hard to figure out which end was which.

But, the whole thing is really cool. I was really pleased with myself. Maybe I’ll just get a new motor.

I’m not sure what you were doing to control the motor, I’m not familiar with the code involved. I’ll guess there was a PWM output to “write” to the transistor and use it as a switch for the motor which was in turn connected to 5V and the transistor. The motor looks like a pretty cheap affair, rated from 1.5-4.5 V. They generally don’t have all that long a lifetime and less when run at their max voltage. So yes it could have died. You can find out by simply connecting it to 5V and ground or better yet use a AA battery (1.5V). It’ll either run or it won’t. Can’t hurt the battery.

I just found the “manual” and looked at the code for CIRC-03. There’s a few variations so I’m not sure which one you were doing and what mods you made to use the flex sensor so I can’t tell what effect an 800 might have had vs a 255. Generally speaking the transistor is either on or off, the motor running or coasting. I see one option was to use the analogWrite function (vs digitalWrite). This is the [PWM function I mentioned above. A 255 gets you a 100% duty cycle, full on all the time, same effect as a digitalWrite(1). I’d guess an 800 gets truncated to a 255 and so is no different than a 255.](http://arduino.cc/en/Tutorial/PWM)

Update in case anyone is reading this:

It looks like the Arduino resets or disconnects if a negative number gets written to the PWM output pin, so I constrained it not to do that.

Also, the motor wasn’t burned out, but the leads are so thin they don’t hold in the breadboard well. So, I wrapped them around header pins. They stay connected better now, but still wiggle loose a bit when the motor spins. Ordered a bigger motor. Hopefully it has thicker leads.

And it still disconnects sometimes due to, I don’t know what, reverse voltage spikes when power is cut to the motor maybe? The project plan in the guidebook recommends a capacitor to stop that, so I ordered one of those. If the disconnecting can be stopped, I have a working circuit and will be expanding the features. Woot!

A flyback diode might work better to prevent the voltage spikes caused by turning the motor on and off:

http://en.wikipedia.org/wiki/Flyback_diode

Reacharound:
Also, the motor wasn’t burned out, but the leads are so thin they don’t hold in the breadboard well. So, I wrapped them around header pins. They stay connected better now, but still wiggle loose a bit when the motor spins. Ordered a bigger motor. Hopefully it has thicker leads.

You might think about getting something like [these and cutting one in half to make 2 connectors to fit over the header pins. Or [these to do likewise and plug directly into the breadboard. Solder or crimp the other ends to your motor. Or perhaps just solder/tin the motor leads to thicken them up.](Jumper Wires Premium 6" M/M Pack of 10 - PRT-08431 - SparkFun Electronics)](Jumper Wires Premium 6" F/F Pack of 10 - PRT-08430 - SparkFun Electronics)

Valen:
A flyback diode might work better to prevent the voltage spikes caused by turning the motor on and off:

http://en.wikipedia.org/wiki/Flyback_diode

The breadboard layout here http://ardx.org/src/circ/CIRC03-sheet-OOML.pdf has a flyback diode, and I am using it. It also shows an optional capacitor which doesn’t come with the kit, and I read somewhere that I can no longer find that it is for the purpose of preventing resets.

Actually, I can’t really decipher where that capacitor is supposed to go on the breadboard, so if anyone has any insight there, that would be super cool.

This project taught me what a flyback diode is for, so that made me happy.

Reacharound:

Valen:
A flyback diode might work better to prevent the voltage spikes caused by turning the motor on and off:

http://en.wikipedia.org/wiki/Flyback_diode

The breadboard layout here http://ardx.org/src/circ/CIRC03-sheet-OOML.pdf has a flyback diode, and I am using it. It also shows an optional capacitor which doesn’t come with the kit, and I read somewhere that I can no longer find that it is for the purpose of preventing resets.

Alright, wasn’t sure how you had your board setup in the above posts. You didn’t mention the diode.

Actually, I can’t really decipher where that capacitor is supposed to go on the breadboard, so if anyone has any insight there, that would be super cool.

This project taught me what a flyback diode is for, so that made me happy.

In that breadboard schematic, the optional capacitor leads are directly above the +5v and GND rails on the side of the board. Seems clear to me.

Oooooh! I see. Thank you.

I wonder what that does. It will be repeatedly just… building up charge from the Arduino and then releasing back. Maybe that causes a wake-up/re-connect.

If you don’t mind answering one more question- is that something that should be included if I moved this project to a PCB, or is it just something specific to using the breadboard and Arduino?

Be mindfull if you are using a electrolytic capacitor (elco for short) that you need to keep an eye on the right polarity. Or else it might blow up on you. There should be a minus on the casing indicating the lead that goes to ground.

The reset is likely caused by the board voltage 5 volt to sink too deep when switching the motor. Ideally you would want to measure this behaviour with some sort of oscilloscope. To see how the voltage changes after switching. The capacitor holds a certain amount of surplus electrons which it can supply incase the battery voltage sinks during the switch. Capacitors are the electrical equivalent of water towers. They keep the pressure up (voltage) and are a temporary supply of waterflow (current).

It isn’t just a breadboard phenomenon. Almost all ICs (and voltage regulators too) need capacitors (nearby on the PCB) to even-out temporary current surges.

Ah. That’s a great explanation. I’ll read up on using capacitors in that role. Thanks for answering my questions.