Maker Pro
Maker Pro

Beginner needing help - Simple timer circuit for reversing 5v motor

AnalogKid

Jun 10, 2015
2,665
Joined
Jun 10, 2015
Messages
2,665
I might have missed this back in the thread - what is the running current for one motor at 5 V?

Also, does the running time for each motor have to be settable in precise increments, or is an adjustment pot acceptable?

If the running current is less thean 100 mA and a pot is acceptable, then each motor can be driven by a pair of 555's (or one 556). No PICs, no code.

ak
 

Euan Williams

Jul 3, 2017
10
Joined
Jul 3, 2017
Messages
10
OK. I think if we drive T3 and T5 with two separate transistors and modify the code accordingly we can prevent this. Is this right? (In this case we will use 4 instead of 2 microcontroller pins).

Sumeryamaner and Alec_t - Thank you!!!

I will try my best to build the circuit as you have drawn it, Sumeryamaner. As I've said, I'm an absolute beginner, and I'll be getting help putting it all together - but I have a question about the comments between Alec_t and Sumeryamaner about the...
... high shoot-through current.
.. how should I incorporate these changes into the circuitary? (I'm asking you to make this idiot proof for me ;) )

Thanks so much again!!!
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
My suggestion is to forget the discussion and try my circuit. :) This is a relatively simple task if you do not use PWM for motor speed control. So you won't have serious problems.

If you want to eliminate the discussed problem (during switchover all MOSFET's will conduct momentarily (for a very short time which is negligible in this project) causing a short) you can use relays instead of MOSFETs.

For every P - N MOSFET pair you can use a relay (type C, SPDT contact) driven by the 2N2222.

The circuit with MOSFETs and with relays have been tested by me in my RC aircraft landing gear controller project with 5 - 12 V motors and both work without any problems.
 

AnalogKid

Jun 10, 2015
2,665
Joined
Jun 10, 2015
Messages
2,665
Each motor is so far apart from one another that controlling them with one Arduino or Raspberry Pi would be impossible
I don't understand this. If you already are running 5 V power and GND from somewhere to each motor, then why is one more wire "impossible". Or, what about a circuit (actually, 70 circuits) near the Arduino that sends reversing power out to the motors on 70 2-wire links?

Arduino -> 70-stage shift register ->-| -> 70 2-transistor power switches -> 70 2-wire links
5 V supply -> -5 V converter ->-|

ak
 

AnalogKid

Jun 10, 2015
2,665
Joined
Jun 10, 2015
Messages
2,665
Here is a completely stand-alone reverser circuit with minimal parts count. The max period is just under 9 minutes; add capacitors in parallel with C1 to increase.

Note: C2 and C3 are decoupling caps for the 555's. They are shown near the Reset pins only because that is a convenient place to show a Vcc connection.

ak
Motor-Reverse-5V-1-c.gif
 

Attachments

  • Motor-Reverse-5V-1-c.pdf
    8.6 KB · Views: 38

Euan Williams

Jul 3, 2017
10
Joined
Jul 3, 2017
Messages
10
I don't understand this. If you already are running 5 V power and GND from somewhere to each motor, then why is one more wire "impossible". Or, what about a circuit (actually, 70 circuits) near the Arduino that sends reversing power out to the motors on 70 2-wire links?

Arduino -> 70-stage shift register ->-| -> 70 2-transistor power switches -> 70 2-wire links
5 V supply -> -5 V converter ->-|

ak
Hi AnalogKid,

Sorry, I should have been more specific. Each motor is about 40-50m apart from one another, sometimes with walls in between one another. I thought it would be better (and aesthetically cleaner) having each motor much more stand alone - but too expensive for me to buy a brand new arduino for each of the 70 motors
 

Euan Williams

Jul 3, 2017
10
Joined
Jul 3, 2017
Messages
10
I might have missed this back in the thread - what is the running current for one motor at 5 V?

Also, does the running time for each motor have to be settable in precise increments, or is an adjustment pot acceptable?

If the running current is less thean 100 mA and a pot is acceptable, then each motor can be driven by a pair of 555's (or one 556). No PICs, no code.

ak

Hello AnalogKid,

Thank you for your questions. I don't know the answer to your first question, but yes, I was planning to use a simple 5v battery. I would prefer to use settable precise increments - but if all else fails I'ld love to try an 'adjustable pot', but I unfortunately I don't know what that is; Sorry - very much a beginner : (
 

Euan Williams

Jul 3, 2017
10
Joined
Jul 3, 2017
Messages
10
Do all of these motors need to operate synchously. If so, it is much more complicated.

Bob
Hello BobK,

All of the motors will be standalone and not connected with one another - although they will be running at that same time. Pleased to hear that the lack of synchronicity simplifies things ;)
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
If you want settable precise intervals I would recommend to use an Atmega328 instead of an Attiny85. I have to solutions:
1- You can use a rotary switch and set fixed periods. As Atmega328 has many I/O ports this can be done without any problems.
2- You can use serial communications. You can design a handheld device with an LCD display and you can connect this to each module and set the period. This would require a more sophisticated code. (Maybe in the next version you can use infrared to set the individual periods).
 

AnalogKid

Jun 10, 2015
2,665
Joined
Jun 10, 2015
Messages
2,665
Just to be clear, absolutely no wiring of any kind between/among the motors?

ak
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
All of the motors will be standalone and not connected with one another - although they will be running at that same time.
I don't know what "running at that same time" could mean, other than they are synchronized.

The question is, is there a time relationship between when the different motors run and reverse?

Bob
 

AnalogKid

Jun 10, 2015
2,665
Joined
Jun 10, 2015
Messages
2,665
[QUOTE="BobK, post: 1737205, member: 11295"The question is, is there a time relationship between when the different motors run and reverse?Bob[/QUOTE]
Since each motor's forward/reverse time is independently adjustable, almost certainly not.

ak
 

Euan Williams

Jul 3, 2017
10
Joined
Jul 3, 2017
Messages
10
Hello Sumeryamaner,

thanks for your help. I've spent a lot of time on this but I am unfortunately slightly flummoxed - It isn't working and I'm wondering what I'm doing wrong.

I think I know what I've done wrong and that is the coding - I've got PB0, PB2 as outputs and when I test them seperately I can make them flash LED bulbs ; ) but I couldn't work out how to code in the ADC3 input:

In the main loop you will read the ADC3 input. It will give you a value between 0 - 1023. You need a period between 20 - 6000 seconds. So you will map the reading to this range.
You will use delay(x) where x will be a number between 20000 and 6000000

Basically I've just made a blinking lights code and couldn't work out the coding that you suggested.

This is the breadboard I built (I think quite faithfully to what you suggested):

circuit.jpg


I was a bit of a fool in my original description, I said 5 volt power source - I meant 9V.
Here is your schematic again with info about the motor and the Mosfets that I used:

Circuit_adjusted.jpg


Can you see where I am going wrong (if it isn't the coding - which I am sure is the problem)? And if you can, could you help me and tell me how to fix it?

Many, many thanks in advance!

Kind regards,
Euan
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
Hello Sumeryamaner,

thanks for your help. I've spent a lot of time on this but I am unfortunately slightly flummoxed - It isn't working and I'm wondering what I'm doing wrong.

I think I know what I've done wrong and that is the coding - I've got PB0, PB2 as outputs and when I test them seperately I can make them flash LED bulbs ; ) but I couldn't work out how to code in the ADC3 input:



Basically I've just made a blinking lights code and couldn't work out the coding that you suggested.

This is the breadboard I built (I think quite faithfully to what you suggested):

circuit.jpg


I was a bit of a fool in my original description, I said 5 volt power source - I meant 9V.
Here is your schematic again with info about the motor and the Mosfets that I used:

Circuit_adjusted.jpg


Can you see where I am going wrong (if it isn't the coding - which I am sure is the problem)? And if you can, could you help me and tell me how to fix it?

Many, many thanks in advance!

Kind regards,
Euan

First of all there is a very big problem. The supply voltage. For the Attiny85 the absolute maximum supply voltage is around 6 V. It is highly possible that you have destroyed the microcontroller. A not so big problem is the motors. They are rated for 1.5 - 4.5 V and you have applied 9 V. Why?
You can fix these two problems by usng a 5V supply (the easiest way) or separating the microcontroller power by inserting a 5V regulator (cut the power line just to the left of the R4 and insert a regulator (7805 or similar). The latter solution requires that you change the motor and use a 9V type.

You can omit the flyback diodes because the MOSFETs you are using have them built in.

About the code... (Assuming you are using Arduino IDE)

Declare an integer variable. For example "int x;"
Declare a long variable. For example "long y;"

Now in the main loop:
x = analogRead(3);
y = map(x, 0, 1023, 20000, 600000);

Then use delay() function for the control of the intervals.

digitalWrite(0, !digitalRead(0));
digitalWrite(2, !digitalRead(2));
delay(y);

continue with loop...

What this code does is...

It reads the pot. It gets a result between 0 and 1023. These values correspond to the minimum and maximum periods (20 sec to 10 minutes). The map() function does this conversion. Then it inverts the motor driver outputs and waits for the calculated delay. Then repeats this.

Please note that in order this code to work you have to start the motors during setup(). That means;
digitalWrite(0, HIGH);
digitalWrite(2, LOW);
 

Euan Williams

Jul 3, 2017
10
Joined
Jul 3, 2017
Messages
10
First of all there is a very big problem. The supply voltage... you have applied 9 V. Why?

...

About the code... (Assuming you are using Arduino IDE)

Declare an integer variable. For example "int x;"
Declare a long variable. For example "long y;"

Now in the main loop:
x = analogRead(3);
y = map(x, 0, 1023, 20000, 600000);

Then use delay() function for the control of the intervals.

digitalWrite(0, !digitalRead(0));
digitalWrite(2, !digitalRead(2));
delay(y);

As ever - thank you so much!
Luckily I didn't burn out the microcontroller (it can still make the LED's blink : ) but I have followed your advise and gone down to 5 volts powersupply. There is no good reason for the 9volts other than that I had a 9 volt battery laying around - silly mistake.

It is unfortunately still not working. I am using Arduino IDE. How does this code look - have I made another silly mistake?

void setup() {
digitalWrite(0, HIGH);
digitalWrite(2, LOW);
}

void loop() {
int x;
long y;
x = analogRead(3);
y = map(x, 0, 1023, 20000, 600000);
digitalWrite(0, !digitalRead(0));
digitalWrite(2, !digitalRead(2));
delay(20000);
}

Thanks for your help and patience!
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
As ever - thank you so much!
Luckily I didn't burn out the microcontroller (it can still make the LED's blink : ) but I have followed your advise and gone down to 5 volts powersupply. There is no good reason for the 9volts other than that I had a 9 volt battery laying around - silly mistake.

It is unfortunately still not working. I am using Arduino IDE. How does this code look - have I made another silly mistake?

void setup() {
digitalWrite(0, HIGH);
digitalWrite(2, LOW);
}

void loop() {
int x;
long y;
x = analogRead(3);
y = map(x, 0, 1023, 20000, 600000);
digitalWrite(0, !digitalRead(0));
digitalWrite(2, !digitalRead(2));
delay(20000);
}

Thanks for your help and patience!

Attiny85 is interesting. I have connected 12V by mistake but the chips keeps working now. :)

One mistake in your code is:
not "delay(20000);"
but "delay(y);"

Another one is very important: You MUST declare the two ports as outputs.
pinMode(0, OUTPUT);
pinMode(2, OUTPUT);

Usually the two variables (x and y) should be declared before setup() but this doesn't prevent your code from running.

I would first check the hardware. That means, without the microcontroller in place, use jumper wires to connect the resistors at the bases of the driver transistors to +5V (one at a time) and check the motor is running. If not, there is a wiring problem.
So please be sure that the motor driver is connected properly. Then proceed to the microcontroller and the code.
 

davenn

Moderator
Sep 5, 2009
14,043
Joined
Sep 5, 2009
Messages
14,043
It is unfortunately still not working.

I'm not surprised ... you have wiring errors on your board .... you haven't followed the schematic

1) for a start ..... the negative of the battery ( black wire) isn't even connected to the circuit .... it should be in the top blue negative rail of the board

2) the capacitor in the top right corner is wired incorrectly ..... it should be between the blue rail and the red rail

3) your diodes are not correctly wired .... the top 2 are, the bottom 2 are not

4) You don't even have the P1 trim pot in there

there's 4 obvious mistakes with just a quick glance ;)


Dave
 
Top