# Arduino experts around?



## zozo

It's rather new for me but I like to play with it to automate a simple 3 volt LED for a mini terrarium setup... Now I already ordered me a NodeMCU ESP8266 WiFi development board I know that can do it... I'm not totally unfamiliar with program scripting did some VBS in the past so in a way, I can make some sense of it, but it's more than a bit rusty... Already found a valid sketch that automates the LED on/off over WIFI internet Time Server.

This bellow should work, but if I would need to change the time I need to re-upload another edited script.








						NodeMCU_ESP8266/TURNON_OFF_WITH_TIME.ino at master · jumejume1/NodeMCU_ESP8266
					

Maker Tutor Channel. Contribute to jumejume1/NodeMCU_ESP8266 development by creating an account on GitHub.




					github.com
				




Now I've also seen that HTML can be corporated to access the NodeMCU as webserver via port 80 to edit the values web-based via button tags etc. Would like have buttons to switch LED port off and on, on-demand and be able to edit the time on and time off values. Seeing examples it all looks much too easy, but still, this is where I run into complete noobilities. I actually wouldn't now where to start HTML scripting with Arduino IDE is completely unfamiliar to me... I'm more of a copy/paste script kiddie (more to say old fart) but i can't find the examples i need and how to incorporate it.

Are there people around that know this stuff? Any assistance would be hugely appreciated... 😍


----------



## castle

I think you may be going about this the hard way, seen this? Controlling Arduino With Python Based Web API (No Php)


----------



## zozo

No have not seen it thanks I'll give it a read... Tho I do not have the Arduino Uno but will get the NodeMCU wifi shortly.
No idea if it can handle all that as the Uno does...

I actually came to the idea with looking at this NodeMCU getting started tut.


What he shows here does for a part what i want relatively simple, switch the LED port on/ff via Web... The part i'm missing is how to create the possibility to edit and save the time parameters and where to put this correctly in the script.. 

It actually shouldn't be too difficult for someone who knows how to incorporate the correct HTML tags and parameters to get it done... It looks like it needs a few more lines... But at the moment I'm running around like a chicken without ahead.


----------



## castle

I was typing out code, but this does a much better job: A Beginner's Guide to the ESP8266

You're basically trying to build an http server with the NodeMCU to control some LEDs, yep simple, see how the above helps


----------



## dino21

Hi,
You want to look at this Free site which takes you from Beginner to Advanced for the ESP8266 and ESP32 boards.
The ESP32 includes Bluetooth so that might be more suitable than wifi, depending on your needs.
Both ESPs can be programmed from the Arduino IDE with C++ which again has lots of free online help.

80+ ESP8266 NodeMCU Projects, Tutorials and Guides with Arduino IDE | Random Nerd Tutorials


----------



## zozo

castle said:


> I was typing out code, but this does a much better job: A Beginner's Guide to the ESP8266
> 
> You're basically trying to build an http server with the NodeMCU to control some LEDs, yep simple, see how the above helps



Thank you! I have some reading and digging to do now... This is indeed what I basically want... I can edit the existing sketch i posted above to say LED on at 08:00 and off at 20:00 that ain't rocket science. And i guess it simply wrks and loops this day in day out till told otherwise.

But it would indeed be fancy that if needed that I can edit the time period over the HTTP server on the NodeMCU without editing the script and upload it again.

It actually is for this little bugger  A friend asked me to also build one for him but he wants it mobile and wireless on battery power, no power cords to mains. It only contains 3 x 3.3 volt 200mA LEDs parallel...




So I thought intersting idea and experiment, this I can only fix with using the NodeMCU hooked to a battery.

That's how the idea was born...  But my scripting skills are more than a bit rusty... Haven't touched it over a decade.


----------



## zozo

dino21 said:


> Hi,
> You want to look at this Free site which takes you from Beginner to Advanced for the ESP8266 and ESP32 boards.
> The ESP32 includes Bluetooth so that might be more suitable than wifi, depending on your needs.
> Both ESPs can be programmed from the Arduino IDE with C++ which again has lots of free online help.
> 
> 80+ ESP8266 NodeMCU Projects, Tutorials and Guides with Arduino IDE | Random Nerd Tutorials



Thanks a million!...


----------



## zozo

dino21 said:


> The ESP32 includes Bluetooth so that might be more suitable than wifi



That's a good one, made a new order to play with that too... It's too cheap not too, funny stuff...


----------



## dino21

zozo said:


> That's a good one, made a new order to play with that too... It's too cheap not too, funny stuff...



If you have the time and brain power its an interesting hobby, though its our young ones who do all the work on them, they were equally overjoyed when finding that RN tutorial, it really got them into those wifi /bt things;   ( it all baffles us oldies ! )
They say log on to that site with an email address to get their latest updates, all free, though they have not joined up to the paid for lessons etc as most of it can be found for free.
They also suggest you look at this free site ( one of several similar) which allows you to build your own mobile App to control your ESP etc etc.

MIT App Inventor | Explore MIT App Inventor


----------



## zozo

I think I found what I'm looking for, almost completely ready to roll.









						JohnHalfords/Timer-Clock-program-for-the-ESP8266
					

Timer Clock program for the ESP8266. 4 timers with ON and OFF time or automatically switch ON and/or OFF by SunSet and/or SunRise with Offset - JohnHalfords/Timer-Clock-program-for-the-ESP8266




					github.com
				




This would be the web-based portal to set and update the ESP timer



Only need 1 timer (A) and since it likely is designed to switch relais I need to fiddle a bit with the Pin settings to make it switch a small Mosfet instead... It only needs to switch 3 LEDs 3.3.V - 60mA total

Thanks, Guys for the inspiration... I let you know how it runs when all is tested...

Now the hunt is on to find something similar for the ESP32 via bluetooth...


----------



## dino21

zozo said:


> let you know how it runs when all is tested...
> 
> Now the hunt is on to find something similar for the ESP32 via bluetooth...


Yes, please do let us know how it works, as all that wifi stuff is a mystery to us, I do occasionally see the younger ones  doing such stuff, but they go at such a pace I'm lost after 5 mins !   

Re the ESP32 and Bluetooth, seems it working in two ways,  BT Classic  and the newer BLE Low Energy. 
Apparently BLE is complex to set up and run so they suggest sticking with BT Classic ,  when you load the files for the ESP32 ( see the RN tutorials) into the Ardunio IDE it installs an Example folder which include wifi and BT  test programs.
You should also find a similar ESP8266 Examples folder.

Re the Mosefet, you can drive them directly ( or via a simple resistor)  from the micro if you use the Logic Level Types , most supplier list them as such.
However for your current needs any simple transistor should be fine eg BC337. BC547


----------



## zozo

I think I changed my mind again...  After reading some documentation it seems I didn't think of the obvious. The more fancy features requiring regular updates the more power consumption... Since it needs to run on battery power I need a lite setup to have to longest fun for my buck. But I ordered 3 boards so still room enough to play and see where it ends.

Thanks!...


dino21 said:


> Re the Mosefet, you can drive them directly ( or via a simple resistor) from the micro if you use the Logic Level Types , most supplier list them as such.
> However for your current needs any simple transistor should be fine eg BC337. BC547



Regarding lite, I indeed ordered a few BJT NPN 2N3904 transistors that should do the job perfectly with a 1.5V gate and a 27k resistor to the 3.3V IO pin to switch the 60mA source/base load.

That GitHub site I previously linked to is a gift from heaven... It contains quite a few alternative timer switch programs that are ready to use with minor editing.  Enough stuff to learn...


----------



## zozo

Small update on my research... Since i want to run my project for considerable time on battery power I found out that ESP modules are actually very power hungry devices. The more code is put into it the more it consumes and it gets even worse if it needs a Wi-Fi connection, run a RTC in the background and run a web server at the same time. It would flatten the largest battery out there in hours time...

Thus i had to throw this whole idea overboard and go a different route...



			Dynamic Product Page | Microchip Technology
		




This chip can be programmed with Arduino IDE LUA script.

And it is actually not this difficult at all... All i  need is to run a few LEDs for a period of time and since its for a mini terrarium a 12 hour on//off light cycle is perfect. For this i don't even need a real time clock. I found an easy LED blink interval code that simply goes 12hours On and 12 hours Off in a constant loop as long there is power. The code starts at power up or reset... Thus the hour i want the lights to come on i switch on the circuit and it starts, 12 hours later the light goes off and 12 hours later on again. The controller simply counts down in milliseconds in a loop... Even if there is a slight time shift over a certain period it will be a few seconds per day maybe.  That will be no more than a few minutes per moth and a reset/power down  brings it back on track if needed.

The micro controller consumes few μAh the LED lets  say i take 2 consume 40mAh then i'll be generous with calculating 50mAh total... This on a 26800mAh power bank it should run 26800/50= 536 hours = 22 days x 2 = 44 days at 12 h/d.

For now this is theory... Currently testing the code on the ESP on a breadboard...



When this is confirmed running stable I'll start building the microcontroller...


----------



## castle

That was my main concern, I gace a talk recently in Cambridge where one of the other speakers went deep into low power battery operated arduino devices. I'll try and find it on Youtube


----------



## LondonDragon

Seems like a lot of work to turn a light on and off! Or am I missing something?


----------



## zozo

castle said:


> That was my main concern, I gace a talk recently in Cambridge where one of the other speakers went deep into low power battery operated arduino devices. I'll try and find it on Youtube



Yes i did already read a few articles on that... And they all pul the device into deep sleep, but than still it seems to be a power hog... Only running days on a battery...  Even running the LED only actually exceeds the controllers power consumption.
There for i need a massive power bank, simple batteries wont cut it long enough.


----------



## zozo

LondonDragon said:


> Seems like a lot of work to turn a light on and off! Or am I missing something?



Well to do this battery powered it has some issues if you like it on a real time clock like a timer switch....
It isn't the clock spoiling the fun, but more the lights and the eventual needed relays that consume the most. But both added are too much for general batteries to run a significant time.

The microcontroller is the only way around this... And it's not ready made for this use, so the rest should be DIY build around it.

Instead of relays i use a low current BJT as electronic switch, since analog relays are power hogs again.

In the end once known how and what it actually isn't that much work at all.


----------



## castle

LondonDragon said:


> Seems like a lot of work to turn a light on and off! Or am I missing something?



Unsure, with a birds view down, there's a few things: You need to programming in a low level language (C, ideally). You need to be able to write logic to work with a wifi chip, you'll need to write more logic to handle communications. This assumed you know these technologies, communication is a pig, the wifi stuff could be a challenge, ihopefully we just need to send an http GET; does the creator know about udp or tcp? it might be needed. What about packet loss, connection loss? Hopeflly the chip doesn't involve us needing to write anything more for ISO layer below - but maybe we need to for resource saving. We additionally need an interface to send these messages to the board (use postman @zozo ). I haven't even got to the electronics; if you don't know anything about circuits, control loops, resistnace, voltage (I can go on here) electronics is a pain point too.

Such a simple task as switching on an LED, requires exposure to so many pieces of technology


----------



## LondonDragon

Could you get something like this:

Amazon product

And just connect it to a power bank?

Edit: just noticed the timer on it is not adequate


----------



## zozo

LondonDragon said:


> Could you get something like this:
> 
> Amazon product
> 
> And just connect it to a power bank?




No the challenge given is to make a copy of this bellow running on batteries as is, with the light build in... As requested by a friend who wants me to build it for him.





And i though, this on battery power without the need of a mains socket close would be awesome... Put it where ever you like,maybe he wants to take it to bed... I don't know... But i just thought i'll give it a try, at least if it all fails miserably I learn something new again.

But as above in theory if calculated correctly it might be not that difficult at all... But we need to try first to know.


----------



## LondonDragon

Yeah cool, it is an awesome little project 

Have you seen the candles that have a built-in timer with an LED? 

Amazon product

I have one, and it turns on for 8 hours every day at the same time, and the batteries on it last forever, I am pretty sure you could also take one of those apart and build that little system you pictured above! Might just have to increase the size of the LED if needed!

Bonus: Remote controlled!


----------



## zozo

LondonDragon said:


> Yeah cool, it is an awesome little project
> 
> Have you seen the candles that have a built-in timer with an LED?
> 
> Amazon product
> 
> I have one, and it turns on for 8 hours every day at the same time, and the batteries on it last forever, I am pretty sure you could also take one of those apart and build that little system you pictured above! Might just have to increase the size of the LED if needed!
> 
> Bonus: Remote controlled!




Thanks Paulo, yet didn't seen these things... Absolutely worth to take one apart and look inside... All tho i'm not sure if the led is powerful enough...  A regular white coloured LED giving 12000mcd consumes 20mAh, 1 didn't cut it, currently i'm using 3 (36000mcd) and this seems to grow mosses nicely... I haven't tried 2 yet, but assume it works as well that would be 40mAh consumption. A regular AA provides if its a high end 3000mAh / 40mAh it runs flat in 75 hours.


----------



## LondonDragon

Will keep an eye on this, I am more used to Raspberry Pies


----------



## LondonDragon

zozo said:


> A regular AA provides if its a high end 3000mAh / 40mAh it runs flat in 75 hours.


Powerbank with solar panel? lol

Amazon product


----------



## zozo

LondonDragon said:


> Powerbank with solar panel? lol
> 
> Amazon product




I've tried this, but it wasn't a real success... 😂


----------



## noodlesuk

zozo said:


> I've tried this, but it wasn't a real success... 😂




Haha, love the little generator.

I saw the bit about the ATTINY85, they are great little microcontrollers. I did a similar project for a dummy alarm box with warning LEDs. If you use a crystal on the microcontroller, it will keep pretty accurate time. I programmed it so that once it was powered on, it would flash LED's for 8 hours, then put itself into sleep mode for 16hours, then on again for 8. kept time very well and battery lasted for ages. I had the advantage that the LEDs were flashing, not the constant on in your application. But as a simple elegant solution, the ATTINY85+some transistors gets my vote!


----------



## zozo

LondonDragon said:


> Powerbank with solar panel? lol
> 
> Amazon product













						Solar Power Bank 8000mAh Portable Waterproof Solar Charger with LED Light
					

Only US$20.99, buy best Solar Power Bank 8000mAh Portable Waterproof Solar Charger with LED Light sale online store at wholesale price.




					uk.banggood.com


----------



## zozo

Found the perfect code to do the job... And it actually is just a small snippet...

Original








						blink-led-with-out-using-delay/code at main · shazforiot/blink-led-with-out-using-delay
					

Contribute to shazforiot/blink-led-with-out-using-delay development by creating an account on GitHub.




					github.com
				




Mine




Had to do quite some fiddling to find the way to make it work right... The initial script started always with a LOW (LED Off).
Whatever I changed that looked obvious to me I couldn't get it to start at power up with a HIGH (LED on). I guess this is because all similar scripts I found counts milliseconds from an Unsigned Long previousMillis starting at 0 and then simply always starts with a LOW regardless if the HIGHs and LOWs in the script are changed it only gets a HIGH when it reached the currentMillis set value.  Then if it's powered on its off and you need to wait 12 hours for the lights to come on.

Searched the internet and it seems I wasn't the only one complaining about this code working in reverse but couldn't find a simple solution... And at one point I had an enlighting moment and thought if it counts from 0 to + then can it also count from - to 0?


 Lo and behold and it can and it does... I changed previousMillis from 0 to Minus TWELVE_HOURS and it works like a charm it now starts at power-up with the LED On and switches Off when 12 hours are counted down. Huh? Up. Whatever!?


----------



## zozo

For those yet far from the expert like me, but have a basic understanding of electronics and a little coding experience.
And you like to give it a go, to play with the NodeMCU ESP8266 to create a timer switch relais to switch on your lights via a web server interface on you PC or mobile phone.

Then have a look at this free to use  *ESP8266_TimerPowerSwitch* code at github. It works like a charm with a little code tinkering to get the correct UTC Offset for realtime display on the server.

The straight forward webserver dash looks like this in your browser...

Home



Settings





If you are yet not really familiar with creating electronic circuits then hop to <TinkerCad>. It's also free after you created an account with your Google or Facebook account. You can create simple circuits with all sorts of components and test them out, it also has an Arduino platform with the IDE tool to create code and test both, circuit and code in a virtual simulation. Very handy to find out if you are on the right track without the need for purchasing any components. 

I played a little with the ATTiny microprocessor circuit I intent to use on one of my projects as said to switch a few LEDs on and off with a 12-hour interval with the lowest power consumption possible. And it looks like this.



This worked exactly as intended and it's ready to be built in realtime...

It's really fun to play with and very educative... Awesome tool for noobs like me... And if not for you maybe your kids will love it, ThinkerCad has a lot more to offer then circuits only.


----------



## dino21

Hi,

Good to hear you have got it working ok, but there is a bit of a flaw in your hardware in terms of battery life, if it is as shown above.

The Linear 3v3  regulators use at lot of current that they waste as heat converting the 9v to 3v3 , probably more that the rest of your circuit including the led.

To give a much better battery life use one of these little £1 Buck Converter modules,  you have to set it to 3v3 with the little trimmer and  a volt meter before connecting in circuit, but once done they are around 90% efficient.

Would think it will increase your battery run time by 50 to 100%.


----------



## zozo

dino21 said:


> Hi,
> 
> Good to hear you have got it working ok, but there is a bit of a flaw in your hardware in terms of battery life, if it is as shown above.
> 
> The Linear 3v3  regulators use at lot of current that they waste as heat converting the 9v to 3v3 , probably more that the rest of your circuit including the led.
> 
> To give a much better battery life use one of these little £1 Buck Converter modules,  you have to set it to 3v3 with the little trimmer and  a volt meter before connecting in circuit, but once done they are around 90% efficient.
> 
> Would think it will increase your battery run time by 50 to 100%.
> 
> 
> View attachment 162417



Thank you for your reply...  I knew the Mosfet and 9-volt battery as shown in the circuit isn't the one I should use, but it's an option limitation in TinkerCad. It's the only 3.3 voltage regulator I could choose as a listed example component that in principle practice works the same.

I actually already have the buck converter you link to...

But, I choose to use the TO92 <HT7533> regulator instead since the complete circuit I intend to build is only consuming about 70mA total. And the power supply will be a 5-volt power bank.


----------



## dino21

Hi.

Afraid I was incorrect ,  just did a test on the two types of regs with a 5ma led  load and there is little current difference between the two, seems the buck converters must come into their own at higher current.
Have actually  replaced my  projects hotish T220 regulators with the bucks and they and the transformer run cool by comparison, so must be saving power.

So now you are into programming ,when is the new tank controller due out  ....😁


----------



## zozo

dino21 said:


> So now you are into programming ,when is the new tank controller due out



I did some VBS programming for almost a decade ago in my IT years to automate some computer tasks. Now VBS is ancient and discontinued because it's too rough around the edges. But under the hood it has some similarities with LUA, so that comes in handy to figure out what this basically does and pick some of it back up a bit... Now I'm far from a programmer and don't have the ambition to become one and reinvent the wheel. In most cases, all simple tasks it can do is already out there and done before by others. I'm more of a script kiddie that conveniently searches the net for open-source example snippets I can copy/paste and or edit it with minor changes to make it work for my needs.

It's an old Dutch motto. "It is better to steal something good then to invent something bad" 🥳🤭

By the same motto, I build simple electronic circuits, basically, I know or if not I find out how to connect things to make it work. How it exactly works from the inside out I don't really need to know to learn and remember all of it in detail.
I guess that's the reason why I know a little (basics) of a lot of interests and meanwhile running around like a chicken without a head never found the time nor ambition to become an expert in anything.

Some experts I know call this ADHD... 🤔 (But IMHO it's a or their disorder to put personalities in boxes)

So I really don't know if I ever build a complete tank controller... For now, my brain fart is I want an extremely low power consumption battery powered light switch for a mini terrarium.   Basically, it will be ready on a breadboard somewhere next week, to test it how long it actually will run on that power bank. The aim or expectation is at least 30 days, but this still is a theory... If it does that +/- than I will solder it to a PCB and use it.

After this, I will most likely switch to another brain fart again, usually in an opposite direction. Backing bread maybe...


----------



## dino21

Hi,
You might want to look at the LP2950 or similar Low Drop out 100ma regulators or the little Buck/Boost modules to squeeze the last bit of power out of the battery.

Mini DC DC 3V-15V To 3.3V/5V/12V Automatic Buck Boost Module Converter UP/Down  | eBay

Yes, most folk start off programming the way you have, but soon find they are modifying those routines to suit their particular needs which in turns expands your abilities and soon end up writing most of your own work, can be addictive !


----------



## zozo

dino21 said:


> Mini DC DC 3V-15V To 3.3V/5V/12V Automatic Buck Boost Module Converter UP/Down | eBay


Thank you!  I have a couple of these at home in 3.3 and 5 volt








						2A 4-36V to 3.3V/5V/6V/9V/12V Converter Step Down Voltage Regulator Power Module
					

Only US$3.99, buy best 2A 4-36V to 3.3V/5V/6V/9V/12V Converter Step Down Voltage Regulator Power Module sale online store at wholesale price.




					www.banggood.com
				



And they actually are rather tiny and seem to be pretty sufficient, but still draw relatively high current on their own.

After doing some research on low power applications I found an expert video tutorial on building the best 3.3v voltage regulator. The video is actually about ESP boards in deep sleep, in this case, I only focussed on the regulator explanation.


High current is indeed very relative it's from mA to µA but most regulators as recommended draw more current on their own than the device its powering. And i do not need to draw 2A maybe 70mA total.

With something like an HT7533 or similar. In the datasheet of this regulator, it is recommended to use 10µf capacitors between Vin and Vout and Gr to stabilize it and prevent voltage drops so the device doesn't crash. He explained and showed that the recommended 10µf in the Vout still has a rather high current leakage making the regulator still a rather unstable drop more voltage and draw more current. That it's best to replace this Vout capacitor with a beefier 1000µf capacitor to achieve more stability with only 0.1v voltage drop and 24µA the regulator itself draws from the battery. So I decided to go this route instead. In theory, it seems to be much lower consumption and next to that it's also a lot cheaper, the 3.3v regulator and 2 capacitors together are only € 0.70. I thought I can't go wrong with this. 



dino21 said:


> Yes, most folk start off programming the way you have, but soon find they are modifying those routines to suit their particular needs which in turns expands your abilities and soon end up writing most of your own work, can be addictive !



That's true, in my IT years i really liked to play with VBS programming, used it quite a lot to make life easier at work so it made sense. But then I dropped out that line of work went another direction and kinda forgot about it again. It could very well be I go on with LUA if I find any more future purpose for it. Microcontrollers are indeed very interesting little things. Who knows!? But for now, all I can think of for now is already invented and cheaply available. 

Yesterday I found Blynk you also might like... Possibilities are indeed endless








						Blynk IoT platform: for businesses and developers
					

Join the most popular Internet of Things platform with free Cloud, iOS and Android mobile apps, Web dashboard, and Machine Learning




					blynk.io
				





			https://www.youtube.com/c/techiesms/videos


----------



## zozo

On a side note, for those into DIY and still using the bulky Timer Switches analogue or digital but interested in more convenience.
Have a look at the Sonoff products... 





						SONOFF Official Homepage| Smart Home automation SONOFF Official
					

Explore the innovative world of SONOFF, learn and chose about various smart home products, define your smart home,your smart  choice!




					sonoff.tech


----------



## dino21

Hi,

Just one point about that video, he was talking about regulators like the 1A AMS1117 and the 0.25A  HT7333, but you mention the HT7533 at 0.1A.
Thats is only available in SMD , which might be a problem soldering for you ?  if so the LP2905 has similar low current parameters but T092 packaging.

With either of those 100ma regs,  1000uf across Vin is ok, but not sure if 1000uf across its Vout will work safely ,  a discharged 1000uf will initially present as a short to the regulator and might exceed its 100ma limit ??
Perhaps 220uf or 330uf more suitable for such a low current.

Regarding the Buck modules, the one I last referred  to is a Buck Boost module that intially acts like a voltage regulator, but when the battery drops to around 3v5 it would normally loose its 3v3 regulation, but the Boost part will allow it to still produce 3v3 even though the battery voltage has dropped to say 2v.

Yes,  did try a simple test with Blynk when we first got the ESP boards,  but was about to put a post up on the electronic forums to see if Bylnk or any others are the best to use, not just from a coding point of view but more in terms of will they be available in the future, a bit like other online  services where a couple of years later they withdraw  things and everyone has to change or pay high charges.

Those Sonoff  devices do seem good and  popular , though a bit old fashioned there, why do we want to turn things on and off from a mobile phone ?  
Same when it comes the fish tank, surely your system should be designed to control things, so why would you want to override that remotely  ?
eg. We would not want to change dosing parameters and not be around to properly observe the effects.


----------



## zozo

dino21 said:


> the HT7533 at 0.1A.
> Thats is only available in SMD



I have it in TO92 model, it actually was the only 3.3 regulator available at that shop. Got it in the mail this afternoon and is already running fine so far. Still waiting on the ATTiny to arrive.



I didn't think of a capacitor discharge and fry the regulator!? Why would this happen? But if so and the risk is high, it might indeed be good to replace it. Not going to die over a few µA.  All tho it already seems to discharge over the LEDs when its switched off by the looks of it. The LEDs fade off.

Good point on the buck converter...  Something to keep in mind depending on how the HT7533 works out.



dino21 said:


> Those Sonoff devices do seem good and popular , though a bit old fashioned there


Lol, yes things go crazy fast these days with electronics, you buy it walk out the door and you're about old fashion before you're on the street.



dino21 said:


> why do we want to turn things on and off from a mobile phone ?


Also a good question one should answer for himself... I happen to have a few occasions I find it handy... One happens to be the lights from one tank where the power plug and the timer switch in it is behind a huge jungle of plants and pots I need to move to get to it. The next time I'll need to be there I'll definitively be going to replace it with a Sonoff I already have laying around.  For example, next time when we need to reset the clock to summertime.  And thereafter no more moving plants and pots and reset it manually. The other one is switching some lights on in the garden without the need for opening the door, going out and plug them in and visa versa. Well, I guess having multiple remote controls laying around is even more old fashion and less convenient than 1 mobile phone. Or install MemuPlay and do it via the PC.

For the rest indeed, I'm personally also not font on totally automating fishtanks I rather keep my hands on it... Also not into auto dozing fert or food... Not my intention I like this also the old fashion way.


----------



## Kattis

Hi! I have also started to mess around with arduino and I was wondering if there's a reason you don't use real time clock (RTC)?


----------



## zozo

Kattis said:


> Hi! I have also started to mess around with arduino and I was wondering if there's a reason you don't use real time clock (RTC)?



Yes, my aim is to make a low power application that runs as long as possible on a battery/power bank. And I have 60mA LEDs that need to be turned on 12 hours a day.

I did think of doing this with the help of an RTC, but in the end only means more power consumption. Then what good is an RTC if you can't read it real-time? And if not updated regularly it will have the same deviation in the microcontroller simply counting down milliseconds. Then updating/syncing an RTC would require an NTP connection. Again a relatively high consumption source to build that around it.

To undress it from all actually unnecessary bells and whistles that consume power. I thought to take a simple blink sketch put this in a microcontroller and make it turn the LED on at startup then countdown 12 hours to turn it off and back on 12 hours later. With an indefinite loop.

The moment the microcontroller gets turned on it turns on the LEDs and it starts counting down and does this with the very same milliseconds and clock speed as it would run the RTC. There would be no difference, in this case, an RTC has no added value. If there would be a 15-minute time shift in a month time then a hard reset would be enough to start over again with a fresh count. This actually will happen anyway since it runs on battery and this will need to be replaced. If my calculations are correct about every 45 days.


----------



## noodlesuk

Kattis said:


> Hi! I have also started to mess around with arduino and I was wondering if there's a reason you don't use real time clock (RTC)?



Just to add, yes agree with zozo, it's another overhead that you have to manage with power, both processer and energy. For most simple delay projects, the internal timer suffices. 



zozo said:


> The moment the microcontroller gets turned on it turns on the LEDs and it starts counting down and does this with the very same milliseconds and clock speed as it would run the RTC. There would be no difference, in this case, an RTC has no added value. If there would be a 15-minute time shift in a month time then a hard reset would be enough to start over again with a fresh count. This actually will happen anyway since it runs on battery and this will need to be replaced. If my calculations are correct about every 45 days


If you use an external crystal on the ATTINY microcontroller (most arduino's have these built in) rather than the internal clock, you might find it keeps time better.


----------



## Kattis

Ah ok, I thought RTC had its own battery and using it with sleep function or AutoPower could save overall energy. Mind I’m very much a noob so following this with interest.

I was planning on dabbling with some kind stripped down Reef Pi style system but it’s so complex that I think doing something simple with LEDs could be good first step


----------



## zozo

noodlesuk said:


> If you use an external crystal on the ATTINY microcontroller (most arduino's have these built in) rather than the internal clock, you might find it keeps time better.


Thanks for the tip, I have to do some research on that...  For now, i did run the sketch on an ESP and it runs pretty accurately. The time shift is neglectable, yet no idea about the ATTiny performance with this. Haven't received the order yet.


----------



## zozo

Kattis said:


> Ah ok, I thought RTC had its own battery


It does and it can run pretty long a button cell, the clock is not the issue... But to set it, it needs a lot more to it than the RTC module only. You would need a display and a timer function to set and control the relays on/off time. And to keep track of time and sync it real-time, as said, it needs an NTP server connection. All that added is quite a power-hungry application... 

That's why I first thought I could do it with NodeMCU or maybe an ESP only. this can also run an internal RTC... But again very power hungry.

Another thing I also aim for is to make it in the smallest footprint possible...


----------



## dino21

zozo said:


> It does and it can run pretty long a button cell, the clock is not the issue... But to set it, it needs a lot more to it than the RTC module only. You would need a display and a timer function to set and control the relays on/off time. And to keep track of time and sync it real-time, as said, it needs an NTP server connection. All that added is quite a power-hungry application...
> 
> Other thing i also aim for is to make it in the smallest footprint possible...


Agree with you that just using the internal timebase  / millis is all you need if you have got to change the battery /reset it every month or so.  surely adding or loosing a few minutes over 45 days is not going to be important for this project.


----------



## noodlesuk

Kattis said:


> Ah ok, I thought RTC had its own battery and using it with sleep function or AutoPower could save overall energy. Mind I’m very much a noob so following this with interest.
> 
> I was planning on dabbling with some kind stripped down Reef Pi style system but it’s so complex that I think doing something simple with LEDs could be good first step



Yes the RTC's do, sorry was a little confusing, my reply.

I too was looking at reef-pi, but was far too overkill for what I needed. I created my own setup (aquasca-pi ), which was a cut down version with web interface <Here>. If you want anymore info, pm me, don't want to hijack the thread!


----------



## dino21

Kattis said:


> Ah ok, I thought RTC had its own battery and using it with sleep function or AutoPower could save overall energy. Mind I’m very much a noob so following this with interest.
> 
> I was planning on dabbling with some kind stripped down Reef Pi style system but it’s so complex that I think doing something simple with LEDs could be good first step



Thats a good way to learn,  try doing a timer to switch  your leds on and off at a specific time, using your RTC module.
Also look into using logic level Mosfets to control you DC devices, a lot less noisey than Relays,  electrically speaking.
Save that module as it could form the basis for other timers such as a doser  etc

Then you could adapt your timer  module to included a sunrise and sunset routine to control the leds using the PWM function,  though doubt it makes any difference to the fish or plants, it does make things more natural to us.


----------



## zozo

noodlesuk said:


> don't want to hijack the thread!


Never mind...  Me too I can only learn from this... I will not consider it hijacking at all.


----------



## LondonDragon

zozo said:


> I've tried this, but it wasn't a real success... 😂



Still amazed by that little reactor!


----------



## zozo

LondonDragon said:


> Still amazed by that little reactor!


Haha...  It is indeed a great little toy that Stirling Engine... I actually bought it as an educative present for my nephew but couldn't help playing with it myself for a couple of days...









						Stirling Engine Model Physical Motor Power Generator External Combustion Educational Toy
					

Only US$48.99, buy best Stirling Engine Model Physical Motor Power Generator External Combustion Educational Toy sale online store at wholesale price.




					www.banggood.com


----------



## Kattis

Thanks guys! I probably should start some Arduino for idiots thread. I was wondering is there a reason why any LED light can’t be dimmed with PWM? I have little Aquael LED with my shrimp tank and I was pondering hacking that but it says something about having spare LEDs that come on when others dim to keep equal brightness.


----------



## Kattis

zozo said:


> I've tried this, but it wasn't a real success...




This is really cool  I can see how to end up on serious tangent with this stuff and end up with permanent mad scientist branding


----------



## noodlesuk

Kattis said:


> Thanks guys! I probably should start some Arduino for idiots thread. I was wondering is there a reason why any LED light can’t be dimmed with PWM? I have little Aquael LED with my shrimp tank and I was pondering hacking that but it says something about having spare LEDs that come on when others dim to keep equal brightness.



You can use PWM to dim any LED, the arduino PWM will only handle mA, so you would need a transistor that is controlled by the PWM signal, which controls the larger load of multiple LED's. That's what I do on my nano tank to get a sunrise/sunset type lighting profile. Sounds as if the Aquael may already have a controller in it, that dims 90% of the LED's, whilst the others are on all the time? You'd have to open it up and try and trace the circuit to see how the LEDs are controlled. You would have to bypass any controller already there if you wanted to use your own PWM LED controller.


----------



## zozo

Kattis said:


> I was wondering is there a reason why any LED light can’t be dimmed with PWM?


The LED in itself as the Light Emitting Diode it is can be dimmed with PWM it might only need the proper current sensing resistor... If it concerns a factory-made light containing LEDs than it might be a different story. This because a LED is current driven, it might contain a constant current driver then the driver chip needs to be dimmable over a PWM pin.  Some dimmable constant current drivers can be dimmed over PWM directly over the mains without the pin on the driver chip, but this is a rather crude solution that could cause the driver making a faint beep noise. Then it's more constructed for a phase dimmer or a variac.

For the rest is PWM a rather complicated and not so easy to explain matter (At least for me that is)... In principle, it's a 3-volt analogue signal that gives an On/Off pulse, in Arduino, this is stated from 0 (low) to 255 (high). For a single 3 volt LED it can be driven over and Arduino etc. PWM pin directly depending on the pins max output current it might require the correct current sensing resistor.

Do you want this with an array of LED's then you need to drive them again over a driver chip with a PWM/DIM pin connected to the Arduino PWM pin. (Or via a capable Mosfet I think.) There are many of those LED driver chips out there in development.


----------



## zozo

I might add, in laymen terms PWM as the abbreviation stands for Pulse Width Modulation is a 3-volt pulsing signal.
Anything a LED or a Motor than runs on a higher voltage than 3 volt needs an extra driver hooked to an adequate PSU that can interpret the PWM signal and so on the driver is a PWM driven voltage regulator. For example a 12-volt input PWM dimmer or Motorspeed regulator connected to a 12-volt PSU. Gives 0 volts output at PWM pulse 0 and increases the output voltage towards 12-volt max accordingly in 255 steps. 

Why some seemingly dimmable LED drivers make a beeping noise when hooked to such a dimmer is a complete mystery to me... It kinda makes no sense actually and makes me think the drivers are crappy or that the above isn't fully correct.


----------



## zozo

Finally, I got it to work.




And it was quite a runaround to get this far... Yet i didn't have a programmer... Now it seems the NodeMCU ESP8266 can function as one but only as Wifi-AVR-ISP as can be found here. So i did set it up as seen in the pic top right.








						Arduino/libraries/ESP8266AVRISP at master · esp8266/Arduino
					

ESP8266 core for Arduino. Contribute to esp8266/Arduino development by creating an account on GitHub.




					github.com
				




Thus this means we need to send a package from the PC over the network TCP port to the Nodemcu so it can program the chip. And it can only program via CMD console AVRDude. Arduino IDE crashes this process. 

That's where the fun starts because AVRDude and Windows do not support this function it drops the package along the way and the programmer times out. In windows Arduino programmers only can communicate over serial COM port it seems. After 2 days of searching, I find a little tool <Netburner NNDK> and this allows you to make a virtual COM port hooked to an IP/TCP Port... Than AVRDude does its job perfectly fine and programs the chip flawlessly. 

For now, it works a charm, my circuit is running as should now up to the next stage... Testing ho long this runs on a desent power bank. If that meets the expectations I will solder it to a PCB to be built into the project.


----------



## noodlesuk

Wow looking good, looks like you have learnt loads in a very short amount of time, lots of progression in this thread! Are you planning a PCB design for it, or using proto/vero board?


----------



## zozo

noodlesuk said:


> Wow looking good, looks like you have learnt loads in a very short amount of time, lots of progression in this thread! Are you planning a PCB design for it, or using proto/vero board?



Yes, thank you...  I did learn quite a bit the past few days... It was a hell of a search to make things work. Once you know it's simple but before, it was a pain in the neck to find it out... Searching for the errors I encountered, I found that a lot of people using Windows ran into the same problem and complained about the ESP8266 AVR-ISP not working. Took me 2 full days searching and reading to find out about the virtual com port, this information was very well hidden in an Arduino blog in Chez language I had to translate. I guess very little people know about this workaround and even the author of the program fails to mention it in his Github documentation.

I already have bought a couple of small proto/vero boards.  That's a lot more convenient for such a tiny project.


----------



## dino21

Wow, well that one way to program a chip !! 

We used to take the simpler route with one of these little USB programmers, they do most AVR chips  including the ATTiny.

What you can also do is burn a bootloader into the chip so you should then be able to simply reprogram from the Arduion IDE afterwards.

How to Program and Bootload ATtiny85 With USBasp


----------



## zozo

dino21 said:


> Wow, well that one way to program a chip !!
> 
> We used to take the simpler route with one of these little USB programmers, they do most AVR chips  including the ATTiny.
> 
> What you can also do is burn a bootloader into the chip so you should then be able to simply reprogram from the Arduion IDE afterwards.
> 
> How to Program and Bootload ATtiny85 With USBasp



Thank you!... 

So I found out but didn't have it yet. In all my frustration I did order a USBasp yesterday...And this afternoon I found the fix...
Well no loss anyway, it still might be easier to use than the ESP so it has some future use.

I have a couple of those small development board programmers (spark fun clones) I ordered and thought would do. But these are an absolute useless Chinese scam. I got ripped off for € 4,50.  When it is plugged in it says unknown USB device, then I read indeed the chip needs a bootloader first to make this board function. Then what good are they? Thus it needs a programmer first to burn the bootloader and then program with this board while you are already at it with another programmer?

The good thing about it is, I learned how to make the SPE work and still program my chip.  I have a couple extra Attiny's and did burn 2 different bootloaders to each of them and the above development boards still don't work...  And those darn Chinese tell you zip only sell it... It might need another bootloader? But I don't care anymore actually I wrote a bad review and throw them in the trash.


----------



## dino21

Hi,

Do not see those BG board as a Programmer ?  its just a couple of sockets and a voltage regulator as a mini dev board.

The USB ASP little boards do work, we programmed some Atmega328 chips direct, ie just the chip and a xtal,  though cannot remember if we ever programmed in a bootloader, was a  good few years ago.
Seems today there are more software options to run them, at the time we used some far east program that came with the  stick., a bit of a learning curve as it needed details of which "fuses" to burn etc etc.


----------



## zozo

dino21 said:


> Hi,
> 
> Do not see those BG board as a Programmer ?  its just a couple of sockets and a voltage regulator as a mini dev board.
> 
> The USB ASP little boards do work, we programmed some Atmega328 chips direct, ie just the chip and a xtal,  though cannot remember if we ever programmed in a bootloader, was a  good few years ago.
> Seems today there are more software options to run them, at the time we used some far east program that came with the  stick., a bit of a learning curve as it needed details of which "fuses" to burn etc etc.



It seems they like to overcomplicate things... At least for beginners, it is... I first did read the BG reviews on these boards and some say it's noo good and others say perfect if you know what you are doing... Thus I thought they seem to be good to go I'll figure it out and ordered them. They are Digispark clones and the chip needs a special bootloader to get recognized by the proper USB hub driver. The original Digispark seems to use the Micronucleus bootloader and USB drivers. But with these boards, I was curious and tried 2 different ones the Micronucleus en ATTiny85-default and still no go. Then we again have a run around to find the proper drivers, BG doesn't tell, people who know writing positive reviews probably don't tell for the nerdy fun of it. I don't know and actually don't care anymore...

The ATM chips don't require a bootloader at all to get programmed if the correct programmer is used. The first one I programmed worked straight of the bat without it. So I have no idea why they are developing and even cloning these things? And then sell it without the proper documentation? As if they just like to give people a run around for their money by selling silly crap. And indeed playing with bootloaders can mess up the fuses and render the chip useless. I think I messed one up but don't know yet.

But as you say, it's a learning curve...  Maybe that's why they are throwing curveballs, to keep us off the street.


----------



## not called Bob

I can say,  I don’t understand an awful lot of this quest, my electronics career ended with my gcse’s, but im marvelling at your dedication to this project.


----------



## dino21

not called Bob said:


> I can say,  I don’t understand an awful lot of this quest, my electronics career ended with my gcse’s, but im marvelling at your dedication to this project.



Think even @zozo will agree that he has had diffiucult and unusual route with his minature project, though starting off with the Arduino is normally a much easier experience.

If its something that interests you,  for just £5 you can purchase,  from this good uk seller,  a starter clone Arduino board and run it with the free official software and countless online tutorials / examples.
Something to keep your mind active , lockdown or not 

https://www.ebay.co.uk/itm/Arduino-...299808?hash=item4b2e3d0ba0:g:bmcAAOSwK~RaFdI3

Software


----------



## zozo

dino21 said:


> Think even @zozo will agree that he has had diffiucult and unusual route with his minature project


Haha, I certainly did, I went the hard way off the bat. I know it's not the best example to give for other newbie's.  I just worked with what I had at hand and didn't want to sit around and wait on orders to arrive... Even tho I ordered a USBasp I got a little frustrated and impatient that I couldn't get the ESP to work as expected and simply didn't want to give in to that. 
I guess that's the nutty troubleshooting pitbull mentality in me I developed in the 10 years I worked in the IT branch as SysAdmin. 

And I must admit I'm also not entirely unfamiliar with electronics. I played with it for a few years as a teenager. Never made a hobby out of it because I actually was studying in a completely different direction. But it always kept intriguing my interest. I guess that's why ended up becoming a SysAdmin in the first place after working 25 years in the mechanical industry. We live in a very interesting era, the teen generation of the 1970s witnessed some crazy developments where mechanics and electronics where racing in more and more overlapping development.  Looking at today's automobiles is the best example.


----------



## zozo

not called Bob said:


> but im marvelling at your dedication to this project.


Well, thank you...


----------



## zozo

Haha, now the circuit is ready and hooked to the power bank at my friends' house and another nice issue I never thought about came up.  Simply didn't know yet... But it seems those darn USB power banks are designed as chargers and not as constant voltage power supplies for low current applications. Thus this means each power bank requires its designed minimal draw current to stay switched on. If the current drops below a certain value the Bank closes and goes into standby.
Thus with the small +/- 70mA my circuit is pulling the Power Bank thinks it's switched on but doing nothing, thus goes in an auto power-off mode in a minute.

It seems to be a standard feature that all Power Banks have build-in. And to find one that doesn't is searching for the needle in the haystack or pay top dollar for specially designed experimental IoT Banks. Internet is littered with this question and complaint.

In my research, i found out that the only way to fool the power bank thinking it needs to stay on is to generate a pulse over an NPN transistor pulling a minimal load for a few millis before the build-in timer runs out and switches off. Most people use the NE555P chip for that in a separate circuit to pulse and pul the load.

Fortunately, I'm already using the ATtiny and this actually can do the same... So I had to edit my code to add a Pin and make this come High about every minute for 250 milliseconds to shortly pull the minimum load from the power bank to prevent it from switching off. 🤬

Here I made a small circuit diagram as to what it should be... Pin 2 runs the LEDs on/off for half a day over the 3904




Pin 1 should pulse the minimum load over an NPN that I yet do not know so I left it blank with an X. Still need to get my hands on that specific power bank in question. From what I read I assume an extra 100mA once +/- every minute for a few milliseconds should fool it to stay switched on.

And extra power consumption, but no other way around it, it seems...


----------



## noodlesuk

Nice circuit. It's a classic thing, think you have it all nice and working and then you plug it in and it doesn't work! However, Engineering a solution around it can also be quite exciting. Looks like a very elegant solution. You can also buy adaptors, but this wouldn't be as elegant.

Power Bank Keep Alive

If you find that changing the pin, for the keep alive circuit, interferes with other processor operations, you can use the built in clock on a pin that can operate independently of any code. If you have a simple program, then dipping out to toggle a pin every 250ms, might not be an issue, but can sometimes help. I've used this when running a stepper motor, the oscillator provides the pulses and the mircroprocessor is then free to run other buttons and sensors/LEDs etc.

Attiny Oscillator


----------



## zozo

noodlesuk said:


> Power Bank Keep Alive


Thanks... 

Yes, I found this one and a few more of them Smarties trying to sell it, but looking a tad further I found the DIY diagram, etc.








						Power Bank "Keep-Alive"
					

A simple module to keep power banks from turning off, when your DIY circuit draws low currents. By Tirdad Sadri Nejad.



					www.hackster.io
				




Reading it I thought this I can do with the ATtiny no need for an extra chip etc, currently only using one pin still have 5 others left. So I looked up how to edit the code to get 1 extra pin pulsing over the internal millis time base first to see how that will go. Going to test how (long) that will run with this extra consumption added. Then I will find out how good the internal timebase is to keep the bank alive.

I had it running for a week on a phone charger and it doesn't seem to drift off in time that much.  But this could indeed be an issue with keeping the bank alive, yet no idea with the minimum current draw and the shut-off time sequence of that thing is. My mate said around a minute...


----------



## zozo

noodlesuk said:


> Attiny Oscillator


Very interesting!... Thanks...


----------



## zozo

For those who like to see a simulation concept of this project visit Tinkercad via the link below.









						Login | Tinkercad
					






					www.tinkercad.com
				




This link is active for 336 hours counting down (Millis) from the time writing.  And actually, i have no idea if you need to subscribe to see the content. But if you do, no worries it's 100% free, no strings attached, and with a Google or Facebook account, it's done in a minute.

And Tinkercad is awesome, for a lot more design simulations than only this... Tinkercad rocks for many kinds of designs. Tho i guess you need to be a tad of a tech nerdy. ☺️


----------



## zozo

I'm finally done and have it working like a charm for now...  The diagram below...




The Power bank has a build-in standby shut-off timer for 1 minute 58 seconds. Gave pin 1 from the Attiny via a npn transistor a 55 Ohm 1 Watt resistor and a small green 20mA LED resulting in +/- 120mA total dummy load. This comes on for 1 second every 110 seconds and a little green LED blinks. That is 8 seconds before the Power Bank shuts off and resets the shutdown timer to 0 again and about enough to keep it on 24/7.

Now it's waiting to see how long that power bank will run this circuit... If calculated correctly and if the Bank specs are accurate it should run at least a month.


----------



## zozo

It's done and rocking and rolling like a charm... 

I decided to keep the actual PCB in view to add some intrigue to the project. The Old Cigarbox contains the battery. The copper coil on the PCB is an ornamental fake doing nothing other than look nice. I kinda liked to add it, because it also adds intrigue and adds to the overall steampunk style.




With all 3 LEDs at full power 60mA, it ran at the first for 26 full days... Then I looked in the dark and dimmed the LEDs to 8mA each and it still is light enough... That is 24mA total and 36mA less consumption. Thus most likely it must run a lot longer than 26 days like this on a full battery.





Backside view, with On/Off switch and a USB-A flat cable...




Top view of the PCB, with the blink, LED on...  I'm planning to paint the PCB silver colour and put some brass and bronze colour on the components with enamel model paint to keep all in the same old fashion Edison style...




And the power bank in the Cigar Box...



 No idea if this is the first Battery powered ATTiny Terrarium?

Technically finished and approved, aesthetically still a little work to do...  I'll test run it for another month or so before I start painting.

For those interested, this is the final circuit... Completely wrong drawn by conventions, but I guess it does the job...


----------



## jacobb6

zozo said:


> Solar Power Bank 8000mAh Portable Waterproof Solar Charger with LED Light
> 
> 
> Only US$20.99, buy best Solar Power Bank 8000mAh Portable Waterproof Solar Charger with LED Light sale online store at wholesale price.
> 
> 
> 
> 
> uk.banggood.com



Oh, I have the same one like this. Critical when I wanted to charge my cell phone or tablet quickly. Have had different advice from TSA here on whether I can take it onboard a plane, so have used it only if traveling by car, bus, or train. Easily charges cell phone 3-4 times before requiring a recharge. The battery holds enough juice for me to use it all week. It may take a few hrs to charge the device completely but it’s 100% worth it


----------

