Thanks again for for comments. Glad you find these videos interesting.
2 หลายเดือนก่อน +1
Brilliant video, I really like the idea! I have two questions though. 1. What are the advantages of using a P-MOSFET over a PNP BJT transistor on the VIN side? 2. Why did you add that while(true) loop inside the loop() function which by itself loops indefinitely? Wouldn't it work without the while(true), apart from it requiring that ButtonHeld, StableLED, lLEDState and lReleased variables be global and initialized in setup()?
1. MOSFETS turn on/off from presence of the electrical field at the Gate rather than current flowing like a BJT. They drain virtually no current in the OFF state. 2. That's just habit. I prefer to have the loop within my control. Quite often I do some initialising at the top of the loop function before I want the actual loop to start. This is normally because I use local variables which cannot be initialised within the Setup section. Global variables are bad practice.
This is lovely. I'm thinking about using this with my esp32s. I'm still new enough to these things that I'm not sure what changes would need to be made to power this off of a 5v circuit, or if it's even still possible. Do you have any hints?
Hi. Thanks for the comment. I had the circuit still setup on my bench so I tested it and yes it works OK at 5V. That's with an Aurduino Nano, but I see no reason why an ESP32 board would be any different. Just bear in mind the slight volt drop across the MOSFET which looks to be around 0.1-0.2V, so @5V supply your actually getting around 4.8-4.9V. This might vary dependant the total load of the ESP32 and any other components you're powering. Good luck, I would be interested to hear how you get on.
Very nicely done. Seems like it might be more efficient to use events instead of a loop for knowing button states and depressed durations though would it not? I have not done any Arduino programming so I am only relying on "other" programming. I do not know if events are available [in Arduino] but it would be a shame if they were not. Just thinking through it, you would only need two events... onButtonPressed and onButtonReleased. From there, it is a simple matter of recording when the button was depressed or released and doing math... and taking an action similar to what you're doing in your loop once the button is released. But hey, it's 8am and I'm on my first cup of coffee in a topic in which I have zero experience... so there's that. LOL. Have a wonderful day and I look forward to more of your videos!
Yes, you can setup hardware interrupts for Rising Edge and Falling Edge triggers. The code is just there to demonstrate an example implementation of utilising the button to do a certain action within your code, but also act as an OFF switch.
. @paulpkae thanks Paul. I just ordered a Nano so I can play around with this. I'm sure it will be a fun way to learn more about Arduino as well as how various transistor types work.
The leak current was undetectable (with my test kit) in this circuit and nothing to worry about unless you are ultra concerned about power for some reason. In which case a mechanical switch or a latching relay is your best option.
This is great. Just what I need. I have been looking for ways to reduce power consumption after running some code to start a generator.
Great, glad you found it of use. Would be interested to hear how you get on.
This is exactly what I was looking for sir. Thank you very much for your experience and knowledge.
Thanks. Glad you found it of use.
Very happy to have found (and now subscribed to) your excellent channel!!
Best regards
Thanks and welcome.
I like it, thanks for sharing
Thanks again for for comments. Glad you find these videos interesting.
Brilliant video, I really like the idea! I have two questions though.
1. What are the advantages of using a P-MOSFET over a PNP BJT transistor on the VIN side?
2. Why did you add that while(true) loop inside the loop() function which by itself loops indefinitely? Wouldn't it work without the while(true), apart from it requiring that ButtonHeld, StableLED, lLEDState and lReleased variables be global and initialized in setup()?
1. MOSFETS turn on/off from presence of the electrical field at the Gate rather than current flowing like a BJT. They drain virtually no current in the OFF state.
2. That's just habit. I prefer to have the loop within my control. Quite often I do some initialising at the top of the loop function before I want the actual loop to start. This is normally because I use local variables which cannot be initialised within the Setup section. Global variables are bad practice.
@@paulpkae Thank you!
This is lovely. I'm thinking about using this with my esp32s. I'm still new enough to these things that I'm not sure what changes would need to be made to power this off of a 5v circuit, or if it's even still possible. Do you have any hints?
Hi. Thanks for the comment. I had the circuit still setup on my bench so I tested it and yes it works OK at 5V. That's with an Aurduino Nano, but I see no reason why an ESP32 board would be any different. Just bear in mind the slight volt drop across the MOSFET which looks to be around 0.1-0.2V, so @5V supply your actually getting around 4.8-4.9V. This might vary dependant the total load of the ESP32 and any other components you're powering. Good luck, I would be interested to hear how you get on.
Wow, Very useful
Thanks.
Well done buddy ❤
I would like to have a similar circuit, but running off 5V rather than 9V.
What changes would have to be made (to resistors etc.)?
None, 5V works absolutely fine.
Very nicely done. Seems like it might be more efficient to use events instead of a loop for knowing button states and depressed durations though would it not? I have not done any Arduino programming so I am only relying on "other" programming. I do not know if events are available [in Arduino] but it would be a shame if they were not. Just thinking through it, you would only need two events... onButtonPressed and onButtonReleased. From there, it is a simple matter of recording when the button was depressed or released and doing math... and taking an action similar to what you're doing in your loop once the button is released. But hey, it's 8am and I'm on my first cup of coffee in a topic in which I have zero experience... so there's that. LOL. Have a wonderful day and I look forward to more of your videos!
Yes, you can setup hardware interrupts for Rising Edge and Falling Edge triggers. The code is just there to demonstrate an example implementation of utilising the button to do a certain action within your code, but also act as an OFF switch.
. @paulpkae thanks Paul. I just ordered a Nano so I can play around with this. I'm sure it will be a fun way to learn more about Arduino as well as how various transistor types work.
@@Wil_Bloodworth nice one. Let me know how you get on.
Is it possible to have even lower leak current when it's off?
The leak current was undetectable (with my test kit) in this circuit and nothing to worry about unless you are ultra concerned about power for some reason. In which case a mechanical switch or a latching relay is your best option.
going to give it a try