Today I present you the making of a game I made for the school year-end party for my son. In France we call these festivals "kermesses", I don't know if they exist in other countries and what they are called...
In these parties there are often the same games, that's what I'd call classic games, and this year I decided to make a more modern version of one of these classic games: the "Chemin electrique" or "Main chaude".
The goal of the game is very simple, there is a wire where an electric current passes, you then have a "joystick" composed of a metal circle at its end which passes around the electric wire and the goal of the game is to traverse the wire from one end to the other without touching it otherwise a warning light and/or sound goes off and you have lost.
Traditionally there isn't really any electronics to create this game, a simple 12V battery with a light bulb and some electric wire is enough but I had some cool ideas to make the game more modern.
So let's see what I added as functionality!
Step 1: Features
As I just said this game simply turns on a light when the player inadvertently touches the wire with the "joystick", it also happens quite often that the game produces a sound during contact.
In my version of the game there will be a total of 6 blocks of 4 LEDs (green-yellow-yellow-red) that will light up simultaneously, a buzzer that will produce a sound and also a vibrator integrated in the controller that will activate when there is contact between the electric wire and the "joystick".
The LEDs will light gradually from green to red depending on how long the contact between the wire and the controller lasts.
I also added a selection of the difficulty level (easy-normal-difficult) as well as the ability to enable/disable the vibrator and sound. The sound volume will also be adjustable with a potentiometer.
The choice of difficulty is in fact simply a more or less long delay between the moment when there is a contact between the wire and the joystick and the moment when the game starts to light up/ring/vibrate. I set predefined times by programming, for example in easy mode the game waits 1 second before triggering warnings, while in difficult mode the warnings will be triggered immediately.
I designed the game so that it is easy to dismantle, reliable and above all that it does not present any danger for the children who will use it. Indeed since the electric wire is crossed by a current and that it is stripped I had to make sure that it does not present any danger for the users of the game.
Step 2: Disclaimer and Further Informations
The game will be powered by 4 batteries of 1.5V, a total voltage of 6V, I also limit the current that crosses the wire to only a few microampere. We are therefore in the field of very low safety voltage (SELV) with an extremely low current value accessible to the user.
But attention I specify well that no value of electric current is harmless, a weak current can in certain cases be dangerous for the person who is electrified. I did a lot of research on this during the creation of this project, and even though there is no scientific consensus on the limit value before which current has no impact on the human body the current of some microampere which crosses the electric cable has very little chance to hurt a person.
But attention I will not be able to be held responsible in the event of accident ! Care must always be taken when handling live electrical conductors, even at very low current values. I strongly advise you to inform yourself as much as possible about the risks of electricity and the good precautions to take!
Further informations :
This project works very well and has all the features I wanted but it has some flaws. When I create an electronic project I try that everything is as optimized as possible in terms of cost, number of components, space, and especially that the operation of the whole is as "logical" as possible.
While I was doing this project and after finishing it I think there are some choices I made that are not the best but I was pressed by time, I only had 2 weeks to do everything from scratch (design, programming, ordering components, creating the structure, and especially assembling all the elements).
I will indicate as I go through the manufacturing steps what I think could be optimized if I had to create this game again. But I repeat the project is quite functional like that, but I am perfectionist...
I also regret not having taken more photos of the different stages of the project, but I preferred to devote myself as much as possible to the project in order to be able to finish it on time.
I'm happy with this project because it was a great success at my son's school party, so let's see what's in the belly of the beast;)
Step 3: Obligations
- Must be battery powered (for safety and mobility)
- The game must be safe (it will be used by children from 2 to 10 years old)
- Settings must be available (choice of sound/vibrator activation, and choice of difficulty)
- The settings must be simple to understand and easily accessible (it must be assumed that the person who will take care of the game during the party knows nothing in electronics/technical)
- The sound must be loud enough (the game will be used outside in a rather noisy environment).
- The system must be removable to the maximum for storage and easily replaceable physical parts (joystick, electric wire...)
- Must be attractive to children (that's the main goal they play for... :))
Step 4: Components (BOM)
For the case :
- wood plank
- some tools to drill and cut....
For the "joystick" :
- 1 vibrator
- cable jack 3.5 (stereo)
- jack connector 3.5 (stereo)
- electric wire 2.5mm²
- a small PVC tube
Electronic components :
- 2 x 2N2222A
- Zener diode 2.7V
- 12 blue LED
- 6 green LED
- 6 red LED
- 12 yellow LED
- 5 resistors 10K
- 2 resistors 4.7K
- 1 resistor 470 ohm
- 6 resistors 2.2K
- 6 resistors 510 ohm
- 18 resistors 180 ohm
- 1 potentiometer 1K
- 1 ON-OFF switch
- 2 ON-OFF-ON switch
- 1 buzzer
- 1 DC boost converter
- electric wire 2.5mm²
- 2 banana connectors male
- 2 banana connectors female
- jack connector 3.5 (stereo)
- holder for 4 LR6 batteries
- some PCB prototyping boards
Electronic Tools :
- A programmer to inject the code into a Microchip 16F628A and 12F675 (e.g. PICkit 2) -
I advise you to use Microchip MPLAB IDE (freeware) if you want to modify the code but you will also need the CCS Compiler (shareware). You can also use another compiler but you will need many changes in the program.
But I will provide you . HEX files so that you can inject them directly into microcontrollers.
Step 5: Function Analysis
Microcontroller 16F628A (Func1) :
It is the "brain" of the whole system, it is this component which detects the position of the settings switches, which detects if there is contact between the "joystick" and the electric wire, and which triggers the warnings (light, sound and vibrator). I chose this component because I have a fairly large stock and because I'm used to programming with it, and since I didn't have much time to do this project I preferred to take some material that I know well.
Power interface ULN2003A (Func2) :
This component serves as a power interface between the 16F628A and the circuits which consumes more energy than the microcontroller can provide (LED, buzzer, vibrator).
Buzzer control (Func3) :
The PIC 16F628A cannot provide enough current to power the buzzer, especially since the buzzer must be powered through a boost converter in order to increase its sound power.
Indeed since the assembly is supplied in 6V and that the buzzer requires 12V to function at the maximum I use a converter to obtain the good voltage.
So I use a transistor as a switch (commutation mode) to control the buzzer power supply. The component I chose is a classic 2N2222A which is very suitable for this use.
Here are the buzzer features: 12V 25mA, this means that it needs a theoretical power of P=UI=12 x 25mA=0.3W
So there's a power requirement of 0.3W out of the DC boost converter, the DC boost module has an efficiency of 95% so there is about 5% loss. Therefore, a minimum power of 0.3W + 5% = 0.315W is required at the converter input.
We can now deduce the current Ic which will cross the transistor Q1:
P = U * Ic
Ic = P / U
Ic = P / Vcc-Vcesat
Ic = 0,315 / 6-0,3
Ic = 52mA
We now calculate the base resistor allowing the transistor to be well saturated :
Ibsatmin = Ic / Betamin
Ibsatmin = 52mA / 100
Ibsatmin = 0.5mA
Ibsat = K x Ibsatmin (I choose a sur-saturation coefficient K=2)
Ibsat = 2 x Ibsatmin
Ibsat = 1mA
R12 = Ur12 / Ibsat
R12 = Vcc - Vbe
R12 = (6 - 0.6) / 1mA
R12 = 5.4K
Normalized value (E12) for R12=4.7K
Vibrator control (Func4) :
As for the buzzer, the 16F628A cannot supply enough current to the vibrator which requires a current of 70mA, moreover it must be supplied to the maximum with a voltage of 3V.
So I chose to use a zener diode coupled with a transistor to make a 2.7V voltage regulator for the vibrator. The operation of the zener-transistor association is simple, the zener fixes the 2.7V voltage on the base of the transistor and the transistor "copies" this voltage and supplies the power.
The current which will cross the transistor Q2 is thus equal to Ic = 70mA
We now calculate the base resistance allowing the transistor to be well saturated :
Ibsatmin = Ic/Betamin
Ibsatmin = 70mA / 100
Ibsatmin = 0,7mA
Ibsat = K x Ibsatmin (I choose a sur-saturation coefficient K=2)
Ibsat = 2 x Ibsatmin
Ibsat = 1,4mA
The minimum current in the zener diode must be at least Iz = 1mA for its operation, so we can deduce the current passing through the resistor R13 :
Ir13 = Ibsat + Iz
Ir13 = 1,4mA + 1mA
Ir13 = 2,4mA
To ensure that the current of the zener diode Iz is always in the correct operating range, a safety margin is taken with an : Ir13_fixed = 5mA (completely arbitrary choice of value)
Now let's calculate the value of R13 :
R13 = U13 / Ir13_fixed
R13 = VCC-Vz / Ir13_fixed
R13 = 6-2,7 / 5mA
R13 = 660 ohm
Normalized value (E12) for R13=470 ohm
I could have chosen 560 ohm in the E12 series but I didn't have this value so I took the previous value...
Can be optimized
When I made the design of the project I did not think about the Vbe of the transistor so instead of having 2.7V to power the vibrator I only have 2.7V-0.6V= 2.1V. I should have taken a 3.3V zener for example, the vibrator would have been a little more powerful even if the result is quite satisfactory, I do not exploit all the power of the vibrator...
Warning LEDs (Func5) :
The LEDs are positioned vertically as if they formed a gauge:
When a contact is detected between the "joystick" and the electric wire, they gradually light up from green to red.
The LEDs are connected to the VCC in groups according to their colour :
- All the anode of the green LEDs are connected together
- All the anode of the yellow1 LEDs are connected together
- All the anode of the yellow2 LEDs are connected together
- All the anode of the red LEDs are connected together
The microcontroller then activates them by grounding their cathode via the ULN2003A.
On the schematic there is only one LED of each color with a symbol "X6" next to it because I use a free version of Cadence Capture and I am limited by a maximum number of components per diagram so I could not make all the LEDS appear...
Buzzer sound level managment (Func6) :
It is simply a potentiometer in series with the buzzer which makes it possible to adjust the volume of the sound.
"Decoration" LEDs (Func7 - Schematic/Page 2) :
The purpose of these LEDs is to create a chase for the decoration of the game. They light up from left to right. There are a total of 12 blue LEDs : 6 at the beginning of the course representing the start line and 6 at the end of the course representing the finish line
I chose to do a display multiplexing for these LEDs because it would have required a lot more pins to order them (6 pin with mutliplexing, 12 pin without multiplexing).
Moreover it is indicated in their datasheet that the Vf is 4V therefore I could not put 2 LEDs in series (VCC is 6V), and I could not either put in parallel because they THEORIQUELY need 20 mA and that the microcontroller can supply only 25 mA max per pin, therefore 40mA would have been impossible.
To summarize I could not make a association of LED (put in series or parallel) and I did not have enough pin on the microcontroller to drive them anyway... So I chose to use another microcontroller (12F675) of 8 pins in order to be able to drive them.
Thanks to this microcontroller I control the activation of the LEDs by setting a high logic level (VCC) on their anodes and I use the PIC 16F628A and ULN2003A to perform the multiplexing.
Can be optimized :
I realized while performing the tests on a breadboard that for the same current I=20mA the LEDs had a great difference in brightness according to their colors.
For example with 20mA the blue LEDs were much brighter than the green ones. I didn't find it aesthetic that some LEDs were much brighter than others, so I varied the resistance in series with the blue LEDs until I got the same luminous power as the green LEDs powered with a current of 20mA.
And I realized that the blue LEDs had the same brightness as the green LEDs with a current of only 1mA! Which means that if I had known that before I could have chosen to put the blue LEDs in series (in groups of 2). And I only needed 3 more pins on the 16F675A (which are available), so I didn't need to add another microcontroller dedicated to managing these LEDs.
But at this time of the design I did not know it, there is sometimes a not negligible difference between the characteristics of the technical documentations and the real characteristics of the components...
Limiting the current (Func0) :
I hadn't planned this part at all at the time of the design I added it only at the very end of the project, when everything was already finished.
At the beginning I had simply connected the VCC directly to the electric wire with simply a pull-down resistor in order to put the input of the microcontroller which detects the contact to the ground.
But as I said before I did a lot of research to find out if the current flowing through the electric wire could be dangerous if it came to have contact between the wire and a human body.
I did not find a precise answer on this subject so I preferred to add a resistance between the VCC and the electric wire in order to reduce the current crossing the wire as much as possible.
So I wanted to put a high value resistor in order to reduce the current to the lowest possible value but as I had already finished the project and therefore all welded and wired the different cards I could no longer remove the pulldown resistor of 10Kohm. I therefore had to choose a resistance value in order to obtain 2/3 of VCC on the BR0 pin (pin 6 of 16F628A) so that the microcontroller detects although it is a high logic level when there is contact between the joystick and the electric wire. If I had added too much resistance I would have had the risk that the microcontroller would not have detected the change between the low logic state and the high logic state.
So I chose to add a resistance of 4.7K in order to obtain a voltage of about 4V on the pin when there is contact between the joystick and the electric wire. If one adds to this the resistance of the human skin in case of contact of the electric wire with the hand for example the current flowing through the body would be less than 1mA.
And even if a person touches the wire he will only be in contact with the positive terminal of the batteries and not between the positive and negative terminal but as I said in the disclaimer ALWAYS pay attention to what you do with the electric current.
Note : I hesitated for a long time to add this resistance as the electric current possibly accessible to the user (via the electric wire) is weak and that the assembly is supplied by battery with only 6V of voltage and that maybe it's be strictly unnecessary to limit the current from the batteries but since it's for children, I preferred to take as many precautions as possible.
Step 6: Programmation
Programs is written in C language with MPLAB IDE and the code is compiled with the CCS C Compiler.
The code is fully commented and quite simple to understand, but I will quickly explain the main functions of the 2 codes (for 16F628A and 12F675).
The first program -CheminElectrique.c- (16F628A) :
LED multiplexing management :
Function : RTCC_isr()
I use the timer0 of the microcontroller to cause an overflow every 2ms which allows to manage the multiplexing of the LEDs.
Contact detection management :
Function : void main()
This is the main loop, the program detects if there is a contact between the joystick and the electric wire and activates the LEDs/buzzer/vibrator according to the contact time.
Difficulty setting management :
Function: long GetSensitivityValue()
This function is used to check the position of the switch which allows to selects the difficulty and returns a variable representing the time to wait before activating the alarms.
Alarm setting management :
Function : int GetDeviceConfiguration()
This function is used to check the position of the switch that selects the buzzer and vibrator activation and returns a variable representing the alarms that must be active.
The second program -LedStartFinishCard.c- (12F675) :
Blue LED activation management :
Function : void main()
This is the main loop of the program, it activates the LEDs one after the other from left to right (to create a chase)
See below a zip file of the MPLAB project :
Step 7: Soldering and Assembly
"Physical" part :
I started by creating the box, so I cut wooden boards about 5mm thick for the top and sides and chose a board 2 cm thick to make the bottom to have more weight and that the game does not move.
I assembled the boards between being with wood glue, I didn't put any screws or nails and it's really solid!
In order to make the game more attractive than a simple painted box I asked my wife to create a decor for the top of the box (because I really suck at graphic design...). I asked him to make a winding road (to have a relation with the wire...) With cans/panel on the edges of the curves so that I can incorporate my warning LEDs. The blue LEDs of the decorations will be like the start and finish lines.
She created a "Route 66" style scenery, with a road that crosses a kind of desert, and after several impressions to find the good location of the LEDs we were rather happy with the result!
Then I drilled holes for all the connectors, switches and of course the LEDs.
The electric wire is twisted to create zig-zags to increase the difficulty of the game, and each end is screwed into a male banana connector. The connectors will then be connected to the female banana connectors that are attached to the housing cover.
Electronic part :
I have broken down the electronic part into several small prototype cards.
- a card for 16F628A
- a card for 12F675
- 6 warning LED cards
- 4 cards for decorative LEDs (start line and finish line)
I fixed all these cards under the lid of the box, and I put the battery holder in the lower part of the box with the buzzer and the DC boost module.
All the electronic elements are connected by wrapping wires, I have grouped them together as much as possible according to their direction and I have twisted them together and fixed them with hot glue so that they are as "clean" as possible and especially that there are no false contacts or wires that disconnect. It really took me a lot of time to cut/strippe/weld/position wires correctly!
"Joystick" part :
For the joystick I took a small piece of PVC tube (1.5cm diameter and a length of 25cm).
And then I soldered the female jack connector like that :
- a terminal connected to the wire at the end of the joystick (ContactWire on schematic)
- a terminal connected to the positive terminal of the vibrator (2A on J1A connector on schematic)
- a terminal connected to the negative terminal of the vibrator (1A on J1A connector on schematic)
I then integrated the wire, the vibrator, and the jack connector inside the tube and fixed the jack with hot glue to make sure that nothing moves when connecting the jack cable between the joystick and the other part of the system.
Step 8: Video
Step 9: Conclusion
Now the project is over, it was really cool to do this project even though I regret having very little time to do it. It allowed me to take up a new challenge;)
I hope that this game will work for many years and that it will amuse many children who will celebrate the end of their school year!
I provide an archive file that contains all the documents I used/created for the project.
I don't know if my writing style will be correct because I'm partly using an automatic translator in order to go faster and since I'm not English speaking natively I think some sentences will probably be weird for people writing English perfectly.
If you have any questions or comments about this project, please let me know!