starting simple project but need help on how to accomplish

I have a light box (wooden box with semi transparent image on glass and white led bank in background plus 1 blue led bulb in foreground.) I want to use a PIR sensor to activate a microcontroller with a program wich controls the leds

the blue led is just a single LED which turns on at about 2.5v and gets as bright as i want at 5v and about 15ma.

The background LEDS which are white (they are concealed in the box and I do not have any information about how they are arranged or what configuration they are in or even how many there are exactly. I only know that they come on at about 7v and around 12v they are about as bright as they get or I want. they draw about 1.5A fully on.

I have an arduino mega2560 which I would like to use to test the circuit and code but eventually want to put the code onto an ATTINY85 chip.

I want the program to work as follows

program boots up and waits for input from PIR sensor (HCSR501) then background lights fade on over a 3 second period, then remain fully on.
next the blue led fades on and off or possibly flickers, this LED is representing a glow bug or firefly. The light could just pulsate with 2 or 3 different patterns that repeat maybe.

after a total of 15 seconds the background lights fade out while the blue light continues to pulsate
5 seconds later the blue led fades out and the program waits for another trigger from the PIR sensor

obviously the microcontroller of the arduino or even the attiny85 cannot handle this on its own.

I found a BUZ91A N-channel mosfet that I think could be used to drive the background LEDs from a GPIO on the controller. I'm not sure if I was using a PWM signal from the controller through the mosfet if this could allow the fading that I'm looking for or not.

I believe that I can drive the single blue LED directly from the controller with some fancy programming to accomplish the pulsing effect I am looking for.

Also the PIR sensor I have seems to work best when it is powered by a 9vdc source rather than 5v so it would have to use a different power supply.

I am actually thinking that maybe I can put 2 9v batteries in parallel with each other as a main voltage source then use some regulators to drop the voltage needed to supply the controller. using the 9 volts to also power the background leds through the mosfet.

I know from reading around on the net that I need to use a flywheel diode across the mosfet to protect it and have a N4001 diode that I think might work.

I haven't created a schematic yet and I am unfamiliar with arduino code. I have some experience using assembly to program an atmega328p, and ultimately in the end I will be trying to program the ATTINY in assembly (for fun) once I understand the arduino code I create.

Does this even sound like I'm on the right track or is there things I am missing that will prevent me from accomplishing my goal?

hexluthor:
I have an arduino mega2560 which I would like to use to test the circuit and code but eventually want to put the code onto an ATTINY85 chip.

Why? A Pro Mini will be cheaper to implement. (Yes, I am referring to a $2 clone,)

A Nano for development.

hexluthor:
I'm not sure if I was using a PWM signal from the controller through the mosfet if this could allow the fading that I'm looking for or not.

That is indeed what PWM is for.

hexluthor:
I believe that I can drive the single blue LED directly from the controller with some fancy programming to accomplish the pulsing effect I am looking for.

Using 20 mA or less, certainly.

hexluthor:
Also the PIR sensor I have seems to work best when it is powered by a 9vdc source rather than 5v so it would have to use a different power supply.

Strange! Care to cite a Web reference for this sensor so we might check that out?

hexluthor:
I am actually thinking that maybe I can put 2 9v batteries in parallel with each other as a main voltage source

Just what do you mean by "9V batteries"?

hexluthor:
then use some regulators to drop the voltage needed to supply the controller. using the 9 volts to also power the background leds through the mosfet.

Regulators waste power. If - for some reason - you really must use batteries rather than mains power, you need to take many steps to economise power usage.

That said, for 1.5 A, you would need some serious batteries! Deep discharge lead acid I would say.

hexluthor:
I know from reading around on the net that I need to use a flywheel diode across the mosfet to protect it and have a N4001 diode that I think might work.

Why?

hexluthor:
I haven't created a schematic yet and I am unfamiliar with arduino code. I have some experience using assembly to program an atmega328p, and ultimately in the end I will be trying to program the ATTINY in assembly (for fun) once I understand the arduino code I create.

Definitely for fun! No other conceivable reason for assembly here. :astonished:

Pro Mini might be cheap but I have this arduino mega already on hand to play with and I also already have 4 ATTINY85 chips doing nothing but collecting dust.

I realize it is PWM that would fade an LED but I'm not good at understanding the data sheets and don't know if the mosfet is realiable to switch on and off as fast as I would need it to.

Here is a link to the data sheet for my PIR and I know it says it operating range is 5v to 20v however when I do some simple tests on the device simply using it to turn on 1 single led I see the sensor appears to start and stop repeatedly, basically every 8 seconds or so the led comes on and then goes off this is regardless of sensor being triggered. When I increase the voltage to about 9v the sensor turns on then waits until its sensor is activated then turns on the LED. this is just what I have observed playing with the sensor.

I meant to say I need a flywheel diode across the load on the mosfet and think the 1n4001 will do because its reverse voltage is up to 50v which I don't think I'd get spikes that high.

by 9v battery I mean one of these guys Duracell Coppertop MN1604 9V Alkaline|Battery Junction
I guess it would really take 3 of them in parallel to give me the current I need and maybe these are not
the best option, I beleieve I can get .5A from each 9v cell for up to an hour, The circuit will not run for more than half a minute at a time or atleast the LEDs which draw the most curent wont. There will be no mains to connect to. I am open to using an alternative battery maybe a rechargeable lipo or something.

I'm attaching a circuit I just put together in EASYEDA that kinda looks like what I want to accomplish.

Quote from: hexluthor on Today at 05:38 pm
Also the PIR sensor I have seems to work best when it is powered by a 9vdc source rather than 5v so it would have to use a different power supply.

Strange! Care to cite a Web reference for this sensor so we might check that out?

The HC-SR501 seems to run with between a 5 and 20 v input and output a 3.3 high or 0 v low signal.

If it seems to work better with more than 5v, I would go with that.

Arduino HC-SR501 Motion Sensor Tutorial

hexluthor:
I found a BUZ91A N-channel mosfet that I think could be used to drive the background LEDs from a GPIO on the controller.

That MOSFET is not a logic level or TTL level mosfet. It is designed to be driven by 10V, not the 5V on an arduino pin.

hexluthor:
by 9v battery I mean one of these guys https://www.batteryjunction.com/mn-1604.html?gclid=EAIaIQobChMIiIDsiIua5gIVBVYMCh31KAlHEAQYASABEgJLSfD_BwE

Those 9V batteries will NOT work. They won't deliver anywhere near the current you need. I would seriously consider power this project from the wall to make your life easier since it seems the project itself is a learning for you.

blh64:
That MOSFET is not a logic level or TTL level mosfet. It is designed to be driven by 10V, not the 5V on an arduino pin.

Okay that may be. Do you have a recommendation for a Mosfet that would suit my application? I thought this would work because on the data sheet the VGS(th) is listed as min 2.1v and max 4v. I am not good with datasheets though so maybe this isn't the correct value to look at.

blh64:
Those 9V batteries will NOT work. They won't deliver anywhere near the current you need. I would seriously consider power this project from the wall to make your life easier since it seems the project itself is a learning for you.

The location where this project will be placed doesn't have any outlets nearby so I am trying to use batteries instead. I was under the impression that a 9v battery typically has 500MaH so thought 3 of them in parallel would give me 1.5A for up to an hour. the batteries don't need to be this type and I can look into other options, I do have some 11v LiPos laying around that I could use instead.

hexluthor:
the VGS(th) is listed as min 2.1v and max 4v.

I'm not any better with the data sheets, but I think that represents the point where the MOSFET begins to turn on, not the point where it is fully on and allowing max power.

Compare to something like this, for example

which has a 1 to 2v VGS(th).

Others can make a recommendation of a particular item.

schem.jpg
Very nice schematic diagram. :sunglasses:

Lots of problems! :cold_sweat:

Battery?

That's not a battery! :astonished:

For 1.5 A, perhaps a pack of alkaline "C" cells. Does anyone use "D" cells anymore?

Don't know where you dreamed up those C1 and C2 values from, but this datasheet puts C1 at a minimum of 330 nF and C2 as 10 nF but we would specify at least 100 nF presuming the regulator is mounted directly next to the tiny85 (OK, if you have 'em, use 'em; you need the Arduino to program them of course).

A "flywheel diode" is not relevant to an LED. Need some more study on that. :grinning:

As pointed out, VGS(th) is completely irrelevant to using a FET as a switch. You have to look at the VGS for which RDS(on) is specified, in the case of the BUZ91A that happens to be 10 V! :astonished:

So the problem with the circuit so far is that the Tiny85 will draw a continuous few mA which can be minimised by sleep. Unfortunately, so will the 78L05, nominally 3 to 5 mA which is going to slowly drain your battery.

Paul__B:
schem.jpg
Very nice schematic diagram. :sunglasses:

Lots of problems! :cold_sweat:

Battery?

That's not a battery! :astonished:

For 1.5 A, perhaps a pack of alkaline "C" cells. Does anyone use "D" cells anymore?

Don't know where you dreamed up those C1 and C2 values from, but this datasheet puts C1 at a minimum of 330 nF and C2 as 10 nF but we would specify at least 100 nF presuming the regulator is mounted directly next to the tiny85 (OK, if you have 'em, use 'em; you need the Arduino to program them of course).

A "flywheel diode" is not relevant to an LED. Need some more study on that. :grinning:

As pointed out, VGS(th) is completely irrelevant to using a FET as a switch. You have to look at the VGS for which RDS(on) is specified, in the case of the BUZ91A that happens to be 10 V! :astonished:

So the problem with the circuit so far is that the Tiny85 will draw a continuous few mA which can be minimised by sleep. Unfortunately, so will the 78L05, nominally 3 to 5 mA which is going to slowly drain your battery.

Aww man I'm in trouble. lol
If that isn't a battery than what is it? n/m I understand that seems to be a bad choice so what I have laying around that I could use is a 4 cell LIPO (14.8v) 2200mAh battery which is rechargeable. The brand is Floureon, here is a link to amazon if you want to see.
https://www.amazon.com/FLOUREON-2200mAh-Battery-Evader-Airplane/dp/B071YPNWFY/ref=sr_1_8?crid=4XCHKDPFM9A1&keywords=floureon+4s+lipo+battery&qid=1575410901&sprefix=floureon+4s%2Caps%2C145&sr=8-8

Yes you got me the values of C1 and C3 were pulled out of my @$$. I know to reference the datasheet to see what the recommended values are. I just threw some numbers in there quickly, I see in the datasheet what you recommend is correct however and will make the changes on the schematic. thanks.

As far as the flywheel diode is concerned your right I need to learn more about this, from watching some videos on people using mosfets I gathered that the load always needs one, granted the videos I watched were driving motors not LEDs.

Thank you for clarifying which value I should be looking at in the datasheet of the mosfet. I have found this mosfet RFP30N06LE and it seems as though it would work its VGS for RDS on is 5v.

I cannot escape my circuit draining my battery but hopefully if I use this LIPO there will be enough charge to run the circuit for a goodwhile before needing to recharge the battery.

I will most likely place a mechanical switch in line with the battery supply so I can completely kill the circuit when its not being used.

Since 12 V would be about optimum for your LEDs, a three cell LiPo (11.1 V) would seem to be required for your application, 2.2 Ah should be quite adequate for the 1.5 A load.

I hesitated to mention a rechargeable since we do not quite know what your usage case is, but that certianly sounds appropriate. You need a specialised charger for a multi-cell LiPo,

Paul__B:
Since 12 V would be about optimum for your LEDs, a three cell LiPo (11.1 V) would seem to be required for your application, 2.2 Ah should be quite adequate for the 1.5 A load.

I hesitated to mention a rechargeable since we do not quite know what your usage case is, but that certianly sounds appropriate. You need a specialised charger for a multi-cell LiPo,

Yeah that would work. I'm going to stick with the 4s lipo I have because I have it already and no use for it. I have a charger for it as well. As far as the usage goes it is going to be very minimal and its like an art piece so its not doing anything important like collecting data or monitoring anything. Its just a small light box display which will only get activated a few times per day. Thanks for your input though.

Paul__B:
Since 12 V would be about optimum for your LEDs, a three cell LiPo (11.1 V) would seem to be required for your application, 2.2 Ah should be quite adequate for the 1.5 A load.

I hesitated to mention a rechargeable since we do not quite know what your usage case is, but that certianly sounds appropriate. You need a specialised charger for a multi-cell LiPo,

Have you ever used a Lipo battery this way? I have completed a circuit on a breadboard and wrote code for the uC and it all works as intended (thanks for the advice on which Mosfet to use from previous responders btw). I am powering the circuit from a dc power supply. when I try to use my lipo the circuit fails to operate. I get power where I need it but the circuit won't work. I have tried with a 4s lipo (14.8v, 1300mAh 100c) and a 3s (11.1v 5000mAh 50c). Both have been fully charged and are working batteries. I am wondering if maybe I need some sort of special filtering on the battery or something?

again the circuit works perfectly fine when run off a DC supply, what am I doing wrong here?

here is what my circuit actually looks like at this point on the bread board.

the code for the controller was written in assembly and is kind of sloppy but it functions like I said with a dc power supply no problem.

What voltage is the DC power supply?

I'd use DC-DC converters rather than linear regulators because I don't like power wasted as heat. But your version should work.

Lipos are an excellent source of DC power and I've never had any problems other checking that the voltage is suitable for the circuit and that the grounds of all components are connected. I regularly test with a power supply then switch over to battery for deployment.

Steve

slipstick:
What voltage is the DC power supply?

I'd use DC-DC converters rather than linear regulators because I don't like power wasted as heat. But your version should work.

Lipos are an excellent source of DC power and I've never had any problems other checking that the voltage is suitable for the circuit and that the grounds of all components are connected. I regularly test with a power supply then switch over to battery for deployment.

Steve

The DC power supply is variable. I've been running it at 9.6v just to setup and test the circuit. once it was running I cranked it up to 12v and left it run for a few hours with no issue.

There is something funky happening in my circuit though with the power and I cannot pin point it. I've tried the 2 lipos and now I've found some old wall warts and have been trying some of them out with no luck. (9vdc with 500mA) and (9vdc with 1A << 5v regulator couldn't handle that for very long though).

the dc power supply is adjustable voltage and I have been able to run this circuit at 9.6v and 11.3v.

I tried a wallwart and have the same issue (9vdc 500ma and tried 12v 800ma one as well). This is strange.

I must be doing something silly here.

I'm certain you're not connecting all these sources where your circuit diagram says you are...a 7809 won't produce anything useful if you only feed it with either 9V or even 9.6V. So where are they connected? BTW you're not exactly testing to the limits...a 4S Lipo is 16.8V fully charged!

But it has to be something to do with the way you're connecting the various sources. Unless you're doing something really silly like leaving several sources connected at the same time or using alligator clips or have dodgy breadboard connections I can't really guess what.

Steve

slipstick:
I'm certain you're not connecting all these sources where your circuit diagram says you are...a 7809 won't produce anything useful if you only feed it with either 9V or even 9.6V. So where are they connected? BTW you're not exactly testing to the limits...a 4S Lipo is 16.8V fully charged!

But it has to be something to do with the way you're connecting the various sources. Unless you're doing something really silly like leaving several sources connected at the same time or using alligator clips or have dodgy breadboard connections I can't really guess what.

Steve

My issue was that I had left 2 unused pins on the attiny85 floating. as soon as I tied them to ground everything works as intended. my prototype is complete and functioning, yahhhh! only thing left to do is etch a board and solder the components in place.

Lesson learned.... don't let pins float!

Thanks to everybody who offered advice on this project.