08m2 knock box mosfet problem

steviejay

Member
Hi
I have a student project at year 7 making the same knock box discussed on the forum, also on instructables, but using 4.5v instead of 6v.

A piezo responds to knocking, stores the count and the duration between, then controls a small motor with a weight to repeat the pattern.

It functions, but the voltage is so low through the mosfet switch that the knock is too weak

the original plan used 6v dropping to 4.5 thru signal diodes for the 08m2, but keeping the full 6v at the motor.

Because Im using 4.5v I tried dropping to 3.75v to the 08m2 to get the voltage difference for the mosfet but no change at the motor.

the circuit diagram attached is the copper foil cut I'm using for students to solder to, I hope you can decipher it

Question
How can I get the full 4.5V at the motor thru the mosfet... at present it shows less than 1v on the meter.

thanks for any help
knock box using 4.5V copper cut  circuit diagram2.jpg


Code:
#picaxe 08m2
'setfreq m4								'Not necessary at 4MHz - Saves 4 bytes

'	Assign names to pins, variables to registers,and constants.

symbol rnd		=	w6				'Word variable : Current random number
symbol kdel		=	w5				'Word variable : Delay between last and current knock input

symbol cnt1		=	b0
symbol kcnt		=	b1				'Number of knocks
symbol pptr		=	b2				'Pointer to knock delay storage array

symbol tmp1		=	b6				'Reusable variable
symbol tmp2		=	b7				'Reusable variable

symbol mic		=	Pin1			'Microphone input (can also be output)
symbol spkr		=	pin2			'Lautsprecher
symbol knock	=	4					'Knock motor output
symbol led		=	0					'Indicator LED for testing

symbol pstart	=	$50				'Start of storage area
symbol tmax 	=	1000				'Time-out value for delay - About 1.5 seconds
symbol settle	=	80				'Settling time for microphone


'	This section is where the person knocks.
'	The time between successive knocks is stored 
' until there is a pause of 1.5 seconds or so.



do												'Start of main loop
	kcnt = 0								'Initialise knock counter
	input 1									'Define mic as input to detect knocks
	
	sertxd ("ready for knock ",13,10)
	do
		for kdel = 1 to tmax				'KDel is counting loops to determine time between knocks
	
			if mic = 1 then						'Detect HI on microphone input
			sertxd ("detecting mic ",13,10)
				inc kcnt								'Add 1 to number of knocks
				high led								'Flash LED to help debugging
				pause settle						'Wait for oscillations to stop
				low led
				kdel = kdel + settle		'Add settle time to loop counter for accuracy
				pptr = kcnt * 2 + pstart'KCnnt is a word variable so need to add 2 to pointer  
				poke pptr,word kdel			'Write the delay from last knock to storage area
				kdel = 0								'Reset kdel ready for next knock
			end if	
		next kdel	
	loop until kdel >= tmax				'If no knocks for over TMax loops then leave loop
	
	
'This section will operate sepending on the number of knocks detected.
'If there are no knocks it will exit.
'Other things happen on 13 or 20 knocks, or it will echo the knocks for any other number.
'The maximum number of knocks is 23 to fill buffer. Incorrect count after that.
	
		select case kcnt

		case 0
		sertxd ("waiting for knock ",13,10)											'Do nothing if no knocks have occurred
		
		case 20											'If 20 knocks play go into prank mode
			gosub twoknock
			wait 30										'Do nothing for 30 seconds
			for tmp1 = 1 to 50				'Make 50 knocks with random spacing 
				random W6								'Generates next random word
				tmp2 = rnd + 100				'Make delay value from random value
				gosub doknock						'Make a knock
				pause tmp2							'Pause for the random delay number of milliseconds
			next tmp1									'Loop until 50 knocks done	

		case 3
		
		sertxd ("doing crazy stuff ",13,10)											'Piecax's favourite number
		high knock
		pause 200
		low knock
		pause 300
		high knock
		pause 200
		low knock
		pause 300
		high knock
		pause 200
		low knock
		pause 300
		
	
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high knock
		pause 200
		low knock
		pause 300
		high knock
		pause 200
		low knock
		pause 300
		high knock
		pause 200
		low knock
		pause 300
		
			high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100
		
		high c.2
		pause 100
		low c.2
		pause 100

		else 												'Any other number of knocks will be echoed
sertxd ("responding to knocks ",13,10)
		for tmp1 = 1 to kcnt				'Loop for the number of knocks
			pptr = tmp1 * 2 + pstart	'Step in twos through buffer
			peek pptr,word kdel				'Read back delay value words from buffer
			pause kdel								'Wait the delay time (in milli-seconds)
			gosub DoKnock							'Perform a knock
		next tmp1										'Loop for next knock
		pause 200
		
	endselect
		
loop


'	This section contains the knocking routines

DoKnock:
	high led										'Turn on LED
	high knock										'Turn on motor
	sertxd ("moota on",13,10)
	pause 100	
	sertxd ("pausing",13,10)									'Wait 100 milli-seconds was 70 before
	low knock 										'Turn off motor
	sertxd ("moota off ",13,10)
	low led											'Turn off LED										
return

TwoKnock:												'More compact to do this as subroutine
	pause 580											'Two knocks with timed delays between for tune
  gosub doknock
	pause 730
	gosub doknock
	pause 730
return
 

premelec

Senior Member
Probably too high a gate voltage required on this - you need a LOGIC LEVEL MOSFET - possible IRL540 would work - there are many LL MOSFETs so give one a try... What CURRENT does the motor require??
 

steviejay

Member
thanks
the mosfet is the same one the original specified and seemed to work ok there, still thru an 08m2 only 6v on the drain side

the motor says 200mA

this is the original using 6v(and a speaker which I didn't use)

original knock box using 6v.jpg
 

Goeytex

Senior Member
Premelec is correct. The IRF540 cannot switch properly with only 4.5 gate drive. The FET may never fully turn on, Since the gate threshold can be as high as 4.0V.

The IRL540 has a max gate threshold voltage of 2.0V, meaning it will fully turn on with a 4.5v gate drive. This should solve your problem.

Another solution is to use a standard NPN transistor instead of the FET. Since the current is only 200 milliamps you don't need a 20 Amp FET. Any general purpose NPN transistor rated at 600ma collector current should work fine. Put a 470 ohm resistor between the Picaxe and the base of the transistor.
 
Last edited:

steviejay

Member
thanks that works ...the NPN...

Gooeytex can you explain how you arrived at the 470 resistor?

help is very much appreciated...and I have lots of transistors and no IRL540 s

Steve
 

Goeytex

Senior Member
... can you explain how you arrived at the 470 resistor?
If we assume a gain of 100 in the transistor and a collector current of 200 ma, then we need
a base current of no less than 2 ma.

Using ohms law .... 4.5v / .002 amps = 2250 ohms. So a 2250 ohm resistor will get us there, but just barely.
To assure saturation we need to use a lower resistance that does not allow more current than the Picxe can supply:

This gives a pretty wide range of workable resistor values

The Picaxe can supply about 20ma so the workable current range is from .002 amps to .020 amps.

Again using Ohms law that gives a resistor range from 225 ohms to 2250 ohms

I selected 470 ohms because it provides a base current of ~ 10ma which is well within the capability of the Picaxe while
also assuring full transistor saturation. However, A 1000 Ohm resistor will work just as well, while reducing the current
load on the Picaxe to about 4.5 ma.
 

premelec

Senior Member
@Goeytex this is certainly a correct approximation however at the PICAXEs output capabilities and low voltage I think Vbe should be in there... ca. 4.5 - .8 volts - and being an empiricist I would suggest OP actually measure current estimated vs measured [though current meter resistance then also comes in...]. And of course whatever works... though it's nice to know how close to not working you are...
 

Goeytex

Senior Member
All I could really do is estimate and provide a fail safe value since we do not know what transistor is selected (hFE ), or what the actual motor current is. And as you said, these can only truly be known by actual test & measurement. Most hobbyists will not bother to take the measurements even if given the precise methodology and step by step instructions. Some won't bother to read the manual or open a datasheet. ( Datasheet?.. What's that). Others are willing but may not have the skills or experience to understand a datasheet. Most are not electronics gurus or EEs and have no aspirations to be. They just want a solution and a simple explanation.

So when giving advise here on something as common as what resistor to use or how it was selected, I generally take the approach of keeping it simple,and understandable to the average Picaxer, while suggesting a solution that is likely to work.
 

premelec

Senior Member
@Goeytex - I thought you did an admirable job of explaining and suggesting the BJT - just suggested a little more hardware understanding - There is a lack of encouraging ohm's law calcs or even to referring to what that might be in the manuals. Having read this Forum for a decade or so I understand that there are extreme differences in experience with hardware [and software but we've pretty much agreed to stick with PICAXE BASIC!]. We both realize that success of a project depends on hardware working as well as the software... Thanks for your many clear statements to users of the forum! I think Manual 3 could use some revision especially things like LL MOSFETs being called out and FET drivers and such... However I'd like a 14X2 part and perhaps they are busy working that up! AXE onward!
 

steviejay

Member
I appreciate the intent all round thankyou. The knockbox works, though the kick in the motor is somewhat less thru the transistor than if I hook it straight up to the battery pack. Perhaps why the original had 6v?.

I am limited to 4.5v(have to keep the whole project under $9) and small cheap motors dont have much torque.

As far as the complexities of refined electronics go, I made sense of the concepts Gooeytex elucidated, became a little smarter, and moved one step forward. I can build anything you want from wood, from joinery to houses...but rely on other clever people to help fill in the blanks in this department. And asI soon intend trying to put a compass module steering arrangement onto my fishing torpedo I'll be back
thanks again
Steve
 

AllyCat

Senior Member
Hi Steve,

...the kick in the motor is somewhat less thru the transistor than if I hook it straight up to the battery pack.
Yes, that is what I suspected / feared. I was unsure whether to contribute to this thread when faced with Goey's rather "simplistic" explanation (when we know that he has the ability to explain it fully). His reasoning was probably correct, but I take the view that as a teacher you might want a more detailed explanation, either out of interest, or to reduce the risk of being "caught out" by questions / observations from a student. ;)

Firstly, IMHO changing to a NPN (bipolar) was absolutely correct (but AFAIK a type number has not been quoted). For many low voltage / low current applications a bipolar transistor is probably cheaper and maybe actually better than a FET. However, my calculation of the resistor for "10 mA" base drive is a little different. Actually, 10mA is probably as much current as can be expected for a PICaxe output to "pull up" (the PIC data sheet is more pessimistic). As premelec says, the Vbe will "lose" 0.7 volt, and the PICaxe output stage perhaps another volt. Then, in this "ecological" age, I prefer NOT to consider "fresh" Alkaline batteries, but around 1.25 volts per cell (i.e. 3.75 volts) either to accommodate rechargeables (NiMH) or Alkalines that are around half way to their (manufacturers') rated "end of life". That gives us nearer 2.0 volts across the resistor, so I'd use 180 or 220 ohms.

Secondly, a simple d.c. (mechanical commutator) motor can apparently "break" Ohm's Law, as do incandescent (or tungsten filiament) lamps. My suspicion is that if you measure the resistance of your "200mA" motor with a multimeter it will read much less than 30 ohms (6 volts / 0.2 Amp) or even 20 ohms. Similarly, the (cold) resistance of a tungsten filament lamp measures less than 10% of the value calculated from its wattage (because the resistance increases greatly as its temperature rises to emit light).

For dc motors, the corresponding effect is caused by "back emf" (emf = voltage). When a motor turns, it acts as a generator (motors and generators are fundamentally interchangeable) with the generated voltage "cancelling out" some of the applied (battery) voltage. So, until a motor starts to turn (fast), it may draw much more current than the rated (200 mA?) value (a multimeter and Ohm's Law should tell you how much). If the current is limited by a transistor ("running out of current gain") then the motor may start much more slowly. That is not necessarily a bad thing (even an advantage in some applications) but for your application with a short pulse of energy, it may produce an inferior "knock".

Thus you might actually "need" a 1 amp driver (which makes the original 20 A device look not quite so daft). However, if you wish to proceed further, there will no doubt be much (conflicting) advice about whether a "Darlington", "Emitter Follower" or "Complementary Driver" configuration, or a return to a Logic Level FET, is the "best" solution.

Cheers, Alan.
 

erco

Senior Member
I had excellent results using a 9V battery driving a small solenoid through a small power transistor.

 

premelec

Senior Member
@erco - that's great and leads me to ask; have you tried it with a tone fed back to the piezo? Your whistling inspired the thought that it might sound good!
I'm not acquainted with the code for this [in Stamp or PICAXE so I don't know if it would be easy to incorporate varying length tones - it would seem likely by just making them a portion of the time between knocks... maybe I'll knock one up if I can find the code...

I've looked for the code and not found it - please post code - Stamp or PICAXE - or link to same - thanks!
 
Last edited:

erco

Senior Member
Thanks premelec. Not sure how well the piezo would work as a mike, with harmonics and all, but certainly an interesting concept. My tiny BS1 code attached here; there are only 256 bytes of memory there for program and EEPROM tap memory. This other video shows another way to use the knock box in a looping mode which worked surprisingly well.

Code:
' {$STAMP BS1}
' {$PBASIC 1.0} 12/13/11
' BS1 KNOCK BLOCK by erco
' solenoid output on pin0
' piezo input     on pin1
' loop switch     on pin2  0=single  1=loop
' memory switch   on pin4  0=record  1=play from EEPROM

'q:DEBUG PIN2
'DEBUG PIN4
'GOTO q
'w:  PULSOUT 0,1000
'PAUSE 300
'GOTO w



PAUSE 2000        'wait to close lid after switching on
IF PIN4=1 THEN b  'skip ahead to read from EEPROM
DEBUG "RECORDING"
a:IF PIN1=0 THEN a'  wait for initial hit
FOR B0=0 TO 50'  knock counter, up to 20 knocks
FOR W1=1 TO 1000' count loops
IF PIN1=1 AND W1>60 THEN hit' ignore sensor first 60 loops, lid & sensor ringing
NEXT
DEBUG B0,"TIMEOUT!"
GOTO playback
hit:
B1=W1/4'  scale down time delay to store as byte
WRITE B0,B1
fin:
NEXT
playback:
DEBUG "PLAYBACK"
B4=B0-1
b:IF PIN1=0 THEN b'  wait for initial hit to start playback
PULSOUT 0,1000 'first knock
c:FOR B0=0 TO B4
READ B0,B1
B1=B1-3 'was 3 'fudge factor, adjust for record/playback delays
W1=B1*71/10'was 68 73/10'  was *7  'time factor adjustment
PAUSE W1
PULSOUT 0,1000
NEXT
IF PIN2=1 THEN a  'go back to record new sequence
GOTO c
 

premelec

Senior Member
@erco - I'll look at the code later - I had in mind that the piezo could be used as a pickup AND sounder on the same pin - I did this once with an LED as photovoltaic generator on a READADC pin which could be switched to light the LED as well. In any case even another piezo with short bursts of tone could could work instead of a motor. I did like the boxes so many years ago which had a hand that came out and turned off a switch if you turned it on - fun! [I think those were entirely electromechanical].
 

steviejay

Member
further to the issues Im having

I have retreated into a 6v to try to get a motor kick that can be returned(even a soft rubber band is too much for the motor to pull against)
I get more oomph with the 6v, but still marginal, the motor on the piecax instructables version gravity returns(mine wont lift anything that is heavy enough to fall)

and I wont be able to get 130 11 year olds to adjust something that's too subtle...

I tried a bc547 which works ok with the resistor,( I see its rated at 100mA continuous?) a bd139 not so good...and seems to be no more punch with the irf540 mosfet back in there( I cant get hold of an IRL 520 logic mosfet) which strangely got very hot occasionally and the motor would jam on

so I'm on the edge of canning the project and retreating back into something dead boring(even though I have 130 sets of bits...thinking I had it sussed)

My last question: would setting up a pair of transistors be likely to improve the response of the motor?
I love the solenoid...maybe next year...

thanks for the discussion everybody
Steve
 

erco

Senior Member
@steviejay: Your multi transistor idea has merit. If you could reverse your motor, then you wouldn't need a rubber band, you just reverse the motor and it strikes the case on either side, alternating back and forth to make taps.

@Technical: I love that Glockenspiel, I have considered making one from scratch. Any video to share? Make it a prize in your monthly project contest and I'll submit more stuff!

Edit: found your video at https://www.youtube.com/watch?v=Rt7vI6oZLcw
 
Last edited:

erco

Senior Member
@premelec: Sure, I have several of the old whistle keychain beepers, which used one piezo as both speaker and mike. Those were optimized for high frequency use. Would be great if a Picaxe could determine whistle frequency without needing a FFT routine. :)
 

premelec

Senior Member
@steviejay - please post a picture of your actual mechanical motor setup - if the motor works without the weight there's hope! Also you could put the motor signal to a cheap buzzer [15 cents or so on ebay] which would be a not as impressive but functional knock back signal...


BTW there are assembly instructions for Tech's ref here: https://www.youtube.com/watch?v=HMAbaz4zmbI
 

Videostar

New Member
Try using a "darlington" transistor - a possible NPN type is TIP121. It has a gain of around 1000 and can handle over 5 Amps on a suitable heatsink. If you only need a lower current or smaller device package then something similar to a BCX38C (gain of 10000 and 500mA current handling) may suffice.
 

AllyCat

Senior Member
Hi,

+1. For a quick test, you can just "make" a Darlington from the BC547 and BD139 that you already have (in #16). Or, as I said in #11: ;)

you might actually "need" a 1 amp driver ..... However, if you wish to proceed further, there will no doubt be much (conflicting) advice about whether a "Darlington", "Emitter Follower" or "Complementary Driver" configuration, or a return to a Logic Level FET, is the "best" solution.
Cheers, Alan.

PS: Welcome to the forum Videostar.
 

Goeytex

Senior Member
A Darlington is liable to make things worse. The voltage drop across the Darlingtion will reduce the effective voltage to the motor and thus reduce the drive current.

Attached are 2 circuits. One uses a single NPN BD139 and another uses a Darlington from a BC547/BD139. The expected voltages and currents are shown.

If the single NPN circuit does not give enough "knock", then I suspect that the motor may be overrated and not adequate for project. I would measure the resistance of the motor winding and see what it is. If rated at 200ma @ 6v, then is should be "close" to 30 Ohms.

I would then apply 6v to the motor and measure the actual current. Is it 200 ma ?
 

Attachments

Last edited:

erco

Senior Member
+1 to Goeytex citing that one or two 0.7 V drops (from bipolar & darlington transistors) can be very detrimental to small low voltage DC motor performance (torque). The original idea of a mosfet is much better in that regard. Another option would be to drive a 5V reed relay directly from the Picaxe, which would then switch the motor with full battery voltage.
 

nekomatic

Member
I may be proving Allycat's prophecy correct here, but just for the sake of it: if you really want to use the BC547/BD139 combo in Circuit 2, you could connect the BC547's collector via a resistor to the 6V supply instead of connecting it to the BD139's collector. You will then turn the BD139 full on with no 0.7V voltage drop, but at the cost of 'wasting' its base current rather than drawing this from the load. Choose your resistor to give adequate base current at (6V - 0.7V), obviously.

I would then apply 6v to the motor and measure the actual current. Is it 200 ma ?
Bearing in mind the voltage drop across your current meter ;)
 

AllyCat

Senior Member
Hi,

you could connect the BC547's collector via a resistor to the 6V supply instead of connecting it to the BD139's collector.
Ah yes, that's effectively the "emitter follower" (driver) that I alluded to in #11. ;)

Or, to get back to the OP's 4.5 volt supply (or my prefered 3.75v design figure), use a PNP driver (BC557,BC327, etc.) if the OP has one, in a "complementary" driver configuration. Only one Vbe drop, plenty of current gain and a PICaxe is rather better at pulling "down" (a PNP base) than "up" (a NPN base).

But we really need to know the "stalled" current that the motor needs, easy to measure with a multimeter (I = V/Rdc, V=battery volts, Rdc from a multimeter), perhaps turning the motor very slowly to ensure contact integrity through the commutator brushes (assuming it is a mechanical commutator type motor).

Cheers, Alan.
 

erco

Senior Member
@steviejay: What batteries are you using? Please say 3xAA size or bigger.

And which motor? Can you post a photo or video?
 

premelec

Senior Member
I think we really need a a picture of the motor setup that is NOT working to judge how that may be rectified... Hope OP hasn't given up! [and does the motor work ok when simply energized directly...].
 

Goeytex

Senior Member
I think the best clue to problem is in this statement.

I get more oomph with the v6v, but still marginal, the motor on the piecax instructables version gravity returns(mine wont lift anything that is heavy enough to fall)
If the motor is marginal when driven directly from the the batteries, or the batteries do not have enough capacity, then no circuit arrangement is going to solve the problem. If the batteries are fresh and have enough capacity, then it seems to me that the motor is too weak and not suitable for the application.
 
Top