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

#### Euan Williams

Jul 3, 2017
10
I’m an absolute beginner and I believe I have started a project which is beyond me and I really need some help!

I’m working on a project involving 70 small 5 volt motors.

I need each motor to turn in one direction for a certain amount of time, and then in the other direction for the same amount of time… and then back again in a constant loop and never ending loop.

The time of the changeover should be different for each motor and pre-programmable. The times vary between 20 seconds and 10 minutes.

Each motor is so far apart from one another that controlling them with one Arduino or Raspberry Pi would be impossible – And buying an Arduino per motor would be too expensive.

What would a cheap, effective and reliable system (which I could build myself) be? I was thinking transistors and a relay – adding the transistors to make the delay larger. But I think this is a bad idea - and anyway, I have no idea how I could make that work. Any ideas or suggestions would be extremely helpful!

---

Another problem is that I want to control the speed with which the motors turn. That is a secondary problem – but if you know of answer that could solve both problems in one that would be amazing!

#### Minder

Apr 24, 2015
3,426
For independent PWM/RPM control of a small motor a small PICmicro with a PWM module at each could do it, depending how you want to implement the programming, it could be done with a pot etc on a analogue input on each.
If these are simple 5v DC motors you will only have rough velocity control, no precise positioning or RPM without a PID feedback loop, if this is sufficient.
M.

#### Alec_t

Jul 7, 2015
3,457
If the motors are only low torque you will likely get away with instant reversal, but beefy motors should be brought to a stop before being reversed.
What is the rated running current of a motor?

#### sumeryamaner

May 29, 2017
50
My solution:

For each motor:
- One Attiny85
- One H Bridge motor driver (such as one L293 or similar, or two AOP605 or similar. The latter are compementary MOSFETs.)
- One potentiometer (or trimmpot, maybe multiturn)
You can drive L293 directly from the Attiny. For the MOSFET type circuit two 2N2222 (or similar) transistors will be needed for gate drive.

The software:
After initialising the motor driver outputs as OUTPUT, you will read the potentiometer and map the value to your time limits. Then you will put simple delay() instructions and toggle the motor outputs.
For speed control you will use the PWM capability of the Attiny.

If you want, I can post a schematic.

PS: I am assuming you will use simple 5 - 6 V motors.

Oct 5, 2014
6,583
Clone Arduino boards can be used at a cost of maybe $4 each, and even with extra external components, far less than any discrete device. In the latter you will need quite a few in comparison. It would be a good move to get just 1 up and running first as I suspect you will find this a bit more involved than you think. #### Euan Williams Jul 3, 2017 10 If the motors are only low torque you will likely get away with instant reversal, but beefy motors should be brought to a stop before being reversed. What is the rated running current of a motor? Hi Alec_t, It is completely open. The motors have to be strong enough to release and pull back a helium balloon. It is good to know that I have to consider this when choosing which motor to use - Thank you! #### Euan Williams Jul 3, 2017 10 My solution: For each motor: - One Attiny85 - One H Bridge motor driver (such as one L293 or similar, or two AOP605 or similar. The latter are compementary MOSFETs.) - One potentiometer (or trimmpot, maybe multiturn) You can drive L293 directly from the Attiny. For the MOSFET type circuit two 2N2222 (or similar) transistors will be needed for gate drive. The software: After initialising the motor driver outputs as OUTPUT, you will read the potentiometer and map the value to your time limits. Then you will put simple delay() instructions and toggle the motor outputs. For speed control you will use the PWM capability of the Attiny. If you want, I can post a schematic. PS: I am assuming you will use simple 5 - 6 V motors. Hello Sumeryamaner, Thanks for your reply! This is exactly the amount of detail I need - if you are able to post the schematic I will be more than grateful! Yes. I am using super simple 5v motors. #### Euan Williams Jul 3, 2017 10 Clone Arduino boards can be used at a cost of maybe$4 each, and even with extra external components, far less than any discrete device. In the latter you will need quite a few in comparison. It would be a good move to get just 1 up and running first as I suspect you will find this a bit more involved than you think.

Hello Bluejets,

I had a look at arduino clones - and even tried to buy 2. One never arrived in the post and the other just didn't work. From that experience I got the feeling that they were just cheap things built in China - and quite unreliable.

Do you have any suggestions of what I could buy, or at least a more reputable place where I could buy them?

Thanks for your and everyones feedback!!!

#### kellys_eye

Jun 25, 2010
6,039
Any of the smaller PIC devices will be capable of driving the motor via a small dedicated h-bridge driver or just a couple of transistors in a discrete circuit.
The hardest part for you will be getting the code right!

I'd suggest instead that you get an Arduino kit, purchase a motor driver module for it and learn some coding to get just one motor doing what you need it to do then - by that time - you should have sufficient understanding of the Arduino and coding to 'port' the solution to a micro-version of Arduino - other sizes and flavours are available and easily adapted.
Given the number of tutorials and 'sketches' (program modules) available for the Arduino platform there may well be some coding that will work right out of the box ('repository' is the proper word) or at least a workable version that is easily modified.

#### sumeryamaner

May 29, 2017
50
Hello Bluejets,

I had a look at arduino clones - and even tried to buy 2. One never arrived in the post and the other just didn't work. From that experience I got the feeling that they were just cheap things built in China - and quite unreliable.

Do you have any suggestions of what I could buy, or at least a more reputable place where I could buy them?

Thanks for your and everyones feedback!!!

I always use Banggood and Aliexpress for shopping electronic components. I have purchased several Arduino Nano boards and they work fine. But in my view those boards are for development most of the time. Final product should be based directly on the microcontroller. For this reason after the development is far enough, I design and build my own board and do not use Arduino boards in final projects.
I will post the schematic in a couple of hours.

#### Bluejets

Oct 5, 2014
6,583
Hello Bluejets,

I had a look at arduino clones - and even tried to buy 2. One never arrived in the post and the other just didn't work. From that experience I got the feeling that they were just cheap things built in China - and quite unreliable.

Do you have any suggestions of what I could buy, or at least a more reputable place where I could buy them?

Thanks for your and everyones feedback!!!
Never had a problem. Been using them for years.

#### sumeryamaner

May 29, 2017
50
This is one circuit suggestion:

We can examine it in two parts. On the left there is an Attiny85. It may run at 1MHz using the internal RC oscillator. One potentiometer is connected to an analog input. This will set the timing. There are two outputs which control the motor driver circuitry.

Right part of the schematic is the motor controller. There are several different solutions. One of them is a MOSFET H Bridge as shown. There are integrated complimentary MOSFET pairs such as AOP605.
Please note that the clamping diodes (D1..D4) are not always necessary. If you use MOSFETs the diodes are already integrated in the transistors. If you use L293 series motor driver look at the suffix. L293 does not have the clamping diodes but L293D has them. (http://www.ti.com/lit/ds/symlink/l293.pdf)

It is also possible to design an H Bridge using bipolar transistors.

You can connect another potentiometer to a free ADC channel and set the right turn and left turn times separately.

Last edited:

#### sumeryamaner

May 29, 2017
50
The code for this circuit is very straightforward.
You will define the two ports (PB0, PB2) as output.
Write a HIGH to one of the outputs.
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
The delay() instruction in Arduino IDE has a limit of 50 days! https://forum.arduino.cc/index.php?topic=115473.0
Then:
These two statements will toggle the outputs and the motor will run to the other direction.
Note that as you will use small motors we can do this. With heavy duty motors you must first stop them, wait a little bit and then turn them backwards.

Of course you will need an infrastructure to program the Attiny85. The easiest way is to use an Arduino Uno and a breadboard. You can Google for the details.

Last edited:

#### Alec_t

Jul 7, 2015
3,457
With the circuit shown there will be a high shoot-through current.

#### sumeryamaner

May 29, 2017
50
With the circuit shown there will be a high shoot-through current.
Any further explanation on how and why?

Last edited:

#### Alec_t

Jul 7, 2015
3,457
Consider T3, T5. With a 5V supply, both will need to have a Vgs(th) of magnitude a good bit less than 5V to ensure full turn-on. There will therefore be a common gate voltage at which both FETs will conduct at the same time.

#### BobK

Jan 5, 2010
7,682
Do all of these motors need to operate synchously. If so, it is much more complicated.

Bob

#### sumeryamaner

May 29, 2017
50
Consider T3, T5. With a 5V supply, both will need to have a Vgs(th) of magnitude a good bit less than 5V to ensure full turn-on. There will therefore be a common gate voltage at which both FETs will conduct at the same time.

Let's look at T1, T3, T5.

* If the output of the Attiny is LOW:
- T1 is practically an open switch
- The gates of T3 and T5 are at 5V
- T3 does not conduct
- T5 conducts

If T3 and T5 are the complementary pairs from an AOP605, T5 will have a RDS(on) of about 40 mohm (according to the datasheet at http://aosmd.com/pdfs/datasheet/AOP605.pdf)

* If the output of the Attiny is HIGH:
- T1 conducts and the saturation voltage between it's collector and emitter is expected to be 0.4V or lower.
- The gates of T3 and T5 are at 0.4V
- T3 conducts with a VGS of - 4.6 V and RDS(on) 58 mohm
- T5 does not conduct practically (with a VGS of 0.4 V)

Apart from a very short (short means short for this application ) switching period there shouldn't be any time period where both transistors conduct.

Of course, things will change when using PWM.

#### Alec_t

Jul 7, 2015
3,457
Apart from a very short (short means short for this application ) switching period there shouldn't be any time period where both transistors conduct.
Agreed, but during that brief period (~1uS in simulation) the supply is effectively shorted. While that may not harm the FETs it may upset some other part of the circuit.

#### sumeryamaner

May 29, 2017
50
Agreed, but during that brief period (~1uS in simulation) the supply is effectively shorted. While that may not harm the FETs it may upset some other part of the circuit.
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).

Replies
0
Views
1K
P
Replies
7
Views
1K
Palmer Hudson
P
Replies
14
Views
318
Replies
4
Views
463
Replies
7
Views
2K