Simple PIC LED toy
1. Overview
One day I decided to do some small light emitting toy myself, except buying something like that. It was for my (at that time more than one year old) son. After spending few hours by searching the internet for some do it yourself (DYI) LED toy fitting my expectations without a success, I realized it was a waste of time. I found easier to develop something myself than wasting additional time by googling. So here is some of my knowledge and skills delivered into DYI cheap simple pic LED toy.
I wanted to have flexibility in changing future behavior - microcontroller based solution was a clear choice. PIC12F629 looks great to fit for purpose:
- has 8 pins (6 I/O pins) - small DIP package,
- just 1 kB flash,
- internal 4 MHz oscillator - no external oscillator circuits needed,
- operates on 2.0-5.5 V - capable to run on 3V battery (like CR2032),
- sleep capability - power saving ~ 1nA power consumption.
All enough to handle some small code with some LED lighting effects.
2. HW
2.1 Schematic
Core component of a circuit diagram is the PIC12F629 powered by a 3 V battery. For light effects there are used 4 LEDs with different color. Light effect is activated by a push button.
Figure 1: Schematic of a simple PIC LED toy
C2 should be physically as closest to IC1 as possible. C3 is important - it protects IC1 against stopping working / freezing. Push button S1 generates bounces with spikes on GP2 input. Looks like it destabilizes PIC and it freezes program execution then. I suppose that spikes generated by push button gets far over 3 V and thus destabilize internal PIC electronics. C3+R5 helps with this. This push button issue depends on a type used. S1 type that I used does producer not intended to use with microcontrollers. As GP3 is input only pin, it is safest to connect it to GND to prevent electrostatic charges destabilizing PIC (similar issue like GP2 input). C1 is not so important if battery holder does not interrupt power supply on shocks that may occur (falling, throwing). LED1-4 could be any LEDs you will find at home. It may be need to increase R1-4 value to 100 Ω based on your LED type. I had some old LEDs with high UF value.
All used passive circuits were (recycled) from home depot. I just needed to buy PIC12F629.
Scheme has so low circuits that it does not need PCB (printed circuit board). I used socket for IC1 and rest of circuits are soldered around it. Socket enables PIC removal and ICSP programming on solderless breadboard. The thing is, that you need 5 V for ICSP programming because 3 V is not enough (see datasheet). For 5 V power supply there are needed higher R1-4 values to avoid LED1-4 destruction.
Final LED toy I packaged into tic-tac box due to these reasons:
- it enables to see LEDs and also
- rest of circuitry (what should be also curiosity for children) and
- is a zero cost (plastic tic-tac box recycled).
| | |
Figure 2: Simple PIC LED toy in a tic-tac box
So total costs of a toy was in my case just cost of a PIC12F629. Very cheap one.
2.2 Safety
From safety point of view - there is no risk of electrical injury for children, because of low power supply voltage from 3 V battery source.
It is important to put a toy in a safe package - well screwed / using enough transparent tape to avoid children to get inside and eat some circuits.
3 SW
Simple PIC LED toy SW is developed in C programming language using Microchip MPlabX IDE (v4.01) and Microchip XC8 compiler (v1.44).
Actual SW version:
- runs on 4 MHz
- saves power using sleep
- has one push button
- pushing: starts new effect (and awakes PIC from sleep)
- holding pushed: keeps actual effect cycling till push button is released
- has with 4 LEDs these light effects implemented:
| 1. | | one 0,5 sec all LEDs blink (also started on battery insertion / power supply attachment) |
| 2. | | repeated all LEDs fade in & fade out |
| 3. | | repeated kitt one direction |
| 4. | | repeated kitt other direction |
| 5. | | repeated kitt (both directions) |
| 6. | | repeated snake one direction |
| 7. | | repeated snake other direction |
| 8. | | repeated snake both directions |
| 9. | | repeated growing and falling bar one direction |
| 10. | | repeated growing and falling bar other direction |
| 11. | | repeated growing and falling bar both directions |
| 12. | | repeated jumping bi-LEDs (like double level crossing lights when train is approaching & crossing) |
| 13. | | repeated all LEDs speed up and down blinking |
PIC LED toy SW source code and HEX files you can download all packed in 20171108_pic12f629_Simple_PIC_LED_toy.X.zip.
It is provided
- as is,
- free of charge,
- free to modify,
just for non-commercial purposes only.
4. Programming
For programming & development I used:
- Microchip’s PICkit™ 3 In-Circuit Debugger/Programmer
It is low-cost hardware debugger and programmer for PIC microcontrollers. It has some limitations like for example up to 3 debugging breakpoints, but it is enough for simple homemade and DYI projects. - Small solderless breadboard using slightly modified scheme on Figure 1 (R1-4 have 220 Ω, 3 V battery is replaced with 5 V stabilized power supply needed for programming):
Figure 3: Scheme of simple PIC LED toy connected to PICkit3
Figure 4: Simple PIC LED toy connected to PICkit3 on a solderless breadboard
If you do not have PICkit™ 3, you can use:
5. License, warranty, legal notice
Complete “Simple PIC LED toy” is available free of charge for non-commercial purposes.
Building a toy is on your own risk, I am not responsible for any damages and injuries caused by using any information published here.
Anything provided here is without any warranty & support.
6. Final words
In case all LEDs are permanently lighting, no matter if button is pressed, this could be caused by a low battery voltage. Try to remove and put back battery - if LEDs keep permanently lighting after battery insertion, you need to replace battery. Brown-out Detect (BOD) functionality keeps PIC in RESET if power voltage (typically) drops below 2.1 V.
If you found these information useful, please consider to:
in USD
(Article created 11.10.2017)