ATTiny85 and MOSFET

First I apologize for being completely noobish with this question.

I want to use a .5watt LED as a strobe. I found a nice schematic using a 555 timer and pot to vary the time between blips, but what I really want is two quick flashes, 2 second pause, and repeat. I was talking to a friend who is an electronics guru and he was talking about adding this and that to the circuit when it occurred to me that a Arduino could do this easily.

But, the Arduino is way too big for what I am using it for. But I do have three ATTiny85 chips in my desk that I've never used before. Could I use one to drive a MOSFET transistor? I have absolutely no idea what I would need to make it work, which is why I ask you all. I can write the code easily enough, but the electronics side is still a bit of a mystery to me.

I have 21-17 Volts coming in (it's a Lithium Poly battery powering a hexacopter). I was thinking of using a 1000uf Cap just after the power comes in/out, then branching positive in two directions- one to a 3.3V regulator to power the AT chip, and the other through a 100ohm resister (if I did my LED math right), to the LED, then to the MOSFET transistor, then back to ground. My issue is, do I need anything else? Can I run a digital output to the MOSFET by itself, or do I need a resistor? How do I determine the resistance needed? What other obvious noob thing did I forget about?

Any help would be greatly appreciated.

The voltage can be converted to 5V or 3.3V with a DC-DC converter.

What is the voltage for that LED ?

An output pin of the ATtiny85 can be connected to the gate of the mosfet, but it is better to have a protection resistor in between of 100 ohm (100 ohm to 1k).
The gate of a mosfet is like a capacitor, so when the Arduino changes the output, a short current peak would occur. The 100 ohm reduces that current peak.

How do you want to program the ATtiny85 ?

I've been watching youtube videos on programming it. I would love to get that little USB stick from sparkfun where you just plug it in and go, but I'll probably use the Arduino as the ISP and program it that way. (If I got my terms wrong, I apologize.- I'd just copy the youtube guys)

It's this one: http://www.parts-express.com/high-power-white-led-05w--073-024.

With fully charged batteries, the initial voltage is 4.2X5, or 21V. But once the throttle is up and the six motors are spinning, the voltage goes down to 3.8V X 5, or 19V. The batteries are pretty much dead at 3.45V X 5, or 17.25V. So there's a big swing.

Thanks for the reply! I saw in the diagram for the transistor that the 100k resitor is going straight to ground insead of between the output pin and the transistor. Does it matter?

Led: Forward current: 150 mA • Forward voltage: 3.0 to 3.8 VDC
The led requires a current. You could use a current module for that. With a voltage and a resistor, the heating of the resistor is wasted energy.

Did you have a look at DC-DC converters ? They are very efficient can have a large input voltage range.

The 100k is an extra. When the Arduino powers up, the pin is not yet an output, and the mosfet has no defined level at the gate. The 100k will keep the gate low, and the mosfet off, during the power up of the Arduino.

Did you test the led with a resistor and 5V ? Did the resistor get hot ?
The value for the resistor can not be calculated, you have to find a value that results in 150mA for the led. I think it is about 10 ohm for 5V.

I did not test it. I should have.

First, I'm not sure where you got 5V from. I'm putting 17.25-21 volts to the LED. The 5V is only to the Tiny85.

I wasn't really worried about wasted heat energy because I'm just using this as a strobe. It will only be on 1/10 of a second or so, and then off for 2-4 seconds. Actually, I want to double flash it and then pause for 2-4 seconds.

I think I should test it with my Arduino Uno and see if it works.

You can use a DC-DC converter to create 5V.

Okay, I got it to work with the UNO, but not with the ATTiny85..

Here is what I did.

First, I got a RadioShack.com Official Site - America's Technology Store Darlington Transistor from Radio Shack. They didn't have any N-Mosfet transistors in stock, but it looked like this one would work. I have a protoboard shield on my Arduino Uno, and I put it on there. I then connected my 21V battery positive to a 100ohm resistor, then to the LED +, then from the LED- to the transistor collector, then from the emitter to ground.

I then used pin 13 to the base. Ground to ground, and tried the standard blink program. It worked perfectly. I modified the blink program to do what I wanted it to do- two quick blinks and then pause.

const int ledPin =  13;      // the number of the LED pin

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
 
    digitalWrite(ledPin, HIGH);
    delay (30);
    digitalWrite(ledPin, LOW);
    delay (90);
    digitalWrite(ledPin, HIGH);
    delay (20);
    
    digitalWrite(ledPin, LOW);
    delay (2500);
  }

So that's the code. IT worked perfectly on the UNO.

Next, I opened the programmer and loaded the ISP sketch. I uploaded it to the UNO.

Then I hooked up the ATTiny85 to the UNO as follows:
•Connect ATtiny Pin 1 (with the little dot) to Arduino Pin 10.
•Connect ATtiny Pin 5 to Arduino Pin 11.
•Connect ATtiny Pin 6 to Arduino Pin 12.
•Connect ATtiny Pin 7 to Arduino Pin 13.
•Connect the ground and 5v from the Arduino to the breadboard.
•Connect ATtiny Pin 4 to ground.
•Connect ATtiny Pin 8 to 5 volts.

I DID NOT have a 10uf cap for reset to ground, so I used a 100uf cap.

I then opened the file above (with the pin changed from 13 to 3), chose "ATTINY85 1mhz internal clock", then clicked on "Upload Using Programmer".

I hooked up the ATTiny by itself with the components and I get nothing. I then hooked it up to a low wattage standard led (no transistor) and it still didn't work. I checked the voltage and I have 5V going in, but nothing coming out of pin 3. I also tried pin 0.

I even removed the +5V coming from the voltage regulator and touche it to the base pin of the Transistor, and it worked fine- the LED comes on just like before- so the ATTiny85 is not sending 5V to the transistor.

So any ideas on what I did wrong????? Thanks.

Question: Since the ATTiny chip is 1mhz, do I have to increase my delay? I read that the compiler is set up for 16mhz and my delay might be going too fast for the voltage to trip the transistor. Should I burn the 8mhz bootloader?

SUCCESS!!!! 8)

I forgot to put the Programmer setting to "Arduino as ISP". It works perfectly now. Woo hoo!

Well done.

c131frdave:
SUCCESS!!!! 8)

I forgot to put the Programmer setting to "Arduino as ISP". It works perfectly now. Woo hoo!

hello friend....

sorry to wake up this old topic but i am trying to do what you have achieved.

i have started a thread for this issue at A flasher not working when ported to ATTiny85.... - Microcontrollers - Arduino Forum

can you please have a look and guide what is that i am doing wrong?

thanking you for your help in advance!

-Sid