Simple code, should be a simple problem

High, just started coding python in may. Is there a reason I'm not getting any response from my vibration motor through this code?

const int motorPin = 3;

void setup()
{
pinMode(motorPin, OUTPUT);
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(motorPin, HIGH);
delay(1000);

digitalWrite(motorPin, LOW);
delay(9000);

if (motorPin == HIGH) { 
digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);              // wait for a second
}
else {
digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
}
}

I just added the led part, wanted to see if it would blink at all but no response.

In this post, you can see more about the project if you need any additional information. In the second to last post you can find the schematic. Pulsing vibration motor

|500x465

Thanks in advance. Olafsson

This is the Programming section, but I don't see any code.

lol... that's cause my head isn't screwed on. I'll add it to the first post now

if (motorPin == HIGH) {

Before this statement, you set motorPin to LOW. So this if statement will never evaluate to true.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

I hope you are not trying power the motor directly from the output pin of the arduino?
What model arduino is it?

Tom… :slight_smile:

if (motorPin == HIGH) {

You've defined motorPin to be a constant with a value of 3, therefore it can never be equal to HIGH which has a value of 1.

Pete

Hackscribble:

if (motorPin == HIGH) {

Before this statement, you set motorPin to LOW. So this if statement will never evaluate to true.

No matter what he digitalWrote() to motorPin, this will ALWAYS be false, because he’s not reading the pin!

if (motorPin == HIGH) {

motorPin is constant integer of value 3, making that equivilent to

if (3==1) {

which is of course always false.

You want to read the state of the pin, so you need to do:

if (digitalRead(motorPin)==HIGH) {

As others have noted, however, since you’ve set motorPin low, the pin will always be low when you check it (during that delay(), nothing else is happening; it looks like you think otherwise; see the tutorials on “doing multiple things at once” for exhaustive discussion of this issue and how to use millis instead of delay for timing)

TomGeorge:
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

I hope you are not trying power the motor directly from the output pin of the arduino?
What model arduino is it?

Tom… :slight_smile:

Added the circuit jpeg to the top post.

It’s an Uno TomGeorge

Thanks all for the quick response.

Hi,

Please do not update your original post like that. This thread can be a help to others with similar problems to you, by continually changing the first post, you are making a very disjointed thread. Just keep adding new post with your changes so the progression of finding a solution can be followed.

If you comment out all the IF bits that control the LED, does it work?

Tom.... :)

Hi

digitalWrite(motorPin, HIGH);
digitalWrite(13, HIGH);
delay(1000);

digitalWrite(motorPin, LOW);
digitalWrite(13, LOW);
delay(9000);

Should work without the IF....

Tom..... :)

TomGeorge: Hi

digitalWrite(motorPin, HIGH);
digitalWrite(13, HIGH);
delay(1000);

digitalWrite(motorPin, LOW); digitalWrite(13, LOW); delay(9000);




Should work without the IF....

Tom..... :)

Ok, I'll have another look over the circuit and see if there are any mistakes there. Thanks all!

Hi,
motorpin=3;

but you are using output 5? ? ? ?

motorpin =5;

Tom… :slight_smile:
Got to have another morning coffee

TomGeorge: Hi, motorpin=3;

but you are using output 5? ? ? ?

motorpin =5;

Tom.... :) Got to have another morning coffee

No, I've changed to 3, the sketch still says 5. Found out what the problem was, never used a LM317 before (or I've completely forgotten about it) and I hooked it up like shown in the drawing. Thought it might be the culprit so I googled the pinouts and fixed the wiring accordingly.

Now everything is up an running :)

Thanks all! First step of the project complete! Waiting on a haptic motor controller from adafruit http://www.adafruit.com/product/2305