ATTiny85 output to transistor - can't figure it out.

Hey all. I have a challenge. The below project is for my car. The Tiny is programmed to monitor 2 inputs (bottom 8 & 9 (10 was a mistake)). These 2 are 12V and a divider is used to get them below 5V. The programming is simple, if either of the 2 inputs go Low, the output (pin 6 on the ATTiny that goes to the 2222 transistor Base) goes High and vise versa. That is all working fine. When I measure the output on pin 6 it does as expected (it flips from 5V to 0V - well 0.01V).

The problem is with the transistor (2222A top right). The collector pin will come from the car (12V) and emitter pin will 'pass' that voltage through. In the car, there was originally a wire that had 12V. I cut that wire and am wiring it to the C and E of the 2222. The intent is for the 2222 to turn it on or off (like a relay of sorts) when the base goes High. For testing, I hooked the collector to my 9V battery and emitter to GND. The 9V battery is also used to provide power to the whole circuit. When I do this, I find that when the Tiny pin 6 goes low, there is still voltage passing through the 2222 (approx 3v). When 9V is hooked up to the 2222, the Tiny pin 6 no longer goes between 0 and 5V. It is more like 3.xV and 5V. What am I doing wrong? It seems that providing power from the same source is causing the issue. This will be a problem as the same will apply when installed in my car.

The code:

      // On ATTiny85
int pin7Juke = 0; //pin #5
int led = 1;      //pin #6
int shiftUp = 3;  //pin #2 
int shiftDn = 2;  //pin #3 

void setup() {                
  pinMode(pin7Juke, OUTPUT);     
  pinMode(led, OUTPUT);     
  pinMode(shiftUp, INPUT);     
  pinMode(shiftDn, INPUT);    

  digitalWrite(pin7Juke, HIGH);  //onstartup, pin7 needs to be supplying 12V.  
}



void loop() {
  if (analogRead(shiftUp) < 900 || analogRead(shiftDn) < 900)
  {
    blink();
    digitalWrite(pin7Juke, LOW);
  }
  else
  {
    digitalWrite(pin7Juke, HIGH);
  }
  delay(50);
}

void blink()
{
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second 
}

You need a resistor to connect the pin from the digital out of the 85 to the base of the transistor. As you mentioned when your pin is low it is still at 0.1v which may be causing enough current to flow in the transistor for what you are measuring. The resistor is needed to control the base-emitter current flow. Since you are using the transistor as a switch (as opposed to an amplifier) it needs to have enough current to saturate the transistor. I would suggest a starting point of around 1k (maybe a little less).

wanderson:
You need a resistor to connect the pin from the digital out of the 85 to the base of the transistor....

Thanks very much, I think that did the trick! Going to test in the car tonight and will post back on the results... fingers crossed for no black smoke...

Edit: confirmed that it works. Thx.