Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Led cyclic dimmer/controller circuit?

Status
Not open for further replies.

yel-low

New Member
First of all I would like to say thank you for anyone here that may be able to shed some light on my project. I am very thankful for finding this forum. I have worked on several projects involving controlling and dimming led arrays.

My newest project requires an array of LEDs to be dimmed over a period of 29-30 days. What I have put together so far was a photocell light dependent switch that would either turn on or off my LED circuit depending on a presettable light intensity. In addition to this circuit it has a built in constant dimming function. Essentially if the ambient light source was low enough my dimmable LED circuit would be activated and remains on until the ambient was above a certain threshold. It is basically a light/dark switch.

What I would like to do now is to have a circuit that would integrate the same photocell light switch with a dimmer or controller that would increase the brightness of my LED circuit over a cycle of 29-30 days, with max intensity occurring half way through the cycle.

I have read over some potential designs online and most point to a "Schmitt Trigger'? I am not familiar at all with this circuit design and am hoping someone here has some idea on how to proceed with my design. The basis of the circuit would be to copy the lunar cycle, going through the phases of the moon. The integration of the photocell circuit is not essential but I would like to have zero LED intensity while there is ambient light present. Does anyone know of a controller circuit that would allow me to run through this cycle?

The product I am trying to replicate is located at the following link.



**broken link removed**
 
yel-low said:
Ok...... I guess I over estimated the scope of this forum. :roll:

Not at all. You haven't stated what your abilities are though.

If you had the ability to do what most here would suggest, I doubt you would need to ask the question.

If it was for myself, I would use something like a PIC or AVR and build a small 24-hour clock with a calendar. It would have a LCD display and a few buttons for programming. I would set the date and time and just let it run and control the "moonlight" as appropriate. I would do the dimming or moonlight simulaion using PWM. Not owning a fish-tank I don't know if the UV lamp over the top is to serve any purpose other than looking pretty. If it is to simulate the UV which would normally be there in daylight, I would put a Triac or relay output on my clock and turn the UV Lamp on as the Moon descended over the horizon. The calendar would know what day of the month it was and just set the "moonlight" accordingly. Nothing hard in that at all.

Why ? Because no matter what you do with a LDR or photo-transistor it will be subject to interference. If you put the photocell inside it will get fooled whenever anyone turns on a light and even if you run the wire through the house and place it outside, you've got to find a location that won't be affected by ambient conditions.

Now, do you need the people here to design the circuit for you, write the code, or both ?
 
A Schmitt trigger is a strategy to filter out switching noise on digital inputs, it might prevent flipping on and off rapidly at the threshhold where light should turn off.

For these long periods, a microcontroller is your only realistic option. The PWM output available on most microcontrollers can be used to control the light level.
 
Oh wow, this is the kind of information I was looking for. Thank you very much Bart. I will investigate your suggested options. I am sorry if my last post sounded a bit offensive I just did not know what type or knowledge the people that frequent this board had. I have search and seeked out help all over similar Led and circuit design boards to no avail. It is very frustrating to not have any help or not have anyone have a clue what you’re trying to do or how to proceed. I am somewhat limited in my circuit design/programming skills and any help designing an effective cost efficient circuit would be greatly appreciated. I am sure I will have more specific questions as I near the process of building the actual circuit. Ozong thank you for clarifying Schmit Trigger applications and your suggestion on the PWM as well.
 
Ok, I have done much reading on both AVR's and PWM. I now understand how the intensity control of the LEDs can be handled by the chip's PWM and the AVR microcontroller. What I do not know is how to develope a calender with specific intensity controls for each day. I am assuming this is all going to be done when programming the controller? The AVR determines the intensity per day, the PWM chip outputs the intensity to the LED circuit? Will I need to incorporate any D/A converters to take the ouput from the PWM chip to feed my analog input to my LED circuit? I am wondering if I am getting over my head in attempting to put something together like this? For anyone that has experience with these components, can you point me to some resources that would give me a good start or can anyone here walk me through the process?
 
Hi yel-low,

Now that you are starting to think about your project, we can move on to the next step. This is where you need to make a decision as to how involved you want to get. Would you like to learn something about micro-controllers or do you just want to build your moonlight simulator ? Going from your last message, it seems as though you wouldn't mind learning a bit, so I will assume this is the path you are prepared to take.

At this point you need to decide how deep do you want to go. If you want to keep it all pretty superficial you could look into things like the Basic Stamp modules and the like. There are a few of these things available using different microcontroller architechtures. Some people think that these can form a introduction to electronics and microcontrollers, whereas others think they lead to brain-dead people who think they are learning stuff. I'll be upfront here and tell you that I would be in the later category.

If you can solder or are prepared to learn how to solder, then there is nothing like jumping in at the deep end. You'll either learn to swim or you will sink real quick :)

Then it comes down to selecting a way to jump in and which side of the pool you will jump from. One way would be on the side of the Atmel AVR and anotehr would be the PIC from Microchip. Both are fine microcontroller families with a wide selection of parts which can do different things. I have done quite a few commercial products in the past with PICs and am currently evaluating the AVR for use in my current project.

If you decide to follow this path you are going to need a way to program your microcontroller and develop the code. The lowest cost path would see you simply buy or build a device programmer and there seem to be quite a few hobby designs for both familes that you can find on the net and build for under US$40- which have programming software freely available. A quick search on Google will help you locate some of these.

This methodology will require what I term a "code-test-crash-burn" method of software development, which isn't really optimal, but it does work. Basically what you will end up doing is writing the program which gets burnt into the micro, compile it, program the device, then run it and see what it does. When things go wrong you will need to work out where in your program the problem is and this can be the hard part. To do this, you will usually use tricks like flash a LED at certain parts of the program, or flash the LED if the program starts to go down a certain branch. That sort of thing. Debugging programs this way can be a challenge in itself and sometimes you will need to devise creative ways of working out what your program is doing inside the micro. It can be frustrating, but it can also be fun.

Another method is to use an in-circuit emulator ( ICE ) which can be quite costly by comparison, yet it can really help in debugging and the entire development process can be a whole lot easier. Basically, an ICE is a special version of the microcontroller which is surrounded by other circuitry which mimics the microcontroller in a real-world device. You plug the ICE into the circuit instead of the microcontroller and the ICE does exactly what the micro would. Except that you can use tools to step through your program while it is executing, set break-points and use a host of other little tricks to quickly and easily determine exactly what is going on inside the micro and your program. The cost of an ICE can be anywhere from a few hundred dollars to a few thousand. Once again, there are a plethora of options available in this area and Google can get you looking in the right area, but I suggest you lurk in device specific forums for both the microcontrollers and development tools before buying any of these as they can have their own quirks and limitations which are handy to know about before you jump in.

Myself, I prefer to use ICE tools, but this isn't a hobby for me and sometimes I still need to rely on code-test-crash-burn as even ICE tools have limitations.

As a person just starting out, you should probably be looking at a simple programmer device which won't cost you much and will let you get started quickly and easily. I have just had a look at a site hosted by Nigel Goodwin who is a regular contributor here. His site is located **broken link removed** and it really does contain everything you will need.

Not only does Nigel give you the software to program your PIC devices, he steers you in some directions which will allow you to build your own programmer cheaply and easily. His site also has some very good tutorials which will teach you a little about programming and electronics. These tutorials actually contain every element you would need to build your device.

He has circuits and software to drive an LCD, scan a keypad, talk to a real-time-clock chip, use the PWM facilities of the PIC, and pretty much everything else you will need. All that would be required would be for you to work through Nigels tutorials and then put it all together at the end. In short, he has your moonlight controller in what might be termed "kit form" and it is all sitting there waiting for you.

To answer one of your questions from your previous message; I would just code the clock-calendar in software and then work out the day of the month and set the moonlight level accordingly. For the small variation of 28-29-30-31 days, I don't think the fish would notice that we jumped from day 28 to day 1, or slipped in an extra day once in a while :) You could use Nigels I2C clock-calendar chip and do the same thing. If it is day 15, then you apply the PWM required to get the desired level of illumination. On day X you simply apply the Y value of illumination. By the time you finish Nigels tutorials, you will know how to do this.

For someone who wants to get started in this area, Nigels site is a real goldmine.
 
Bart, thank you very much for your inspiring words and the time you have invested in helping me out. Most of my life I have worked with analog circuits. The whole microcontroller world is new yet very fascinating. I have always been scared off from venturing into microcontrollers in that past due to the lack of beginner type entry information (or maybe I was just not looking hard enough) needless to say I wonder how I ever lived without the knowledge. The possibilities are amazing and I do feel like I have been living in the Stone Age with my limited analog skills. Thank you very much for introducing me to Nigel’s site. What I had planned to do today is to run up to the bookstore and pick up a few of the Microcontroller cookbooks that I found while searching for information on the net. I plan to read through those in the next few days. There seems to be many good books on this area.

I have read about many of the DIY programmers and those seem like fun weekend projects. The other thing I did notice while reading was that there seems to be some use of simulators. They apparently allow you to run the whole course of the program in a virtual world and allow you to debug from there? Is this something new or has this been outdated? If this is a reliable method it would be a rather painless method of debugging. Thank you again and I hope to keep in touch so that I can update you with my progress.
 
yel-low, I don't think I would be wasting money on books at this stage, especially of the cookbook type. At the moment you probably would not know what to look for in a decent microcontroller book and I don't think there are many that represent good value for money.

Instead I suggest you surf over to the Microchip web site and find the datasheet for one of the PICs that Nigel uses. I think he is keen on the PIC16F819. Download the datasheet and have a look at it.

The datasheet is HERE
This document might be useful too.
A detailed explanation of each Instruction can be found HERE

Don't worry if you can't understand everything at this stage, it will all fall into place soon enough. To start with, just get a handle on what is in the datasheet and roughtly where it is. Have a look at the diagram which shows the internal layout of the PIC and how things are sorta wired internally. Skip over the Register File Map for now, for the moment all you need to know is that there are special memory locations in the PIC that control the chip when you put specific values into certain locations.

Read about the ports and various modules, but once again, don't get hung-up on anything. Don't try to learn it, just try to get a feel for what is inside.

Have a bit of a read of the instructions and the explanation as to what each instruction does. Dont get hung-up on trying to understand the various modes for some of the instructions, this is also something that will come soon enough. All you are trying to do at the moment is get a feel for what is inside the PIC and what the funny mnemonics are that make up the instruction set. You will soon learn all about the various modes, flags and registers, but first off you need to know roughly what each instruction is going to do.

You can find a complete development environment including editor, compiler, simulator and everything **broken link removed** It is a large download at about 38Mb, but it is free and fully functional.

I haven't used simulators so I can't really comment on them. I know some people think they are great and it probably wouldn't be a bad place for you to start out. The reason I haven't used them is that I often start a project with an idea of what I "think" I can get the micro to do. Then I just build it or a small enough sub-set of it to confirm that I can shoe-horn everything I need inside. By this stage, I've got something working and I'm past a simulator. I find that what gives me the most grief is timing critical stuff and it invariably involves things outside the chip so I can't even single-step it as the outside event has been and gone while the ICE is trying to display my breakpoint or whatever. This is where creativity and hard work comes into play, but it is a lot easier when I fluke it first time around :)

Once you have got a bit of a handle on the PIC itself, then have a look at Nigels tutorials. Look at each section and then study the source code he has posted. Work though each line of the code and you will see what it is doing. Before you know it, not only will you understand the Assembly Code, but you will also know what the registers are, how they affect the PIC and what the various flags and other special registers are.

The simulator which is built into the MPLab environment will probably help you here as it should provide a good visual of what is going on inside the PIC. By the time you work through all of Nigels tutorials, and learn the other IC's he will introduce you to, I'm sure you will be able to design build your moonlight controller in a snap.

When you get to the parts of Nigels tutorial where he uses an LCD module or another IC, locate the datasheet and have a browse of it. Just get a feel for what you think it might do then go back to the tutorial and see how Nigel controls it. Work your way inside the other chip from the PIC and the code that Nigel give you, before you know it, you will know those devices too.

If you get stuck anywhere, just yell. I am certain that there are lots of people who will help you if you are stuck and need something explained.
 
You'll use a timer to create an interrupt on the longest period you can get. So maybe you'll get an interrupt every few seconds, maybe minutes. The interrupts will increment a counter which is used to count much longer time intervals- hours, days, months, years.

There are several ways to get the moonlight intensity from the day. There are floating point routines which can do a sine/cosine, but frankly the simplest is just to use a lookup table with integers. You'd create an array of 28 constant values and index it with the day.

You can use the built-in ADC to read the photocell. It'll give you a 10-bit number for the voltage on the cell. You can write code for any type of noise filtering that seems appropriate for enabling the moon light.

You could also add soothing patterns of "clouds" periodically dimming the moonlight. All good and fun.
 
Hi yel-low,

Your question regarding Simulators prompted me to do a bit of snooping. To date, I have not used the MPLab development tools as I have use other 3rd party products. However, the manufacturer of my tools has not been keeping them up to date with the more recent releases from Microchip. As I am about to embark on a new project which will use a PIC, I have been doing a bit of homework on the newer PICS and the tools available for development. I have decided that this time I will use the Microchip ICD2 debugger rather than invest in yet another ICE tool. I am quite confident that I can do prety much whatever I will need with the ICD2 and while it is not quite an ICE it isn't that far from it.

At the moment I am also short-listing suitable micros and while there is a slight chance I may use an AVR, I think it will most likely end up being a PIC. The final decision will come down to component costs and tool availability. At the moment, the PIC is leading in both areas, which is a bit of a bugger as I have a similar project which will follow that the PIC won't be able to handle. What that means is that if I use a PIC now, I will need to redevelop a lot of the microcode for the next other project.

Anyway, one problem I have is that I can't get an ICD2 for about 2 weeks and I am wanting to start the coding process later this week. To this end, I started to look at the simulator which is in the MPLab tool-chain. It looks great and I think that it would suit you perfectly. From the quick look I had, I think I can also use it to test and debug a lot of code before my ICD2 arrives. For someone learning to come to terms with micros it would be absoutely brilliant.

You can download a quickstart guide in PDF format HERE
I suggest you download that guide and have a read.
It even has a very simple program shown which would be perfect for you to look at and learn / understand first.

With MPLab you will have everything you need to springboard yourself into the learning process and all for the grand outlay of exactly zero dollars. You will also be able to find some application notes and other tips and tricks on the Microship website. Some of these may help you learn although some are not really elementry in their concepts or techniques.

I've probably overloaded you with info at this stage, so I won't reply back to anything from here so you can digest everything above.

Good luck with your endeavours and I'm sure you will do well with it.
 
Wow, so much info so little time...

Oznog, I do agree that the easiest way would to use an intensity array indexed to individual days. I believe I would have a little more control over the LEDs and like you said I could add in some randomness to simulate cloudy nights. At this point I am not too familiar with interrupts but it does not seem like a hard concept to grasp. Likewise, I do not know much about using the "ADC" to read the photocell but hopeful in due time I will.

McGuinn, your advice is certainly a good one and probably one of the easiest to implement but with an array of 30 LEDs the initial light intensity would just be too bright. Also, the costs associated with obtaining 30 LEDs per circuit would be not be as economical at dimming 4-5 LEDs.

Bart, I can't thank you enough for showing me all the tools for grasping the microcontroller concept and implementation. At this time I am overwhelmed with information and things to do. I am hoping sometime late next week I should be able to propose some valid design plans and coding.
Thanks to all that have taken the time to help and point me in the right direction.
 
I don't know if this is relevant, or if you have already considered it. I'm sure you know the moon circles the earth in an apparent 24 hour, 50 minute "day". Are you are also planning to slip moonrise by 50 minutes per day?
Certainly this is a detail that pales in comparison to the learning curve that you face. Sounds like fun, though.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top