Converting a traffic light into a timer

tracecom

Joined Apr 16, 2010
3,944
I'd prefer to keep the incandescent lights, just to minimize the reworking of the fixtures.
I am rusty on my PICAXE programming, and am trying to learn PICs. Maybe with elec_mech's help, we can start some coding for the lighting sequences, followed by the human interface, and finally the hardware to switch the lights. We can use triacs and optoisolators to interface the AC lights to the microcontroller.

Do you plan to get into programming?
 

Thread Starter

Transitory

Joined Jan 2, 2013
64
I am rusty on my PICAXE programming, and am trying to learn PICs. Maybe with elec_mech's help, we can start some coding for the lighting sequences, followed by the human interface, and finally the hardware to switch the lights. We can use triacs and optoisolators to interface the AC lights to the microcontroller.

Do you plan to get into programming?
Insofar as I will finish this project - yes, but I won't be making it another long term hobby (I have so many as it is!). That having been said, I do understand programming from my forays with web development (PHP/MySQL and ActionScript). I feel confident in being able to learn a new code and syntax with guidance.

So we'll start with the code then obtain the hardware or should we start shopping for the project?
 

tracecom

Joined Apr 16, 2010
3,944
I think we should select the microcontroller that we are going to use as a first step. I don't know how elec_mech works, but with me, coding is an iterative process, and I don't care much for simulators. So, what I like to do is have my μC in a development board, start with a simple function, write a little code, and then try it out. Then, pick another function, add it to the code, and try it out, etc.

Once we get the code running, adding the hardware for the lights will be comparatively easy - basically an optocoupler and a triac for each of the three lights. Since you want to be able to change the light sequences on the fly, there will have to be some man/machine interface, i.e., switches and a display.

@elec_mech

My preference would be to try to do this using a PIC, if you will take the lead writing the code. I will be willing to set up a development board and do the actual programming. I can use it as a learning experience to try to transition from PICAXE to PIC. Here's a list of PICs I have on hand; would any of them do?

12F509
12F629
12F683
16F84A
16F505
16F506
16F628A
16F684
16F690
16F819
16F886
16F887

I have PBP 3 Gold and the MPLAB IDE.
 

MMcLaren

Joined Feb 14, 2010
861
So I would need:

A programmable microcontroller (the AXE-021 or the MPS430)?
A device that can input/display the time value?
A device that control the time value
What else?
Gosh, there are just so many ways you could do this. How about using a calibrated scale on a potentiometer and a push button switch to start the timing sequence? For example, the scale on the Spinning Class Strobe below could easily be changed to a full scale range of 60 or 90 minutes.



Or instead of a scale on the potentiometer how about using a Charlieplexed 20 LED bargraph display which would only require five I/O pins? In this case the display would show you how much time is left on the timer.



Of course you can always use a 4-digit 7-segment display like the one in this PIC 99 Minute Timer project;



Food for thought... Good luck on your project...

Cheerful regards, Mike
 

Attachments

Last edited:

elec_mech

Joined Nov 12, 2008
1,500
I think we should select the microcontroller that we are going to use as a first step. I don't know how elec_mech works, but with me, coding is an iterative process, and I don't care much for simulators. So, what I like to do is have my μC in a development board, start with a simple function, write a little code, and then try it out. Then, pick another function, add it to the code, and try it out, etc.
Ditto. That's how I learned and prefer to code - write a small section, test on hardware, debug, and onward. Not a simulation guy either.

Goodness, it's been a few years, but I have been wanting to get back into it programming as I have a few projects I need to continue with.

I like Mike's circuit, but he's going hardcore into multiplexing on the uC. Because I am lazy, I propose a hardware solution - an IC that communicates with the uC and controls the display.

Before we get too far ahead, I suggest we come up with a schematic. This will help us visualize what we need in terms of hardware and determine how many I/O pins we'll need on the uC. I'll start on this if that works for everyone else and you can tell me if anything needs changing. I'll definitely look to Tracecom's guidance on how to connect the uC to the AC lights.

My preference would be to try to do this using a PIC, if you will take the lead writing the code.
No problem for me. Might take a little time to clear the rust, but I'm game.

Tracecom, I have no problem with using a PIC. My only question is are you proposing we write and test the code and send to the OP or have the OP do it with our guidance? I have no problem with either. If the latter, the OP would need to either purchase PBP or use the trial version. As it does not sound like the OP will continue to program PICs, the trial version seems ideal, but it is only good for 15 days. The OP could simply write the code in text, post here, and you could test it on your set-up as another option.

I will be willing to set up a development board and do the actual programming. I can use it as a learning experience to try to transition from PICAXE to PIC.
That would be great.

I have PBP 3 Gold and the MPLAB IDE.
I'm so jealous. I bought whatever version came out just prior to PBP 3, then a few months later PBP 3 comes out. Agh. Let me track down my copy and see if I can upgrade so we're working with the same version.




Okay, so at the moment:
  • 4-Digit 7-Segment display with 1" digits, perhaps one of these: https://www.sparkfun.com/search/results?term=7-Segment+Display+-+1"+Tall&what=products - note these do not have a colon to separate the minutes from the seconds, but a dot could be used
  • 4 buttons - start/stop (single button), reset, minute, and second
  • Three AC lights
  • Interface between uC and display, perhaps a MAX7221? I've already got a schematic and code and this would work nicely with the displays linked above
  • uC - thus far, I count 4 switch inputs, 3 light outputs, and 3 lines for SPI communication if we use the MAX7221, totaling 10 I/O's - except for the 500's or 819 (weren't bunched with the others on the website), it looked like any of the PICs listed would do the job - I'll look more closely once the other hardware is defined.
I miss anything?
OP, what do you think about the displays? Would a dot work as a separator between the minutes and seconds? Would look like: MM.SS instead of MM:SS.

Tracecom, could you post a simple schematic showing how to connect a triac or other part of your choice between a uC and a 120VAC light or just a link?
 

MMcLaren

Joined Feb 14, 2010
861
what do you think about the displays? Would a dot work as a separator between the minutes and seconds? Would look like: MM.SS instead of MM:SS
You missed the displays with colon LEDs; https://www.sparkfun.com/search/results?term=7-Segment+Displa+-+4-digit+%28&what=products

They come in a variety of colors and they're bright enough to scan one segment at a time instead of using digit drivers and scanning one digit at a time, which reduces the total parts count as can be seen in the wiring diagram for that 99-Minute Timer;



Interface between uC and display, perhaps a MAX7221?
While the MAX7221 and MAX7219 are viable display driver options, they're costly and the big bulky 24 pin package may be a disadvantage. The three pin interface may seem like an advantage at first, until you realize you can't mux' push button switches off of the column driver lines so you'll actually use more I/O pins for combinations of MAX72XX display driver plus switches. Other driver options, like the MacMux interface method (below), can provide hundreds of levels of gamma corrected brightness level control compared to only sixteen levels from the MAX7219;



Using PBP may be ok for a "one off" project. Otherwise, I would recommend using the free/lite version of BoostC or even XC8 (gag, choke...) so that other people could view/modify/use the code...

Food for thought... Regards...
 
Last edited:

tracecom

Joined Apr 16, 2010
3,944
My only question is are you proposing we write and test the code and send to the OP or have the OP do it with our guidance? I have no problem with either.
I guess that's up to Transitory. I don't even mind sending him a programmed PIC.
 
Last edited:

elec_mech

Joined Nov 12, 2008
1,500
I did see those. The OP was looking for 1" displays. Those are 0.39" and I would guess the serial ones are 0.56". Of course, you bring up a good point I forgot to ask the OP: Would a smaller digit height of 0.39" or 0.56" work?

Mike, I applaud your ingenuity. You have a great project there. The design appears based on minimum parts count, minimum size, and multiple uses of the same I/O lines. I will keep it in mind when I need to really get the most bag for my buck and minimize space and parts count on a uC.

Being not much more than a novice myself, I think it is a bit much for this project. What is saved in hardware and space is made up for in programming and my thought (as well as limited experience) is to keep things simple on the programming side.

I would kindly disagree regarding the use of PBP for only one off projects, but we each have our reasons for using one language or another and for different reasons. I'm sure many here could give a number of reasons why C is better, but BASIC is easy to learn and understand, especially to a beginner. Thank you for mentioning BoostC, I don't recall coming across it before and the prices are the best I've ever see for a C compiler.
 

elec_mech

Joined Nov 12, 2008
1,500
See the attached schematic. I have used these parts before in a similar circuit.
Excellent, thank you. I will look this over so I can better understand the operation and incorporate it into the master schematic.

I didn't use a snubber circuit and don't think we will need one.
I've never controlled AC devices with a uC, so I will rely on your experience and expertise. :)

We might have to use a driver transistor to boost the current from the μC to the optocoupler.
I guess we'll see once we've selected the uC. No problem though.
 

MMcLaren

Joined Feb 14, 2010
861
Mike, I applaud your ingenuity. You have a great project there. The design appears based on minimum parts count, minimum size, and multiple uses of the same I/O lines. I will keep it in mind when I need to really get the most bag for my buck and minimize space and parts count on a uC.
I've shown bits and pieces of several different projects so I'm not really sure which project you're referring to.

Being not much more than a novice myself, I think it is a bit much for this project. What is saved in hardware and space is made up for in programming and my thought (as well as limited experience) is to keep things simple on the programming side.
Not sure what you mean by "a bit much for this project". You're not associating simple and elegant hardware design with more complex programming, are you? If anything, exploiting the hardware and producing a simpler design often reduces the complexity of the software.

I would kindly disagree regarding the use of PBP for only one off projects, but we each have our reasons for using one language or another and for different reasons. I'm sure many here could give a number of reasons why C is better, but BASIC is easy to learn and understand, especially to a beginner. Thank you for mentioning BoostC, I don't recall coming across it before and the prices are the best I've ever see for a C compiler.
In this case I simply meant that unless someone simply wants to duplicate the project by using the hex file, you're limiting the capabilities of hobbyists who might want to modify the program but can't afford to purchase PBP.

Cheerful regards...
 

elec_mech

Joined Nov 12, 2008
1,500
I've shown bits and pieces of several different projects so I'm not really sure which project you're referring to.
Sorry, I meant the PIC 99 Minute Counter.

Not sure what you mean by "a bit much for this project". You're not associating simple and elegant hardware design with more complex programming, are you? If anything, exploiting the hardware and producing a simpler design often reduces the complexity of the software.
As you've phrased it, I suppose I am. I haven't programmed in awhile and I'm likely an order of magnitude below your level, so I apologize if my thinking or observations are in left field. But from a beginner's perspective, isn't charlieplexing, gamma correction (I'll be honest - I don't know what that is), and using the same I/O pin for multiple hardware functions a bit advanced? Not saying it's overly difficult, but to understand the timing required and writing code for that functionality doesn't seem trival. Again, it's been awhile for me and I was never a hardcore programmer.

In this case I simply meant that unless someone simply wants to duplicate the project by using the hex file, you're limiting the capabilities of hobbyists who might want to modify the program but can't afford to purchase PBP.
Is C universal? I know BASIC has slightly different flavors among the compilers, but the code could be cut and pasted and minor mods made to use a different BASIC compiler. I found C to be difficult to learn upfront and unlike learning to ride a bike, it doesn't seem to stay (with me in any event). Nothing against it, as I said we each have our favorites for different reasons.

You do make some excellent points I'll keep in mind through this post. I do hope you'll continue to make suggestions and see where we can make improvements in the design. Thanks again.
 

thatoneguy

Joined Feb 19, 2009
6,359
For the timing functions you are looking for, most all of the above options will work.

TI MSP430 Launchpad: $4.30 + Display and Relays, Relay Drivers ("low level" C) Additional projects, <$5 each
PICAXE - $25 + Display/Relay/Driver, Programmed in BASIC or by Flowchart (Interpreted BASIC, but fast enough) Additional projects about $3 each
Arduino - $30 + Display/Relay/Driver, Programmed in high level C with easy to use libraries. Additional Projects $25-$80 (new board for each project)
PIC - Can do any of the above, programmed in C, BASIC, or Assembly. $60 starting, additional projects: <$1
AVR - Ditto as PIC.

The initial cost is higher due to the language and programmer needed to start. After that, only additional ICs need to be ordered, except in the case of Launchpad and Arduino, where the programmer is on board.

PICAXE is extremely easy to use, as is Arduino, they were designed for hobby designs. Launchpad is middle ground, while "Bare" PICs (or ATmel, 8051, etc) are what embedded applications are created with, steep learning curve, but huge array of options.
 

Thread Starter

Transitory

Joined Jan 2, 2013
64
OP, what do you think about the displays? Would a dot work as a separator between the minutes and seconds? Would look like: MM.SS instead of MM:SS.
Doesn't matter. As long as you can see it, that's fine. The traffic light is what matters.

I guess that's up to Transitory. I don't even mind sending him a programmed PIC.
I imagine I can handle taking the code that you create and put it on the μC, that would be something I'd need to do if I wanted to adjust the timings later anyways, right?


I did see those. The OP was looking for 1" displays. Those are 0.39" and I would guess the serial ones are 0.56". Of course, you bring up a good point I forgot to ask the OP: Would a smaller digit height of 0.39" or 0.56" work?
Sure, not a big deal.
 

tracecom

Joined Apr 16, 2010
3,944
I imagine I can handle taking the code that you create and put it on the μC, that would be something I'd need to do if I wanted to adjust the timings later anyways, right?
No, I think the plan is to make the timing adjustable via some control buttons and the display. Is that what you wanted?
 

Thread Starter

Transitory

Joined Jan 2, 2013
64
No, I think the plan is to make the timing adjustable via some control buttons and the display. Is that what you wanted?
Right, right. The timer itself will be adjusted with buttons/display.

I meant adjusting when the light goes yellow, flashing yellow, etc. - I imagine that would be programmed.
 

elec_mech

Joined Nov 12, 2008
1,500
Tracecom,

Since the OP would like to change the code in the future but doesn't plan to use microcontrollers for future projects, PICAXE seems the most economical choice, would you agree? I would be happy to do the schematics and assist with the programming to get the OP running. Afterwards, we could work together to transfer the program to PBP if you'd like so you can get some more experience with it.

Another thought is to go all out on the programming side and allow the user to change when and for how long each light comes on for. In this way the OP doesn't need to change the program to change the timing of the lights. There are certainly enough buttons and we'll have a display. This will require some thought and more code, but then the OP doesn't need to change the code.

OP,

Do you have a preference? Would you like to change the light timing via code or through the buttons and display?
 

Thread Starter

Transitory

Joined Jan 2, 2013
64
Tracecom,

Since the OP would like to change the code in the future but doesn't plan to use microcontrollers for future projects, PICAXE seems the most economical choice, would you agree? I would be happy to do the schematics and assist with the programming to get the OP running. Afterwards, we could work together to transfer the program to PBP if you'd like so you can get some more experience with it.

Another thought is to go all out on the programming side and allow the user to change when and for how long each light comes on for. In this way the OP doesn't need to change the program to change the timing of the lights. There are certainly enough buttons and we'll have a display. This will require some thought and more code, but then the OP doesn't need to change the code.

OP,

Do you have a preference? Would you like to change the light timing via code or through the buttons and display?
Through the code seems simpler to me.
 

tracecom

Joined Apr 16, 2010
3,944
elec_mech, OK, I will dig out my PICAXE stuff and see what I can get going. I am fairly sure that I can write the code to control the lights according to the sequence Transitory posted. It will take me a few days to clean the rust off my memory.

If I can get that much going, then, we can decide if the buttons and 7 segment display are needed.

Transitory, you should probably go to www.picaxe.com and download the Programming Editor, and begin familiarizing yourself with it. You will also need a programming cable; there are two versions, a serial version and a USB version. The serial version is much cheaper, but serial ports on computers are becoming harder to find, so you may want to spring for the USB version.
 
Top