3
\$\begingroup\$

Hello I want to get a confirmation that what I am doing is not going to fry my Arduino Mega.

The sketch I am using to send a pulse out on pin 8 to a 2n3055 that is switching 12 volts is this:

int pulse = 8;
int sensorValue;

void setup() {
  pinMode(pulse, OUTPUT);
}

void loop() {
  int sensorValue = analogRead(A0);
  map(sensorValue, 0, 1023, 1, 2000);
  digitalWrite(pulse, HIGH);   
  delay(sensorValue);              
  digitalWrite(pulse, LOW);    
  delay(sensorValue);            
}

I am using a potentiometer between the Arduino 5v and ground with the wiper going to pin A0.

Sketch

schematic

simulate this circuit – Schematic created using CircuitLab

I want to know:

  1. could I power this directly from my USB instead of powering the transistor AND the Arduino from the source battery.

  2. If they have to be both powered from the battery do I need to connect the emitter to the ground of the Arduino AND the battery to stop all the current from flowing through the Arduino ground and get a clean pulse or do I just connect the emitter to the battery negative and the signal will be OK.

  3. In whatever configuration is best where is the best place to put a analog meter that is rated up to 3 amps so that I can see total power consumption of the board and the transistor circuit.

  4. Lastly I am using this to pulse the high voltage side coil in a microwave transformer so it has a lot of impedance and when pulsing it it draws about 300 mA max so could I power the Arduino via USB and the transistor from the battery so that I can reprogram on the fly and have a set pulse instead of using the pot. (as in write the code for a certain delay and upload while running)

\$\endgroup\$
8
  • 1
    \$\begingroup\$ This question is confusing and would benefit from a circuit diagram; is the battery 12V, and where is it connected up? \$\endgroup\$
    – pjc50
    Apr 26, 2013 at 16:14
  • 3
    \$\begingroup\$ While some of us can understand what your configuration is, from your verbal description, a picture is worth a thousand words. Please consider adding a schematic for what you are trying: Since you do not have sufficient reputation yet, please create one and upload as an image to any public image hosting site, then leave the link here as a comment to your own question. Someone with edit privileges will edit it into the question. \$\endgroup\$ Apr 26, 2013 at 16:15
  • 1
    \$\begingroup\$ +1 on what @AnindoGhosh said, but also you can edit in a link to your schematic. Better yet, use Ctrl+M and add a Circuit Lab diagram, you don't need any rep for that: it should be fixed now. \$\endgroup\$ Apr 26, 2013 at 16:18
  • \$\begingroup\$ Why not use PWM, it is as easy as doing an analogWrite( pulse , dutyCycle );, where dutyCycle = ( 255 * sensorValue ) / 1024;. \$\endgroup\$
    – jippie
    Apr 26, 2013 at 17:52
  • \$\begingroup\$ im not doing pwm because i want variable frequency with fixed 50 percent duty cycle. varying the delay on and off times with a pot does that for me. if i want to vary the duty cycle i could add a second pot and use it as the off time delay variable. \$\endgroup\$
    – bradley
    Apr 26, 2013 at 18:28

2 Answers 2

1
\$\begingroup\$

int sensorValue = 1;

Why are you initializing this variable to 1, when it then gets overwritten in the first line of loop()?

delay(sensorValue);

Is it intentional to have a varying delay of n milliseconds, where n is the value read from port A0 each time? Also, is that delay required twice, once after setting the output pin high, once after setting it low?


You will require a base resistor between pulse (Pin 8) and the Base of the 2n3055, with a value calculated depending on how much current you intend to allow through the Collector. If you are using the transistor as a switch, then a minimum of around 220 Ohms is suggested, to keep current from the pulse pin under around 25 mA, well within the safe limits for each pin: Absolute Maximum for each pin is rated at 40 mA.

  1. You could power the Arduino from USB and the transistor from the battery, so long as the ground of the Arduino is connected to the negative pole of the battery.
  2. Either way, you will need Arduino ground connected to battery negative.
  3. Put it in series with the coil you are driving, if you want to measure the coil (the transistor's Collector) current. If you want to measure the combination, both Arduino and transistor need to be powered from the battery, and just add the meter in series with either the positive or negative pole of the battery, before any connection to either Arduino or transistor. i.e. all current to the battery must pass through the meter.
  4. Yes, see point 1.
\$\endgroup\$
6
  • \$\begingroup\$ i coppied and pasted that wrong it is just (int sensorValue;) in my sketch not sure how i changed it...and thanks for the information very helpfull. i appreciate it. also i am varying the delay times to keep the duty cycle at 50 so the pulse is off for as long as it is on. it works well on my oscope and for the few seconds i had the guts to plug it all together before i got confirmation. and i do have a base resistor just didn't write that in there. \$\endgroup\$
    – bradley
    Apr 26, 2013 at 16:47
  • \$\begingroup\$ i1279.photobucket.com/albums/y524/BJmalone/… i think i got it all in there...i did have time but i did it with paint so sorry if it isn't clear \$\endgroup\$
    – bradley
    Apr 26, 2013 at 17:36
  • \$\begingroup\$ @bradley Incorporated. Also, the schematic link comment should have been on the question not the answer. Lastly, please try to use the in-built schematic editor by pressing Ctrl-M while editing your question. \$\endgroup\$ Apr 26, 2013 at 17:41
  • \$\begingroup\$ @jippie Nope, you can use variables with delay() and it works. The optimizer recognizes whether it's a const or not, and if it's a const, treats it as a static value. \$\endgroup\$ Apr 26, 2013 at 17:44
  • \$\begingroup\$ Must be new (> v0022). Did you miss the flyback diode? \$\endgroup\$
    – jippie
    Apr 26, 2013 at 17:52
0
\$\begingroup\$

1) It depends on the current draw. USB has a PTC fuse set at 500mA. If your load doesn't exceed that, then it's fine.

2) Current will find the path of least resistance, so that's fine. I would use an optoisolator to separate the two devices. Whenever you switch a large current load, a lot of noise will be induced into your system.

3) Just break the circuit to measure current consumption. Pretty much between battery's positive terminal and load.

4) I would recommend changing to a MOSFET instead of using the NPN transistor. If you do the power dissipation calculation for the two devices, it makes a lot of sense: MOSFET: P = (I^2)(Ron) = (300mA^2)*(mOhms) => little heat NPN: P = (I*V) = (300mA)*(0.7V) = 0.21W

You don't want to use PWM because analogWrite() is fixed at 490Hz.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.