Tacit Modification for Blind Friend

Well... I've managed to create my own library that works (yay!)
It will read the PING))) sensor and return distances in inches or centimeters.
Now I need to figure out how to vary the vibration on a motor...

Where can I learn how to control the vibration of the motor and have it spin faster the closer an object is?

Should be pretty simple to interface a small vibration motor as they draw little current. You would use a pwm output pin and use the analogWrite(pin#, value); to set the motor speed in your sketch code where value = 0 would be off and value = 255 full speed. The following circuit would show you the electrical connections you would need (the motors two terminals would replace the solenoid shown in the picture). You may have to find the actual pwm value where the motor just starts to turn as starting at 0 might be too low a starting value.

Hello there,Hackmodford
i read your project and i think what you are trying to do is awesome let me try to help you as much as i could,
urm first of all i think you are able to make the ping)) sensor to work rite, in what range is the max and the min that it can return. use that as a source of your mapping,then translate that to your motor. why not use a pager motor. its small and i think it provide a good vibrational force.

anyway this may help you a bit on the programming part

int Pingreturn=   //i dont know this part in your setup
int speed = map (Pingreturn,Min,Max,255,);
analogWrite(Motorpin,speed);

Be careful what sort of vibra motor you buy.
Some require an H-bridge to drive them.
Make sure you buy the simple DC motor type with eccentric weight.

Okay thanks guys,
I've managed to get it working... I found someone else that's essentially done the same thing and took their code and slightly modified it. Here's what I came up with.

/*
  Tacit Flashlight/Vibration Code
  Created by Brandon Butler, December 4, 2012.
  Released into the public domain.
*/

#include <Ping.h>
#include <DebugUtils.h>

//#define debug //debug for debugging, anything else otherwise
const int pingPin = 7;
const int vibPin = 3;
int pulseOut = 0;

Ping ping;

void setup() {

	// initialize serial communication:
  	#ifdef debug
  		Serial.begin(9600);
                Serial.println("Testing");
  	#endif
  	pinMode(vibPin,OUTPUT);
}

void loop() {
  
        long inches;

	// get inches from PING)))
	inches = ping.pingInches(pingPin);

	//vibrate proportionally to closeness
	pulseOut = inchesToPulse(inches);
	analogWrite(vibPin,pulseOut);

	DEBUG_PRINT (inches);
	DEBUG_PRINT (pulseOut);

	delay(100);
	analogWrite(vibPin,0);

}

float inchesToPulse(float inches) {

	//curved function so closer distances have more variation
	int MaxInches = 240;
	int minPulseOut = 100; //vib motor won't spin below ~50-70

	//(3 was way too steep) Only felt motor within a foot or two
	float powerConst = 2; //steepness 1 for line >1 for steeper
	int pulseOut;
	pulseOut = (int)(pow(((MaxInches - (float)inches)/MaxInches),powerConst) * (255.0-minPulseOut)) + minPulseOut;
	if (pulseOut <= minPulseOut) { pulseOut = 0; }
	return pulseOut;

}

I took a motor from a gamecube controller. I assume it uses either 3.3V or 5V to run.
I have the arduino pin wired directly to the motor and it seems to work fine. Should I do anything else?

Should I do anything else?

Yes, you should remove the motor before it damages your Arduino. (it may already be too late)
Some of these motors can draw more than twice the maximum current allowed from an I/O pin.
Use a transistor to buffer the motor, and add a snubber diode.

I'm not exactly sure how to do this. I'm more of a software guy than hardware...

Can you provide a link to the transistor and diode I would need? And also a schematic I can follow?

(edit: I suppose the schematic provided for the solenoid is what you're referring too? So would I just use the regulated 5V line off of the arduino (that is powering the ping) to also power the motor? And then use a data line to go to the transistor? If so what transistor and diode do I need?)

I am using the Arduino Pro Mini 5V.

So far the project has been a real success!

Thanks for all your help.

(edit2: Going from this site arduino | AK Eric the author claims that the motors only draw 20ma. My pins can provide 40ma each so I should be good. Also I just realized that only 6 of the 14 pins can be used for PWM and I got lucky and picked #3 for the motor :smiley: Since the motor should be fine I don't need the transistor but should I use anything else?)

Hackmodford:
I'm not exactly sure how to do this. I'm more of a software guy than hardware...

Can you provide a link to the transistor and diode I would need? And also a schematic I can follow?

(edit: I suppose the schematic provided for the solenoid is what you're referring too? So would I just use the regulated 5V line off of the arduino (that is powering the ping) to also power the motor? And then use a data line to go to the transistor? If so what transistor and diode do I need?)

Depends on the current requirement of the vibration motor you are using. Most are very small motors so powering them from the arduino 5v pin should be fine. Note that some vibration motors are rated at 3.3vdc max and might end life early if operated at 5 volts. The size of the transistor again depends on the current draw of the motor, the one shown in the solenoid drawing is probably an overkill but it would work. A simple and common 1N4001 diode is fine.

I am using the Arduino Pro Mini 5V.

I've never used that board, just check what it's maximum rated current draw from the 5volt is to see if it matches what your ping and motor require together.

So far the project has been a real success!

Thanks for all your help.

(edit2: Going from this site arduino | AK Eric the author claims that the motors only draw 20ma. My pins can provide 40ma each so I should be good. Also I just realized that only 6 of the 14 pins can be used for PWM and I got lucky and picked #3 for the motor :smiley: Since the motor should be fine I don't need the transistor but should I use anything else?)

So my next question, if I skip the transistor part how do I wire the diode?

Edit:
I found this diagram on this site http://www.coactionos.com/embedded-design/39-motor-control.html

In my case is that what I should do?

So my next question, if I skip the transistor part how do I wire the diode?

You don't skip the transistor part until you've proven that the motor doesn't draw more than about 30mA when you clamp the output shaft.
With or without the transistor, you wire the diode in parallel with the motor, with the cathode to the positive side.

AWOL:

So my next question, if I skip the transistor part how do I wire the diode?

You don't skip the transistor part until you've proven that the motor doesn't draw more than about 30mA when you clamp the output shaft.
With or without the transistor, you wire the diode in parallel with the motor, with the cathode to the positive side.

LOL... I'll get my multimeter and double check.

And will just use a diode as you suggest.

Thanks :slight_smile:

I've attached a schematic. I assume this is what I should do?

schemeit-project.png

Hackmodford:
I've attached a schematic. I assume this is what I should do?

First the diode is wired backwards creating a short circuit, reverse it. Then test the motor current draw.
Only if the current draw from the motor is around 30ma or less should you wire it directly to a output pin without using a switching transistor. You should first wire it to the arduino 5V pin and then with your multimeter wired in series take a current measurement. Only then if under 30ma or so should you wire it to a arduino pwm digital output pin.

Lefty

retrolefty:

Hackmodford:
I've attached a schematic. I assume this is what I should do?

First the diode is wired backwards creating a short circuit, reverse it. Then test the motor current draw.
Only if the current draw from the motor is around 30ma or less should you wire it directly to a output pin with using a switching transistor. You should first wire it to the arduino 5V pin and then with your multimeter wired in series take a current measurement. Only then if under 30ma or so should you wire it to a arduino pwm digital output pin.

Lefty

Excellent :slight_smile: I believe that's all I needed. And you guys have my code so if anyone wants to make one feel free :slight_smile:

Here's some pics for the project





I have added a corrected version of the snubber diode diagram.

schemeit-project-1.png

I also added a buzzer so that it beeps when you turn it on per my friends request. I got the diode wired up and all is working fine now.

That motor looks like a playstation controller motor, definitely will take more than 30mA (the size of the motor gives it away),
that transistor isn't optional (unless you're happy for the Arduino to fail randomly at some point).

I'll double check. Can you point me to a transistor I could buy at radioshack?

The motor uses about 70mA

When I go to radioshack what transistor should I buy?