Starter Project 9: Motorized Pinwheel problem

I'm having difficulty with the Starter Project #9: Motorized Pinwheel, and I was looking for some guidance on how to make it work.

I have done the usual - checked the code, checked the connections - but it still would not turn on. I read through other forum posts, and I saw one suggestion on changing the 10 kilohm resistor for a 220 ohm; that didn't; work, but when I removed the resistor completely, it worked (woo hoo!). Granted, the motor ran on its own, and the switch did nothing, but, as a noob, it was good to see that at least the motor did work.

My code and setup are below. I appreciate any insights as to where I might investigate further, so I could get this working properly.

PS I also changed the code and input to "8" as another post had suggested, replaced the switch, and used a different 10 kilohm resistor - none of these made any difference.

const int switchPin = 2;
const int motorPin = 9;
int switchState = 0;


void setup() {
  pinMode(motorPin, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop() {
  switchState = digitalRead(switchPin);

  if (switchState == HIGH) {
    digitalWrite(motorPin, HIGH);
  }
  else {
    digitalWrite(motorPin, LOW);
  }

}



For further assistance at least a DVM is required, to verify voltages on certain points.

I'm new so I'm assuming a DVM is a Digital VoltMeter; if I had one, what would I be checking for? Is the hypothesis there is something wrong with the connection points?

Start with the button pin, whether it changes for button pressed/released as expected.

1 Like

don't see anything obvious..
maybe button inserted wrong in breadboard??
if you don't have a meter to measure resistance or volts..
experiment first with button and motor..

1 Like

+1

Add code to drive the built-in LED and you can use it as a simple logic level detector. You'll still need to add pinMode, etc.

if (switchState == HIGH) {
    digitalWrite(motorPin, HIGH);
    digitalWrite(LED_BUILTIN, HIGH);
}
else {
    digitalWrite(motorPin, LOW);
    digitalWrite (LED_BUILTIN,LOW);
}

Try a new battery. Same thing happened to me. Used batteries may supply less current.

1 Like

Thanks - yeah, that was my thought, too, so I got even newer ones, still nothing.

Thanks - I tried rebuilding this in TinkerCad, and it worked. I used the exact same setup as what I had build, so it makes me think something is off on my board, or possibly one of the switches.

Thanks for the idea - I tried that out, and it didn't light up. To compare, I had build a simulation in TinkerCad, and that worked. Would this indicate, to you, that the issue is the switch?

Did you set the built in led pin as an OUTPUT?

If you bypass the switch and just plug the wire going to pin 2 into 5v or ground, does everything work properly?

Sometimes you have to really press those little switches hard into the breadboard to get them to make contact.

1 Like

I think it is a switch issue. I went through every one, and none of them worked, but when I replaced the switch with a connecting wire, it lit up.

I really jammed those buttons in, but I still couldn't get them to work. They used to work, but I must have fried them on a project (maybe the keyboard one), when I having trouble IDing the resistors.

Thanks very much for the help. 'Tis greatly appreciated!

The switches tend do pop out of my Arduino supplied breadboard. Other breadboards behave better.

And if the contact is always closed, rotate the switch by 90°.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.