# Computerized Nano, Mark II (LED Dimming 2-27-11)



## Robotguy (Jan 24, 2010)

I decided to move the computer controlled nano thread into DIY because it will be a while before it even gets water. I took a hiatus from the project while I worked on other shiny projects, but now I'm back and itching to bend/cut/glue/solder/program a desktop nano. I am bypassing the cooler unit for the time being, because it was hangups in the design of that unit that stalled me last time.

I am also switching from glass to acrylic so I can incorporate some filtering into the body of the tank, and am currently looking for some advice on layout. The basic design will be something like this:


I have this so far (sorry for the cell-phone pic):


I want to design an IRFUG (Integrated Reverse Flow Undergravel Filter) into the floor of the tank and at least a small overflow into the back. So here's my first question:

Should I make the rear or bottom areas large enough to contain the entire filtration system? Or should I push the floor all the way to the bottom, make a minimal overflow section in the back and go with an external canister in order to maximize display volume?

BTW, I am seriously considering trading this version on the S&S for some plants when I get it "done."


----------



## bigboij (Jul 24, 2009)

what did you use to make the bends like that for the front?


----------



## gordonrichards (Jun 20, 2009)

I vote external canister filter. Maybe put it in a black box to the left of the aquarium.
Filter will take up much needed space.
You can put your cup of pens and bottle water on top of it :^)

Awesome looking tank. +karma

Where did you find the bent acrylic? Lol

-Gordon


----------



## MeanGreenEyes (Sep 24, 2010)

Subscribed...gotta love the techy side of this hobby!


----------



## Robotguy (Jan 24, 2010)

bigboij said:


> what did you use to make the bends like that for the front?


That one was done with a heatgun. Heat both sides slowly and carefully along the area to be bent, bend into shape and hold 'til it cools. Acrylic shows every flaw and you can see that the bend is not consistent from top to bottom. I think I may build an acrylic bender like the ones below this weekend.

http://www.bishoptechnology.com/proj_acrylic_v2.html
http://pcbheaven.com/projectpages/Acrylic_Glass_Folding_Heater/
http://www.youtube.com/watch?v=WQGoKUVfe6g

Here is an awesome pico that was done in the oven (Note: *Don't try this!* The author of the post below states that he almost ruined his oven and others have mentioned that acrylic gives off explosive vapors when heated :icon_eek:-->:eek5:-->-->:angel:
http://www.nano-reef.com/forums/index.php?showtopic=88081&st=0&start=0

The idea of a single power cord and no tubing coming from the tank is appealing, but the bent acrylic in my previous post is the largest I have so if I want to maximize display volume I'll need external filtering. I was thinking about putting everything under the desk (probably in a tub, just in case). Would a SunSun be way overkill for 3.6 gallons? They are rated for 265 GPH, so thats 73X turnover. Hmmm, with an IRFUG, it may end up as a substrate blender...


----------



## Jaggedfury (Sep 11, 2010)

I visit TAP Platics alot, get most of my custom supplies there. I also used it alot for my work. They will bend acrylic for you as well, it's all about money.


----------



## Robotguy (Jan 24, 2010)

Just a couple of quick pics before bedtime:




I cleaned up the edges with the table saw since the router wasn't doing the trick, then cut the back and bottom slightly oversized so that I can trim them with a flush cutter on the router (after they are glued on. Right now they are just set in place for the pic). I dont know if its visible, but i did nick a corner on the clear when i was cutting it (upper left corner in the pics). I will need to figure out what i am going to do about that. 

Maybe tomorrow I will mill the IRFUG then glue and trim it.

For the overflow I plan to mill a pocket in a piece of 1/4" clear acrylic and this 1/4" black, then when I sandwich the two together I should have a .375" gap between the two. Water will flow into this gap through slots along the top edge. The back of the sandwich will be clear so I can see if anything is stuck in there.

Does that make any sense? Maybe I'll draw up a solid model tomorrow night and get some feedback before I start gluing or cutting anything...


----------



## Robotguy (Jan 24, 2010)

A picture is worth 1k works so maybe this will make a bit more sense:


Note the gap behind the slots along the top back. That will be a small overflow. Here it is from the back:


There is a hole into the overflow area where I plan to thread a hose barb. The volume of the overflow (to the bottom of the slots) will be 7.25" X 8.5" X .35" = 21.5 cubic inches = .1 gallons. Will that be enough to keep from sucking air into a canister filter?

The IRFUG is also made from a piece of .25" clear and .25" black acrylic sandwiched together. A hole also goes through into the manifold area from the rear of the tank. You can see the array of holes for the IRFUG in this shot:


----------



## HolyAngel (Oct 18, 2010)

zoomed 501 canister filter, it does ~93GPH and may work much better, also quite a bit smaller too 

Looking forward to the rest of this build tho, good luck! ^^


----------



## Robotguy (Jan 24, 2010)

HolyAngel said:


> zoomed 501 canister filter, it does ~93GPH and may work much better, also quite a bit smaller too


I'm thinking of going DIY all the way and building a canister filter. I have a hunk of 4" diameter acrylic that might work. I also have a 100GPH submersible pump, (left over from the last incarnation of this project) so that sounds about right...

Oh yeah. If anyone is interested, I uploaded the eDrawing of the tank so you can spin it around in 3D:
http://robotguy.net/aquarium/AQ4.easm

You'll need the eDrawing viewer to see if, but it's free:
http://www.edrawingsviewer.com/


----------



## VaultBoy (Nov 11, 2010)

looks great cant wait to see it up and running... if you do DIY the canister filter make sure you put up a heap of pics... i want to build one myself

good luck


----------



## Robotguy (Jan 24, 2010)

Hmmm. Just found this:
http://www.parallax.com/Store/Senso...efault.aspx?SortField=ProductName,ProductName

I have never seen a sensor like this before. Looks like it could be useful.


----------



## Robotguy (Jan 24, 2010)

Little bit of an update.

I dropped the IRFUG, it added complications and didn't really provide any benefits. I also changed my mind about the overflow on the back. I am making a larger overflow/filter (about 3" deep and half the width of the tank) and putting a small submersible pump, foam, and some bio-media in it. I cut some slots along the top back of the tank where water can flow into the filter area and plan to make an acrylic spraybar for the outflow.

As for the lighting, I am going to try something funky. I found this lamp at sciplus:









I am going to use the steel goosenecks to mount my 5w LEDs, so they will be easy to position.

I have my heart set on Flourite Black Sand as a substrate. Is there any way to buy smaller quantities of that, or something equivalent? I hate to pay $30 for a humongous bag when I'll only use 1/5 of it.

I spent quite a while gluing parts for the main tank area together today, and now I am waiting for the glue to dry. I will clean things up with the flush cutter tomorrow and post a few pics. After that I can start gluing up the filter and electronics areas.


----------



## MlDukes (Nov 24, 2009)

Great start! Why not just finish it off like a nanocube? You could use a compartment to house/hide the heater.

I like the lighting idea, hope it works out!


----------



## Robotguy (Jan 24, 2010)

MlDukes said:


> Great start! Why not just finish it off like a nanocube? You could use a compartment to house/hide the heater.
> 
> I like the lighting idea, hope it works out!


Thanks! It will end up a lot like the nano-cube or the IQ3. There's even a thread where someone put multiple gooseneck lamps on an IQ3. So yeah, something like that!

I ran the flush cut bit around the edges tonight to clean it up. I've never used a flush cut bit before, it's pretty cool how nicely it works to make the edges look good.







Oh, yeah - No leaks! Yay!

I ordered the light and a couple more high-power LEDs today. They should be here by the end of the week. I am also planning to add one of those tiny disposable pressurized CO2 setups and I _think_ 3 of the peristaltic pumps I am working on will fit.

Time to head back out to the lab and glue some more pieces on the back to build up the filter section.

Edit:

Whoops. Almost forgot to drill for the spraybar before I built the filter:


----------



## Robotguy (Jan 24, 2010)

Got a little more work done. The filter area is built and finally waterproof. 

I wanted to have an o-ring seal but it just didn't work out. I ended up having to seal it up with silicone. Now I'll stuff it with a bit of foam and some kitchen scrubbers.


I also received my new LEDs and the "donor" lamp. This is the first prototype of the assembly:


There will be 4 or 5 of these across the top of the tank. Here's a shot with the LED lit, running at about 750mA:


And finally a lighting comparison with the filter running:


I want to make sure this thing has enough light to grow a nice carpet of HC. It looks like I'll have between 640 and 700 lumens about 12 inches from the substrate.

Has anyone seen the "Electronic regulators" from aquariumplants.com? I think I'm going to do something similar with an 88g co2 cylinder, a Leland regulator and a small Clippard solenoid. I'll leave the regulator set at a decent pressure, then use the microcontroller to open the valve for some percentage of the time, say 1 out of every 10 seconds. If I need more or less co2, I will adjust the duty cycle of the solenoid rather than adjusting a regulator or needle valve.


----------



## mistergreen (Dec 9, 2006)

[strike]A CO2 sensor to control CO2 concentration would be cool  You don't have to worry about bubbles/sec and all that none-sense that we regularly go through.

http://www.parallax.com/Store/Senso...ortField/0/Level/a/ProductID/598/Default.aspx

Maybe build it like a drop checker so it doesn't get wet but will get CO2 in the compartment or use a permeable membrane like the kordon breather bags. It will let gases go through not water.[/strike]

I just read the specs for the CO2 sensor. It's only sensitive from 100 - 1000 ppm... We need it to be around 30ppm.. Neat idea though. If I can find one more sensitive, I'd give it a go.


----------



## Robotguy (Jan 24, 2010)

mistergreen said:


> I just read the specs for the CO2 sensor. It's only sensitive from 100 - 1000 ppm... We need it to be around 30ppm.. Neat idea though. If I can find one more sensitive, I'd give it a go.


Wow, that's a bummer. I was getting excited about that sensor. I've been looking into ways to measure co2 for a while now. My current plan is to use a color sensor looking a a drop checker, but that seems a little roundabout and requires maintenance of the drop checker solution. I have been toying with the idea of a DIY NDIR sensor, but sources and filters for 4.26um are a bit pricey.

Hmm, looks like these guys have it figured out, though. And $65 isn't bad:
http://www.co2meter.com/collections/co2-sensors/products/k-22-pwm-co2-sensor
Unfortunately it's only got a repeatability of +/- 40 ppm. I think the biggest problem is that no-one is building sensors for planted tanks, they're all for air quality measurements and need a range of thousands of ppm. We need one with a range of 100ppm and an accuracy of 1ppm. That's less than 7 bits, should be easy right?

Looks like I'll have to stick with the drop checker solution for now. It really is amazing to think that drop checkers can measure that accurately. 30ppm is .003%. A lot of the expensive commercial sensors can only hit .1% resolution.


----------



## mistergreen (Dec 9, 2006)

They actually do make underwater co2 sensors
http://www.contros.eu/products-hydroC-CO2.html

or something like it.. It's beaucoup bucks though. I remember plaintbrain used it in his experiments.

The only problem with using a color sensor looking at a drop checker is that the pH solution loses its property over time so you'd have to put in a new solution every few days.


** just read the specs on that sensor. It uses IR absorption spectrometry.. oooohh.


----------



## Robotguy (Jan 24, 2010)

Progress!

After a few tries, I got the lights built:




The LEDs on the black stars are 5W from DealExtreme and the red ones are Luxeon Rebels from Sparkfun. Both are driven with a board from DealExtreme that I modified to provide 700mA.

LED--------------Voltage(V)----Current(A)----Power(W)
DealExtreme(x2)----13.1-----------.71-----------9.3
Sparkfun------------3.2-----------.71------------2.3


So I borrowed the light meter from work and decided to take a few measurements. I divided the bottom of the tank into 12 sections and took readings with the left, right, center LEDs, then one more with all LEDs on. The measurement head is sitting on an aluminum heatsink to simulate substrate depth.

Heres the Data in a Google Doc.

Using Hoppy's conversion of 70 lux/umol for LEDs I converted the lux readings to PAR and made a few charts:

































I am a little disappointed that I am only getting 60umol with this setup. I have another of the 5W LEDs. It looks like I am getting about 20umol per LED with these so if I can get another wired up, I might be able to bring it up to 80umol. Hopefully this will be enough to grow a nice short carpet of HC.

On another note, I visited a different LFS here in town (AquaWorkz) who carries some planted tank supplies and picked up a bag of Fluval Stratum for Shrimp because I hear it is finer grained than the one for plants. It looks pretty good, but I may wait to see if anyone else has luck with HC in this substrate. They also had the 88g Fluval CO2 setup that I want to use.


----------



## karatekid14 (Jan 16, 2011)

This is so cool


----------



## Im2Nelson4u (Feb 7, 2010)

Why don't you just do everything with an arduino unit? They have shields for everything these days. You can control stuf via timers, sensors, and relays.

This guy makes shields for controlling his marine tank 

http://www.practicalmaker.com/projects/arduarium-controller

I currently use an arduino along with a few simple components to dim my lights from 10% to 100% using a 10 turn potentialmeter. I plan on using a DS1307 to dim the lights on a timer to create a dawn to dusk effect


----------



## Robotguy (Jan 24, 2010)

Im2Nelson4u said:


> Why don't you just do everything with an arduino unit?


Arduino's are fine, but I don't happen to have one. I do have a dozen ATMega128's laying around. Also, I do embedded electronics for a living and as a hobby, so if I am going to DIY I might as well build the electronics from scratch. I am mining the germanium right now.* Well maybe not, but I have a garage full of surplus electronics that I want to put to as much use as possible.**

I actually started the electronics yesterday. I am using an ATMega128 on a breakout board from Sparkfun, a WiFly 802.11 module (yes, my nano tank will have a web page) and possibly a 128x128 OLED display. 

I finished up the power supply board tonight. I needed at least 3.2V for one set of LED's, 13.3V for the other set, 3.3V for the digital circuitry and WiFi, 5V for the LED cooling fan and 12V for the pump. I ended up with 20V for all of the LEDs (the switch mode driver will have no problem with the extra voltage). I put in a 12V switcher with an enable line for the pump so I can turn it on and off easily. I then added a 5V switcher for the fan and a 3.3V linear off of the 5V for the digital circuitry.

Hopefully I can wire up the processor tomorrow night and have the LEDs dimming by the weekend (The drivers have an enable pin that can be used for dimming). My goal for the weekend is to install a bootloader that works over the WiFly module so I don't have to connect my computer to reprogram.

------------------------------------------

*If you wish to make an apple pie from scratch, you must first invent the universe - Carl Sagan
http://www.youtube.com/watch?v=zSgiXGELjbc

**That reminds me; anyone use PIC chips? I discovered several in the garage last night that I would like to find a good home for.


----------



## Im2Nelson4u (Feb 7, 2010)

Dude that sounds awesome please post the step by step if you can. Does your driver dim by PWM? if so is it 5v or 10v?

The damn meanwell 60p dims by 10v PWM so it was a pain in the ass trying to convert a 5v pwm from the arduino to 10v for the driver. Also are you going to add a RTC clock to it?


----------



## Robotguy (Jan 24, 2010)

Im2Nelson4u said:


> Dude that sounds awesome please post the step by step if you can. Does your driver dim by PWM? if so is it 5v or 10v?


I'll do my best to keep the updates coming. It's always a balancing act of build vs. document...

The driver boards are from DealExtreme and are rated 5W up to 18V input. The driver IC has the part number scratched off, but a few comments around the web have identified it as an AX2002 from Axelite. It has an enable input that can modulate the 330khz main oscillator from 0 to 100% duty cycle. The enable line is a logic level input, <0.8 or >2.0V. I plan to drive it with one of the 3.3V PWM outputs from the ATMega128. The biggest downside of this driver is that it requires a pretty hefty DC power supply, but if you are working with an Arduino, you probably already have some sort of DC laying around.


----------



## Robotguy (Jan 24, 2010)

I don't know if anyone else finds this kind of thing interesting, but I put together a communication protocol for this thing. The protocol implies an underlying control model which I think is pretty nifty if I do say so myself:icon_redf
https://docs.google.com/document/d/...XxZsN4zKBCzTdgEZQ/edit?hl=en&authkey=CLmgqdMG

Summary: I/O is defined as "channels" and "events" can be setup based on timers or inputs to "trigger" outputs to go to a certain level. 

For instance event 2 can be set up to occur when the temperature (channel 3) is 76. Trigger 4 can then be kicked off by event 2 to set the heater (channel 7) to 50. Trigger 5 can also be kicked off by event 2 to set the yellow LED (channel 1) to 100.

Offset events can be linked so that event 4 occurs 9 minutes and 40 seconds after event 3 which occurs 20 seconds after event 4. Then one trigger turns the CO2 on at event 4 and another trigger will turn the CO2 off at event 3. Bam, the CO2 is now going to be turned on for 20 seconds every 10 minutes.

Does that make any sense?

Gotta run to go grab some chinese food, but look the protocol over if you like and let me know what you think, since it's likely the protocol I'll use for the peristaltic pump controller.

Oh, BTW! I bought a Clippard Mouse solenoid from Over_Stocked, so I am planning to run pressurized CO2 as described above.


----------



## mistergreen (Dec 9, 2006)

I2C?

I have my CO2 run for 2:40 then shuts off and turns on again for 2:40. I adjust the time for CO2 concentration instead of the needle valve. It's go much easier.


gotta go make some pancakes.


----------



## Robotguy (Jan 24, 2010)

mistergreen said:


> I2C?


As in Inter-Integrated Circuit? Only if I have to. I've never liked I2C, preferring SPI. I plan to use an SPI RTC, probably a DS1305 since I think I have a few samples laying around.

I also don't like Dallas One-Wire, but I have several DS18B20s laying around, so I'll probably use them to measure water and LED heatsink temp.



mistergreen said:


> I have my CO2 run for 2:40 then shuts off and turns on again for 2:40. I adjust the time for CO2 concentration instead of the needle valve. It's go much easier.


Great, so I'm not crazy. Or we both are... 

That reminds me I have a few questions.

1. Does the 20g Fluval CO2 kit have a real regulator or is it just a needle valve? If it's a needle valve and I connect the output to a solenoid, it'll go up to full pressure. BOOM! I'll probably go with the 88g kit, but wanted to keep my options open because I don't have a lot of room, especially if I want to fit 3 peristaltic pumps in there...

2. If I put the diffuser (I plan to get the new GLA diffuser, so I hope he doesn't mind the image) in the filter like so:

That look like it will work?

3. Most importantly, I am thinking of a getting a Marineland Stealth 50W heater. Can I put it in the filter area too? Will I need to keep it from touching any of my bio-stars or filter foam? Can I put it sideways? I REALLY don't want anything in the main portion of the tank; I don't even like the acrylic spraybar.


----------



## Arctangent (Feb 22, 2010)

Very cool. Similar to my plans. I've got a little embedded experience and I'm just now really getting into communications (wanting to do 802.11 too). I'll be watching this one while I'm waiting/prototyping.

How do you plan to waterproof your DS18B20?


----------



## mistergreen (Dec 9, 2006)

1. They look like a combo regulator & needle valve. the 88 come with a bubble counter which is important to have. 
2. They come with diffusers so you might not need the GLA diffuser. yeah, it should work in the filter.
3. How big is this tank? 2-3Gallons? 50W is a bit much. 10-15W should be perfect and smaller. From touching a heater while it's on, I'd say it's on around 150°F - 200°F. If plastic doesn't melt that that temperature, it should be fine.

ps. You can make your own heater too like radiant floor heating or a heating blanket.


----------



## Robotguy (Jan 24, 2010)

Arctangent said:


> Very cool.


Thanks!



Arctangent said:


> I'm just now really getting into communications (wanting to do 802.11 too)


I love the idea of being able to connect without wires, but I am not really impressed with the WiFly. Granted it is an older, discontinued, model but I can't seem to keep it connected to the access point. Hopefully I just need to fiddle with the settings. It basically does telnet to serial, so I plan to do some CGI scripting on a Linux box I keep running as a server for my own access, and FTP a read only page to robotguy.net for public viewing.



Arctangent said:


> How do you plan to waterproof your DS18B20?


Good question. I'm thinking maybe casting it in a bit of Clear-Lite although I did manage to waterproof an LED for my volcano by coating the wire side with a dab of silicone and shoving it in some silicone air tubing. The wires ran through the tubing and out of the tank.



mistergreen said:


> 1. They look like a combo regulator & needle valve. the 88 come with a bubble counter which is important to have.
> 2. They come with diffusers so you might not need the GLA diffuser. yeah, it should work in the filter.
> 3. How big is this tank? 2-3Gallons? 50W is a bit much. 10-15W should be perfect and smaller. From touching a heater while it's on, I'd say it's on around 150°F - 200°F. If plastic doesn't melt that that temperature, it should be fine.


Great! Thanks for the info. It's 3.5 gallons, so something like a Hydor mini would work? I love that they can run dry, just case...


----------



## Robotguy (Jan 24, 2010)

A bit of progress on the physical side. For some reason I am putting off the LED dimming setup, I'm not really sure why. My goal though is to have it done tomorrow. I am waiting for the glue to dry on my custom acrylic PCB standoffs right now.

Well here are the lights:


And mounted on the tank:




From the back:


Yes, that is a tutu behind the tank. While I'm out in the garage cutting and drilling, my wife is at the kitchen table snipping and sewing a tutu for my ballerina daughter. We're birds of a feather, hers are just a lot prettier and more frilly than mine


----------



## Arctangent (Feb 22, 2010)

I thought about using silicon of some sort too, but I'm worry about the thermal resistance being too high. I just don't know if it would be responsive enough to control a heater accurately. Hmmmmm, may look into Clear-Lite. Thanks.


----------



## Robotguy (Jan 24, 2010)

Arctangent said:


> I thought about using silicon of some sort too, but I'm worry about the thermal resistance being too high. I just don't know if it would be responsive enough to control a heater accurately. Hmmmmm, may look into Clear-Lite. Thanks.


I plan to leave most of the body of the device bare and just cover the leads with silicone in order to get a quicker response.

Actually, you know what works really well? A layer of Liquid Electrical Tape covered by a layer of GOOD electrical tape the self amalgamating type. The good stuff is expensive, but once you try it, vinyl electrical tape seems really cheesy. We use this method at work to splice cables that are rated for full ocean depth!



I finally got some PWM dimming going on. For some reason I had to force myself to get past this part, and I kept finding myself Yak Shaving. But now I have the PCB mounted in the tank, all three LED channels wired up on the PCB, and one channel with a completed driver and programming. The other two will be a snap.

As for the driver, I have found that a feedback resistance of 0.33 Ohms (three 1 Ohm resistors in parallel) will give me 750mA of drive current, so that's what I will get at full brightness. Here's the PCB (Man, this looks ugly magnified this much. I really need to clean the flux. :icon_redf ):


Pulling pin 2 above 2.0 volts enables the driver, below 0.8V will turn it off. Just keep it below VCC, but since max VCC is 23V, that shouldn't be too hard. I wired this to one of the output compare pins (3.3v) on my microcontroller. This allows me to do PWM in hardware and take the burden off of the processor. 

Here's a gratuitous shot of the back of my PCB:


I built some acrylic standoffs to mount the PCBs in the rear of the tank without having to drill any holes. 


I connected the standoffs loosely to the PCBs, put a dab of Weld-On 16 on each of them, then mounted the PCBs into the electronics section of the tank:


The adhesive doesn't take too long to dry so I cleaned up a little, ate dinner, then dragged the whole thing into the living room to do a little programming. In this shot you can see the Wifly that I am using to communicate with the board: 


And, final result:
http://www.youtube.com/watch?v=TZ4AfE_G17Y

It actually works a little better than that, but it's hard to tell because of the auto-iris on the video camera. Not a whole lot better though since the PWM is linear, the light output is somewhat logarithmic, and our eyes respond according to a power law. I may grab the light meter at some point and graph lumens/PAR versus PWM duty cycle. 

Here's the meat of the code if anyone is interested:

```
OCR1AL=i; //set the PWM register
		if(i%10==0){ //print an update at multiples of 10
			printf_P(PSTR("Setting PWM to "));
			printf("%u\n",i);
		}
		i+=dir;
		if(i==255) dir=-1; //we hit the top, start counting down
		if(i==0) dir=1; //we hit the bottom, start counting up
		_delay_ms(20);
```
I am getting close to being able to fill this sucker up. Well, if I decide to fill it up. I am considering a dry-start HC carpet. I'm not sure if I have enough patience for that, though. Maybe I can do a context switch and work on the peristaltic pump for a while. Or my latest idea; The Marimo Factory, a circular nano with enough current to keep the little algae balls racing each other in circles all day long. I picked up a Marimo ball today and am quite enchanted with it.


----------



## JACimages (Jan 4, 2011)

this is so nerdy it hurts my brain


----------



## Arctangent (Feb 22, 2010)

Lol @ toccata...it's alive. You get 'cool nerd' points for showing duty cycle on your oscilloscope!



Robotguy said:


> I wired this to one of the output compare pins (3.3v) on my microcontroller. This allows me to do PWM in hardware and take the burden off of the processor.


 Can you elaborate on this? The processor is not timing the PWM?

The code you wrote was just an experimental fade up/down right? How do you plan on controling the value in practice? I was just gonna read/write a ref voltage across a pot.

Also, are you just using the three LEDs? What kind are they? Is that going to be enough to grow anything?

This is so cool, I can't wait to get started on mine. Just gotta wait for parts and free time...maybe spring break.


----------



## Robotguy (Jan 24, 2010)

Arctangent said:


> The code you wrote was just an experimental fade up/down right? How do you plan on controling the value in practice? I was just gonna read/write a ref voltage across a pot.


Yes, that was just a simple demo. I will eventually run the LEDs, and everything else, from timers and serial commands using the protocol mentioned in one of my previous posts.




Arctangent said:


> Can you elaborate on this? The processor is not timing the PWM?


Well, the processor is timing the PWM, but since it's done in hardware the firmware doesn't have to take care of every cycle. I'll describe a bit of PWM theory too, in case anyone's interested.

WARNING, SERIOUS GEEK DETAILS TO FOLLOW!!!!!

There is a timer (TIMER1) inside the chip that constantly counts from 0 to 255 then rolls over and starts again. Every time it rolls overs, it sets the output compare pin to a logic 1 (3.3v). Then when the timer value matches the value in OCR1A (Output Compare Register 1A), it sets the pin low (0v). So to set the LED to a certain dim level, say 50%, I set OCR1A to 128 (256*50%=128. 0-128 is on, 129-255 is off). That's it. No more code required, no interrupts. The firmware can go off and do anything else it wants and the hardware timer handles the set and reset 120 times a second (or a lot faster. I have the timer running at 1/256th speed because I don't want to interfere with the driver switching frequency which is 330kHz). Then later when a command comes in to set the dim level to 75%, I just set OCR1A to (256*75%=192. 0-192 is on, 193-255 is off) and then return to whatever I was doing before. Since the timer counts higher before turning the LED off, it is on for a larger percentage of the time and appears brighter. The microcontroller I am using has 3 output compare registers that run from TIMER1, so I can use OCR1A, OCR1B and OCR1C to drive my three LED channels.

If the chip didn't have hardware PWM, I could do a loop that looks something like this:


```
if(count==0) then set output high;
if(count==DimLevel) then set output low;
increment count;
if(count==Max) then count=0;
```
But if I wanted the LED to have a PWM period of say 100hz to reduce flicker and I wanted 100 different dim levels, the processor would have to stop whatever it was doing and run that little snippet of code 100*100=10000 times every second.

Microcontrollers with hardware PWM are nice.roud:


----------



## Robotguy (Jan 24, 2010)

Small update, no pics.

All three LED channels are working and mapped to output channels 1,2 and 3.

```
SO,1,100                                                                        
Got command SO,1,100
Setting channel 1(led1) to 100
```
The led_fan is now controllable through output channel 4.

```
SO,4,100                                                                        
Got command SO,4,100
Setting channel 4(fan) to 100
```
And last, but certainly not least, after an entire day of troubleshooting the battery-backed RTC is finally working.

```
RTC,GET,1                                                                       
Got command RTC,GET,1
Time is 23:57:50 on Sunday
```
Next I need to add pump and CO2 control, tank and LED heatsink temp input, then start coding the real control protocol.


----------



## Budget aquarist (Feb 1, 2011)

OH, now this is AWESOME! I WANT ONE!


----------



## VaultBoy (Nov 11, 2010)

WOW... just WOW, you make me feel inadequate... i just recieved my first ever arduino in the mail today and plan on automating/computerizing my 29g RCS / Endlers tank.

Cant wait to see more of this project.


----------



## Robotguy (Jan 24, 2010)

Budget aquarist said:


> OH, now this is AWESOME! I WANT ONE!


Thanks.


VaultBoy said:


> WOW... just WOW, you make me feel inadequate... i just recieved my first ever arduino in the mail today and plan on automating/computerizing my 29g RCS / Endlers tank.


No need to feel inadequate. Everyone starts somewhere. The only reason I can pull this off is that I am an old fart who has been playing with microcontrollers for almost 20 years. Arduinos are great way to get started. I look forward to seeing your project.

Another small update:

The RTC is now driving the triggers. I can set TIME and OFFSET triggers and they are stored to EEPROM so they don't get lost when I power down..

TIME triggers will set an output to a specific level at a predetermined time of day

OFFSET triggers will set an output to a specific level at a predetermined time _after_ another trigger goes off

I have a demo setup running that lights the leds 1 and 3 in turn for 10 seconds. It gives me the following output (I turned the verbosity up to see what's going on. It normally isn't this gregarious):

```
Running trigger 1
Setting channel 1(led1) to 100
Trigger 1 has kicked off trigger 2
Set trigger_counter[2] to 10
Trigger 1 has kicked off trigger 3
Set trigger_counter[3] to 10
ISR - Trigger 1 fired!
Running trigger 4
Setting channel 3(led3) to 0
ISR - Trigger 4 fired!
Running trigger 2
Setting channel 1(led1) to 0
ISR - Trigger 2 fired!
Running trigger 3
Setting channel 3(led3) to 100
Trigger 3 has kicked off trigger 1
Set trigger_counter[1] to 10
Trigger 3 has kicked off trigger 4
Set trigger_counter[4] to 11
ISR - Trigger 3 fired!
```
So trigger 1 fires at startup and turns on led1. Ten seconds later triggers 2 and 3 go off which turn off led1 and turn on led3 respectively. ten seconds after that triggers 1 and 4 go off which turn on led 1 and turn off led3. Then the whole cycle starts over.

I can also set up a TIME trigger to go off at a specific time on multiple days of the week. For instance if I want to dose micros on tuesdays and thursdays at 7am for 12 seconds I can set trigger 5 to go off tuesdays and thursdays at 7am and turn on the dosing pump. Then I set trigger 6 to go off 12 seconds after trigger 5 and turn off the dosing pump.


----------



## blink (Feb 22, 2012)

What ever happened with this project?


----------



## Robotguy (Jan 24, 2010)

I actually ended up using the electronics for wardian case I built, mostly because I needed a light controller:


Ward14 by Rbotguy, on Flickr


----------



## Maechael (Sep 9, 2012)

You need to keep updating this, it appears to have been dormant for quite a bit.

Such interesting information, Glad I found this thread.


----------



## blink (Feb 22, 2012)

That is pretty cool, I'd love to see the finished aquarium when it's done.


----------

