Go Down

Topic: Schematic and Arduino sketch that work (Read 3 times) previous topic - next topic

Pedro147

Sigh... still having no luck, but then I checked my circuit and I have a schematic for PNP transistors being contolled by pins 10, 11 and 12 but the 2N2222 transistors I am using are NPN type. Also I have schematic for the NPN transistors being controlled by pins 4, 5 and 6 but the 2N2907 transistors I am using are PNP type. Help I am even more confused that I was before (might just buy a cheap set of christmas tree lights and be done with it ...)

If I put this code;
_____________________________________________________________

void setup ()                         
  {
   
   pinMode (4 , OUTPUT);               
   pinMode (5 , OUTPUT);
   pinMode (6 , OUTPUT); 
   pinMode (10 , OUTPUT); 
   pinMode (11 , OUTPUT); 
   pinMode (12 , OUTPUT); 
   
  }
   void loop ()
                     
  {
   
    digitalWrite( 12 , LOW);
    digitalWrite( 6 , HIGH);
    delay(1000);
    digitalWrite( 12 , HIGH);
    digitalWrite( 6 , LOW);

    delay(1000);

    }


with all connection between LED matrix and Arduino LED's 1 ,5 and 7 flash. The same as when I had ;

void setup ()                         
  {
   
   pinMode (4 , OUTPUT);               
   pinMode (5 , OUTPUT);
   pinMode (6 , OUTPUT); 
   pinMode (10 , OUTPUT); 
   pinMode (11 , OUTPUT); 
   pinMode (12 , OUTPUT); 
   
  }
   void loop ()                     
  {
    digitalWrite( 12 , HIGH);
    digitalWrite ( 6 , LOW);     
    delay(1000);                           
    digitalWrite( 12 , LOW);
    digitalWrite ( 6 , HIGH);
   
   
    delay(1000);
  }
___________________________________________________________________

Is the fact that I have used the wrong type of transistors making my hair greyer than it was this morning,
thanks Pedro.

CrossRoads

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Docedison

There are several errors in the drawing as shown... The NPN are shown as emitter ffollowers and there are 2 issues there, 1. the emitter cant ever go higher than the base, in this case for a functioning transistor the emitter MUST be .7 V lower than the collector (5V source) so we now have a max supply that is ~ 15% lower than it should be and 2. while the emitter current is the SUM of the collector and base currents the available voltage for series led's is lower making a good power supply a must. For optimal results switch the NPN's and PNP's respecting polarity... THe emitter of a PNP is the most positive element of the transistor and to turn it on you must "Pull" current from the base to ground so remember to include a 1K resistor in the base circuit and good design practice would have a 10K pull-up from base to Vcc as this prevents uncertain (read Floating) base connections from turning on the PNP transistor and use the NPN's to Sink current and use a 470R resistor for the base current limiting resistor again good practice would have a 10K resistor from base to ground. When connected in this manner both the PNP's and the NPN's are operating as true switches and the only losses will be ohmic (wire/connection) resistance and the Vce sat of the transistors. Were it me, for light loads (under 150 Ma/device) I would choose a 2SC945 for the NPN and a 2N3906 for the PNP for 2 reasons 1. the '945 has a typ dc gain of ~ 100 @ 150 mA Ic and the '3906 although a lower gain device still has the base current flowing in the emitter lead of the device thus extra base current will be dissipated in the LED rather than to ground as your drawing clearly shows and the smaller the value of base resistor the more wasted current. Never assume that the port of a microcontroller is responsible for insuring that the state of any connection to it. Use Pull-ups (5 10K) and pull downs of the same value. Pull UP PNP's and Pull DOWN NPN's... finally P & N channel mosfets would be my preferred devices for power control of that type... 5A P Ch mosfets can be had for 25 -50 cents a piece... pretty much the same for N channel devices in the same current range. OR one could use TPIB595's and ULN2803's for higher currents and simplified wiring.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

CrossRoads

"Is the fact that I have used the wrong type of transistors making my hair greyer than it was this morning"

Yes.

Your sketch

Code: [Select]

void setup ()                         
  {
   
   pinMode (4 , OUTPUT);               
   pinMode (5 , OUTPUT);
   pinMode (6 , OUTPUT); 
   pinMode (10 , OUTPUT); 
   pinMode (11 , OUTPUT); 
   pinMode (12 , OUTPUT); 
   
  }
   void loop ()
                     
  {
   
    digitalWrite( 12 , LOW);
    digitalWrite( 6 , HIGH);
    delay(1000);
    digitalWrite( 12 , HIGH);
    digitalWrite( 6 , LOW);

    delay(1000);

    }

would work with the schematic you drew, now you just need to wire up the correct parts.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pedro147

Thanks again Crossroads,
I had a good long hard look at what I have done and with your help I finally got it to work as I set out to. Do you think that I should construct a new circuit, matching what I had in the original schematic with Pins 10,11,12  controlling PNP transistors and Pins 4, 5, 6 controlling NPN transistors rather than how they currently are, or doesn,t it matter?  Something tells me that as my physical circuit currently is, it is incorrect to have current sinking transistors to pins 10, 11 ,12 and current sourcing transistors to pins 4, 5, 6. It's all very confusing to the uninitiated I can tell you.
Also (I realise that I might be pushing my luck here) now that I have a 3 x 3 matrix working using six Arduino pins what is the next step to controlling a 3 x 3 x 3 cube. From what I have read it involves using shift registers? Would it be possible for you to point me in the right direction, keeping in mind that I am a rank novice to all this. Thanks again for your help Pedro.

Go Up