Hello, I am trying to design a 'simple' circuit but I have no idea where to start. I am using tinkercad for the circuit simulation, I think I am able to handle the coding. Where do I start in the circuit design? Any videos or suggestions would be greatly appreciated. The platform I am using for coding is platformio on vscode. Attached is an image of a previous design, with a problem that pressing the button only shut off the motor, and the potentiometer gave off weird values.
Code:
int motorPin = PB1;
int runButton = PB5;
void setup() {
pinMode(motorPin, OUTPUT);
pinMode(runButton, INPUT);
}
void loop() {
if (digitalRead(runButton) == HIGH) {
digitalWrite(motorPin, HIGH);
} else {
digitalWrite(motorPin, LOW);
}
}
Goals: (Microcontroller - Digispark ATTINY85 micro USB development board)
DC motor controlled by a potentiometer
Button as the on-state for the motor (when the button is pressed it (motor) comes on).
(Note: Motor, and potentiometer being used come from the Arduino UNO starter kit.)
Again, any help is greatly appreciated.
It looks from your drawing like the button simply shorts the battery.
aka
digitalWrite(motorPin, digitalRead(runButton) ) ;
Why?
That's not what I wrote to change it to.
Hmm, okay, I changed the code to the following:
void loop() {
digitalWrite(motorPin, digitalRead(runButton));
}
However, I am still getting the same functionality as before, the motor still stops when the button is pressed, where I am looking for the opposite. Thanks for the response! I feel like there is something wrong with the circuit design/schematic but I am unsure.
Yeah, noticed I messed it up, sorry. But I did input your suggestion and am getting the same error.
You haven't shown a schematic.
Can't run a motor straight off a 'micro' pin.
A: Use a voltage regulator to provide regulated voltage to the processor. A fixed resistor is not going to work.
B: Your potentiometer should be connected between Ground and REGULATED voltage. The wiper of the potentiometer goes to an analog input of the processor so the processor can read the wiper position.
C: Your button should go between an INPUT_PULLUP pin and Ground. It should NOT be connected to power (regulated or not).
D: The PWM OUTPUT pin can't drive a DC motor directly. You need a transistor to allow the small current (<20 mA) from the processor to control a higher current or voltage.
...well, not for very long.
Okay, must be missing something here. I must have thought that writing a pin to HIGH passes voltage through the pin. I'll look into how it actually works.
It does.
Not much current though.
Okay, I will take the suggestions and get back when I make the changes. Thanks for the response!
Ahh, okay. Thanks for the clarification.
Does this look better? I know for the ATTINY85 you said a voltage regulator, but for the dev board I bought, I think it already has one but tinkercad just doesn't have the version I have.
Here is the code:
//
int potPin = PB1;
int motorPin = PB4;
void setup(){
pinMode(potPin, OUTPUT);
}
void loop() {
int regulatedPot = analogRead(potPin / 4);
analogWrite(motorPin, regulatedPot);
}
Any help will be greatly appreciated!
The schematic is much closer but you still need a voltage regulator. A fixed resistor just won't do it.
The diode across the motor there is backward.
Okay, thanks for catching that.
Okay, thanks for the response I will make the appropriate changes.
Will the motor work on 6V? A 4 AA pack will have a much greater current capability and you can use 1 or 2 silicon rectifier diodes (0.6V-0.7V drop each) in series between the + of the battery and Vcc of the tiny85. No voltage regulator required.