Controlling Motor with ATMega 328

Hello,

I am trying to control automatic air perfumer with ATMega 328. This type of perfumer have a motor inside that momentary gets a signal to run for about a second and then switched off. The perfumer is running on two AA batteries. I first tried the motor separately and it works fine when connecting the batteries wires directly to it. I measured the drawn current and found it 105mA DC on about 3.1v from 2 AA batteries.
I need to run my ATMega 328 chip from the same batteries and send signal from one of the Arduino pins to switch the motor on for a second and then switch it off to simulate its original action for flushing it.

I tried 4N25 optoisolator to drive the motor as per the attached drawing.

The chip is running fine, however the motor could not run on the above configuration. Although I tried the same configuration on a LED to check and it is working fine.

What am I doing wrong please?

This optocoupler can handle only 50mA. And you don't need a optocoupler at all. Regular transistor is OK

|478x500

alesam: This optocoupler can handle only 50mA. And you don't need a optocoupler at all. Regular transistor is OK

Thanks for your reply and the info. Since I'm not expert, could you suggest a suitable transistor for this task please?

I need to run my ATMega 328 chip from the same batteries

To run a 328 at 3V you will need to run it at 8MHz (or less). If your 328 already has a 16MHz bootloader installed you will need to have a 16MHz crystal installed on it or an external clock signal when bootloading to 8MHZ. See this Nick Gammon page on building and bootloading a stand alone 328 board. The page shows how to use an external clock to bootload a 16MHz 328 to 8MHz.

Virtually any transistor is OK. for example PN2222

https://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/transistors

alesam:
Virtually any transistor is OK. for example PN2222

Transistors | Arduino Lesson 13. DC Motors | Adafruit Learning System

Lets be more precise - use an NPN switching transistor capable of 0.6A or more, and a 150 ohm
base resistor. The momentary current demand from the motor will be several times
more than the measured running current and you need good saturation properties if running at 3V.

You must use a free-wheel diode across the motor too, motors are inductive and can destroy
your circuit without such protection from inductive kick-back.

At 3V the MOSFET options are very limited unless you can work with surface mount devices.

The 2N2222 is an example common switching transistor thats frequently used, somewhat
better devices(*) are available these days if the current is higher, but I think the '2222 wlll
work.

(*) My favorite is the ZTX851, tiny but powerful.

Thanks all for your advice. Thanks MarkT for the detailed explanation.

I tried a transistor I already have and worked fine. I will change my PCB accordingly.

groundFungus: To run a 328 at 3V you will need to run it at 8MHz (or less). If your 328 already has a 16MHz bootloader installed you will need to have a 16MHz crystal installed on it or an external clock signal when bootloading to 8MHZ. See this Nick Gammon page on building and bootloading a stand alone 328 board. The page shows how to use an external clock to bootload a 16MHz 328 to 8MHz.

Great reference for 328. Is there similar reference for 2560 chip?