I'm a newbie to Arduino and electronics in general and I would really appreciate your help. I have found many guides on how to make a timer with Arduino but none that came close enough to what I need.
I'm currently working on a DIY fog machine project (based on this tutorial) involving an e-cigarette and a 3V DC aquarium air pump.
So far, so good. I have successfully created the mini fog machine and I even managed to correctly wire it to a push button and a DC adaptor, such that the pump would turn on as long as I pressed the button. Now I would like to replace the button with a timer switch so that the pump is on for exactly 3 minutes once I upload the code into the Arduino.
However, I am lost as to how I should wire and code such a thing. Any advice on this?
If the pump doesn't pull too much current it could work with those components, it's worth a try. Keep an eye on the transistor, it shouldn't get too hot to touch. If it does, you have to get a higher-current transistor.
I’ve been researching how to do the coding and wiring and I’m stuck. Here’s a fritzing diagram of what I have so far (attached). The Arduino is powered via USB, the power socket is 5V, 2.25A, the transistor is 2N2222A and the resistor is 10KOhms as I figured the amperage might be too high for the 330ohm one I had.
The code I’m using is as following:
void setup() {
pinMode(12,OUTPUT); //Channel A Direction Pin Initialize
}
void loop() {
analogWrite(3, 0); //Channel A Speed 0%
delay(100); //100ms Safety Delay
digitalWrite(12, HIGH); //Channel A Direction Forward
analogWrite(3, 255); //Channel A Speed 100%
delay(180000); //3 minute Delay
analogWrite(3, 0); //Channel A Speed 0%
exit(0)
}
This setup is not working (code compiles but motor doesn’t turn on) and I’m not experienced enough to figure what’s wrong.
Any advice is greatly appreciated! Thanks!
Did you connect the arduino GND and motor power GND?
Also, not sure what's going on in your code. You cannot set the direction of the motor with that setup. I guess you used some code for an h-bridge module.
The only wire connected to my Arduino is the 12pin you see in the diagram, connected to the resistor which is in turn connected to the transistor Base. I just added a wire connecting the Arduino Ground pin and the transistor and power grounds. Tested it with the same code as in the previous post, got nothing more than a slight noise.
Motor ground is connected to the transistor Emitter. Transistor Collector is connected to the ground.
I don't have a flyback diode at hand. Could I use an LED instead considering the relatively low voltages I'm working with? And how would I wire the diode "across the motor"?
The code is adapted from the Basic Control example. Original example below for reference:
void setup() {
pinMode(12,OUTPUT); //Channel A Direction Pin Initialize
}
void loop() {
analogWrite(3, 0); //Channel A Speed 0%
delay(100); //100ms Safety Delay
digitalWrite(12, HIGH); //Channel A Direction Forward
analogWrite(3, 255); //Channel A Speed 100%
delay(1000); //1 Second Delay
analogWrite(3, 0); //Channel A Speed 0%
delay(100); //100ms Safety Delay
digitalWrite(12, LOW); //Channel A Direction Reverse
analogWrite(3, 255); //Channel A Speed 100%
delay(1000);
}
Diode goes literally across the motor contacts, but unintuitively backwards, with the cathode (silver stripe) on the positive. Have a look at this page at Sparkfun, near the bottom.
I think I’m almost there. There’s just one thing that I can’t figure out:
If you look at the diagram attached, you’ll see I added a diode. Ardy recommended a flyback diode but I did not find any of that specific kind - instead, I got a bag of mixed diodes and hoped I’d find something similar enough.
When I tried to use the setup attached with a rectifier diode, the motor didn’t turn on and I sensed a burning smell from the transistor, which became extremely hot.
However, when I tried the exact same setup except for replacing the diode with a LED, it all worked. Granted, I didn’t keep it on for more than a few seconds.
I figured I should stop and seek advice before I do any damage. The code seems to work; I just need to confirm what I did wrong with the electronics. I will get a higher current transistor ASAP, but what about the diode? Is it fine as it is? If it needs to be changed, can I replace the flyback diode with anything from this mixed bag (datasheet attached) ?