Silicon ChipModel Railway Level Crossing - July 2022 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions
  5. Publisher's Letter: The importance of repair
  6. Feature: Mixed menu by Mark Nelson
  7. Feature: The Fox Report by Barry Fox
  8. Project: Net Work by Alan Winstanley
  9. Project: Single-Chip Silicon Labs FM/AM/SW Digital Radio Receiver by Charles Kosina
  10. Project: Model Railway Level Crossing by LES KERR
  11. Project: Advanced GPS Computer by Tim Blythman
  12. Feature: Make it with Micromite by Phil Boyce
  13. Feature: Max’s Cool Beans by Max the Magnificent
  14. Feature: Flowcode Graphical Programming by Martin Whitlock
  15. Back Issues: Flowcode Graphical Programming by Martin Whitlock
  16. Feature: Circuit Surgery by Ian Bell
  17. Feature: AUDIO OUT by Jake Rothman
  18. Feature: Electronic Building Blocks by Julian Edgar
  19. PCB Order Form
  20. Advertising Index

This is only a preview of the July 2022 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
Model Railway Level Crossing BY LES KERR This scale-model Railway Level Crossing has realistic moving barriers, flashing lights and a bell sound recorded from a real level crossing. It can be triggered automatically when a model train approaches. It’s controlled by a couple of low-cost PIC microcontrollers and can be built for a modest sum, assuming you have some basic model-making and electronic assembly skills. D uring the recent COVID-19 lockdown, I decided to build a model railway layout in OO gauge. As time went on, I added buildings, a tunnel, a bridge, a pond and many other items, including a level crossing. This level crossing can be triggered manually, or automatically when the train passes It includes arms that automatically lower and raise, flashing lights and a realistic bell sound (video at: siliconchip.com.au/Videos/ Level+Crossing). This article describes how you can build your own level crossing just like mine. OO scale is 4mm:1ft which works out to 1:76.2. I applied this scaling to images of signs taken from fullsized crossings. For other items, like the red flashing lights, servos, barrier, and posts, I used slightly bigger parts than the scaled-down real-life items. The bell sounds were recorded from an actual crossing. The Level Crossing project involves building two boxes with posts that sit on either side of the railway tracks where a road meets them. When the train approaches, they drop their arms to block vehicles from crossing the tracks while simultaneously flashing their lights and sounding alarm bells. 24 Once the train has passed, the lights and bells turn off, and the arms lift up again. Initially, the arms/gates opened and closed at a speed determined by the servo motor manufacturer. This speed was excessive compared with the reallife version, so I developed a circuit to move the arms in small steps, with a delay between each. The easiest way to do this was to use an inexpensive microcontroller programmed to produce the correct number of steps, with a delay between each, covering the angle that the arm needs to move through. There are four red LEDs on each post: two facing each way, and they flash alternately in pairs (with the LEDs connected back-to-back illuminated together). Due to the alternate flashing, normally you would need three wires to connect them up – one to each LED and one common to both. But the hollow post is so small that it is only possible to fit one wire up the centre; using the brass post itself as a conductor gives just two wires. The way around this is to put the pairs of LEDs to be illuminated together in series, then connect those pairs in inverse parallel. This way, if a current is applied across the set of four LEDs in one direction, two are illuminated, and if the current flow direction is reversed, the other two are illuminated. The only problem with this is that to illuminate all the LEDs you need a ‘full bridge’ type of driving arrangement that can drive one end of the LEDs high while it drives the other low, or vice versa. Luckily, this is easily achieved with a pair of microcontroller digital output pins. Circuit description Refer now to Fig.1, the Level Crossing circuit diagram. It is based mainly around two PIC12F617 8-pin, 8-bit microcontrollers. When the start switch (S1) is closed, digital input GP2 on IC1 (pin 5) is taken high. The resistor and capacitor help to debounce the switch contacts. In response, IC1 brings its GP4 digital output high (pin 3), switching on MOSFET Q1, which applies 5V to the recording/playback chip (IC3) with the bell sound recorded on it. IC3 is wired in the continuous mode by connecting pin 2 to pin 13, which results in the bell crossing sound being produced constantly from the connected 8Ω speaker. Practical Electronics | July | 2022 Level Crossing Controller for Model Trains Fig.1: circuit diagram for the Level Crossing Controller. This project uses two PIC12F617 ICs, which saves on extra components – for example, a 555 timer and some transistors that would be needed to flash the LEDs. The sound continues until Q1’s gate is brought low by microcontroller IC1, switching it and the playback module off. I was going to use a 555 timer to flash the LEDs, but the two-wire requirement meant that I would have to add extra transistors. An inexpensive microprocessor fits the needs perfectly, hence IC2. It probably would have been possible to build this function into IC1, but that would make the timing tricky as IC1 also has to generate servo pulses with accurate timing. A separate chip makes that easy. At the same time as GP4 goes high, IC1 also brings its digital output GP1 high, which indicates to IC2 to start flashing the LEDs alternately. IC2’s digital pins GP4 and GP5 are configured as outputs. Initially, GP4 is taken low and GP5 high, resulting in two of the LEDs on pole one and two on pole two glowing red. Half a second later, GP4 goes high and GP5 low, causing the LEDs that were lit to extinguish and the other LEDs to light. This sequence is repeated until the start switch opens and IC2’s pin 6 input (GP1) goes low again. Shortly after the lights and bells are triggered, IC1’s GP0 digital output produces a series of pulses that go to the servos, causing them to move the Practical Electronics | July | 2022 arms slowly down until the servo arm is horizontal. It remains down until a couple of seconds after the start switch opens (at which point the flashing lights and bells cease), resulting in the arms moving up slowly to their full upright position. Switch options The original design uses a toggle switch for S1, with the Level Crossing operated manually. The operator simply switches it on when the train approaches the crossing and switches it off after the train has passed through. However, some constructors may hanker after automatic operation. This can be achieved by gluing a strong magnet somewhere on the train floor, then positioning two reed switches at strategic points underneath the track. They must be positioned so that the magnet passes over one before the train reaches the level crossing, and the other after it has finished passing through. Ideally, the magnet should be underneath the train so that it passes as close to the tracks as possible without actually hitting them. However, with a strong enough magnet, you might get away with fitting it inside one of the carriages. Be careful not to place the magnets right next to the reed switches, as this could demagnetise the switches, making them useless. An alternative version of the firmware for IC1 (ending in B) changes the function of pin 5 on IC1 to toggle the Level Crossing on and off each time that pin transitions from a low to a high level. Therefore, wiring both reed switches across the S1 terminals will provide the required behaviour. If you have more than one set of tracks going through the level crossing (eg, trains going in both directions), you could wire more than two reed switches in parallel. However, note that odd things will happen if you have trains passing through the crossing in both directions at once. If you want to support that case properly, you will need to develop a small external circuit that handles the logic to trigger this circuit, and you’ll probably want to stick with the A firmware in that case. The logic could consist of two S/R flip-flops with their outputs wired through an OR gate, going into pin 5 of IC1. Note that the B firmware could also be used with a momentary pushbutton type switch wired across S1, to allow the operator to manually toggle it on and off if desired. 25 Fig.2: a 1:1 scale diagram of the mechanical construction details for the unit. Note that the servomotors have their mounting arms modified so that they can be mounted sideways. Fig.3: the label artwork for the various parts of the Railway Level Crossing. This is shown at actual size and can be downloaded from the July 2022 page of the PE website. Construction There are two main parts to the construction: the electronic assembly, which is pretty straightforward, and the fabrication of the boxes, poles, arms and other pieces that make up the level crossing, which generally will take longer. As it is most of the work, we’ll start with the mechanical assembly. The mechanical parts drawing (Fig.2) shows the dimensions and quantity of the parts to build the crossing. I will go through each piece and describe how I made them. Mounting post This was made from a length of hollow square brass 3/32-inch (about 2.4mm) extrusion. Mine was made by K&S metals, which most model shops stock. You have to drill a 1.5mm hole 48mm from the bottom as the exit hole for the LED power wire. Using a small round file, clean up the hole and the ends so that all burrs are removed that might cut the insulation on the wire. Backing plates There are six of these, all made from 0.5mm brass sheet, also from K&S metal. You will need two of each of 26 the rail crossing backing plates, track backing plates and stop backing plates. Using a small metal saw, cut out the required size and then use a file to round the edges and remove any burrs. Barrier You will need two; I made them from 1/16-inch (1.6mm) blank PCB scraps. You can draw up the shape on the PCB or trace the shape from the label. Drill the 7mm hole and cut the barrier from the PCB using a saw and file. LED holder I turned these up on a lathe by bolting eight square pieces of 0.5mm-thick brass together on a mandrel, each with a 3mm hole in the centre. Alternatively, buy some brass washers with a 3mm centre hole (the LED diameter) and an outside diameter of about 6mm (not critical). If the inner hole is slightly larger than 3mm, you can hold the LED in place using glue. The washers should be painted matte black. Post mount This is an optional part that adds a bit more realism. Because the base of my model railway was made of polyurethane, I had to insert a metal plate under the rails to which the crossing parts were mounted. I drilled a 6mm hole in the plate and held the post mount in place with Loctite. It’s a simple turning job to make the part out of aluminium round. Servo arm The miniature servo is supplied with a servo arm that has to be cut to size. The mechanical drawing shows the arm before and after modification – you need two, one for each barrier. The barrier is glued to this part of the assembly, as described later. LED assembly Make two LED assemblies, as shown in Fig.2. Use pliers to bend the leads so that you put limited stress on the LED connections. Cut the leads to size and solder them together. The anodes of the LEDs are marked with ‘A’ on the drawing. At this stage, don’t solder it to the post. Servos So that the servomotors can be mounted on their sides, it is necessary to remove the mounting arms. Use a hacksaw to cut them to the size shown on the drawing. Practical Electronics | July | 2022 An example of what the finished barrier and railway crossing sign looks like. Sign labels Fig.3 shows the three sign labels and the covering for the barrier. To make these, download the 1:1 scale label drawing as a PDF from the July 2022 page of the PE website and use a colour printer with 80gsm paper. Print the drawing and measure the 100mm line. Let’s say it measures 99mm. This gives a calibration factor of 100/99 = 1.01 or 101%. So if you print the file again at 101% scale, the 100mm line should measure 100mm. Mechanical parts assembly The first step is to push the black LED holders over the LEDs. Next, with the mounting hole at the rear of the post, clean a 2mm strip on the front with a centre 50.25mm from the bottom and tin that strip with solder. Place the LED assembly over the post, as shown in the drawing. Using a soldering iron, attach it to the post. Select about 100mm of thin wire with high-temperature insulation and slide it into the hollow post at the bottom until it exits out at the 1.5mm hole, 48mm up. Strip off about 2mm of insulation and solder it to the LED assembly as shown in the upper left photo. The three backing plates are then glued to the post as shown, using Loctite GO 2. Leave it for 24 hours for the glue to set. Using heatshrink tubing and masking tape, cover the LEDs and then spray the assembly with aluminiumcoloured paint. When dry, remove the heatshrink tubing and masking tape Practical Electronics | July | 2022 and attach the three labels to their respective backing plates. The final task is to connect the second power lead to the post on the two post assemblies. This is done after they are assembled on the crossing, as any solder on the post would stop it from going into its mounting hole. Again, clean and tin a 2mm section at the bottom end of the post and attach a wire to it. I will leave the design of the road across the track up to you, as the sizes will depend on your particular railroad layout. Mine consisted of timber wedges painted matte black. Electronic assembly The heart of the level crossing circuit is built on a single-sided PCB Fig.4: the overlay diagram for the Level Crossing. Note the resistors are mounted vertically. coded 09108211. It is available from the PE PCB Service and measures 48 x 43mm. The PCB overlay diagram (see Fig.4) can be used as a guide during construction. Start by fitting the PCB pins, then the IC sockets. We used IC sockets for the microprocessors and the recording ICs in case we ever wanted to reprogram or change the sound. Do take care to orient them correctly. Now add the resistors, which are mounted vertically, followed by the capacitors. Check that the 100µF capacitor is the right way round. Next, add the 2N7000 MOSFET Q1, oriented as shown. The wiring diagram (Fig.5) shows how to connect the two post assemblies, the loudspeaker, the trigger Here is an example of the completed project fitted onto a model railway track. 27 Fig.5: the wiring diagram for the project. For triggering the device, we recommend using a reed switch for S1 which is hidden under the tracks, so that it can be triggered by a magnet mounted on the locomotive. switch and the two servomotors. Rather than using a pushbutton switch as shown, we expect most constructors will use a reed switch hidden under a section of the track, with a magnet on the model locomotive to trigger it before the loco reaches the crossing. Finally, connect the positive of the 5V power pack to the +5V point on the board and the negative to 0V. Check that all the connections are correct and that there are no dry joints or solder bridges. At this stage, don’t plug in the PIC controllers (IC1 and IC2). There is no provision for programming either of the microcontrollers in-circuit, so you will either need to program them yourself using an external programmer (eg, PICkit 3 or 4) before plugging them in. You can download the HEX files from the July 2022 page of the PE website; the file ending in ‘A’ or ‘B’ is for IC1 (depending on the type of switch used) and the ‘C’ file is for IC2. Recording the bell sound The download package on our website also includes a WAV audio file of the bell sounds, which you need to transfer to IC3. This is supplied as part of a module that is capable of recording by itself (see the photo opposite). The simplest way to transfer the bell sounds from a computer to the chip is to place the module’s microphone close to your computer speakers. First, though, the module needs a power source. Connect a 5V supply to its power input terminal block. With Fig.6: this box was designed to hide the servomotors when displayed on the track. You can print this diagram on a suitable material, fold it and then paint it if you want. 28 the green terminal block on the left, make sure that the two slide switches marked FT and repeat are switched to the left-hand side. It’s also a good idea to temporarily connect the 8Ω speaker to this module so that you will be able to hear and check what you have recorded. Hold the module so that its electret microphone is about 100mm from the computer loudspeaker. Play the downloaded WAV file at the maximum reasonable volume, and after it starts, hold down the REC button until LED D1 goes out (after the maximum recording time of about 10 seconds). Slide the repeat switch to the right and momentarily press the PLAYE button. This should verify that you now have a continuous recording of the level crossing bell sound on the chip. Testing the electronic assembly Plug the 5V power pack into the mains and, using a voltmeter, check that you have 5V between pins 1 and 8 on IC1’s socket. Switch off the power supply, remove the ISD1820P IC from the recording and playback module and insert it into the Level Crossing PCB, oriented as shown in Fig.4. Do the same for the PIC microprocessors, making sure that you don’t get them mixed up. Switch the power on, close the start switch and you should see the red LEDs flashing alternately and hear the level crossing bell sound from the speaker. Half a second later, the servomotors Practical Electronics | July | 2022 A more complicated approach to recording the bell sounds I designed the circuit shown in Fig.7 to provide a more elegant way of recording the bell sounds from a computer onto the ISD1820P chip. However, while it is a better solution, the effort and expense of building this circuit are not worthwhile for a one-off recording. The speaker/ microphone method described in the text provides decent results with minimal effort. Regardless, I am presenting the circuit here for those interested. Audio from the PC’s output jack is adjusted in level using VR1, then AC-coupled to two op amps, IC2a and IC2b. These convert the single-ended computer audio into a balanced signal, ideal for feeding to the ISD1820P’s balanced microphone inputs at pins 4 and 5. The components at the top of the circuit detect when the audio playback begins on the computer and automatically triggers recording on the ISD1820P (IC4), so that you don’t have to try to press both buttons simultaneously to get the best results. 1a a pli e t e a io i al y and feeds a diode charge pump (D1 / 1μF capacitor i capacitor ic ly charges as soon as a signal comes from the computer. The other half of the dual op amp, IC1b, is connected as a comparator, pulling the GP2 digital input of The ISD1820P is often sold as a module similar to this. This version is sold by Jaycar (www.jaycar.com.au/p/XC4605). But there are a wide variety of alternatives available online that will also work. Note that they might have different arrangements for feeding in power, jumpers instead of switches and other minor variations. (Do ensure the IC is socket mounted – NOT soldered!) pi lo a oo a t e c ar e o t at 1μF capacitor e cee a o t V This also lights LED1. e it icroco troller detects that its pin 5 has gone low, it generates a pulse from its GP1 digital output (pin 6) to trigger recording mode on IC4. This has an appropriate length to recor t e ole ell o e e ce o i acti a a p l e tretc er Fig.7: a circuit I designed to record sound to the ISD1820P module directly from a computer’s audio output jack. Practical Electronics | July | 2022 29 should move slowly clockwise about 70°. On opening the switch, the servomotors should slowly move back, the flashing lights should extinguish, and the bell sound should stop. Final fitting Glue the barrier covering labels to each side of each barrier and trim any excess overhang. Mount the servomotors side-on, as shown in the photo. Apply power and close the start switch. The servomotors will move down to the barrier closed position. Slide the barrier over the modified servo arm bush as shown in the photo, and then attach the servo arm to the servomotor. Glue the barrier onto the servo arm so that it is horizontal and let it dry. Do the same for the other servomotor. Open and close the switch to check that the barriers operate, as in the video. To hide the servomotors, I made boxes out of folded card and painted them silver. Fig.6 is the cutting diagram for this box, and it is also available as a PDF download. Print the 1:1 scale drawing on 80gsm paper – or any suitable material of your choosing – cut out the outline, fold it up into a box and use super glue to hold it together. In this operation, remember to be very careful not to get Parts List – Level Crossing Controller 1 control PCB assembly (see below) 1 5V DC supply (eg, USB charger with USB cable) 1 SPST toggle switch (S1) OR 1 momentary pushbutton switch (S1) OR 2 reed switches plus a magnet (S1; see text) 8 3mm high-intensity red LEDs with diffused lenses (LED1-LED8) 2 1.6kg.cm 9g 180° micro servos [eg, Core Electronics SER0006] 1 8Ω speaker [eg, Jaycar AS3006] 1 ISD1820P-based audio recording/playback module [eg, Jaycar XC4605, see text] 1 set of printed labels (see Fig.3) various lengths and colours of light-duty hookup wire various mechanical parts (see Fig.2) Control PCB parts 1 single-sided PCB coded 09108211, 48 x 43mm 2 8-pin DIL IC sockets (for IC1 and IC2) 1 14-pin DIL IC socket (for IC3) 1 PIC12F617-I/P 8-bit microcontroller programmed with 0910821A.HEX (for toggle switch) OR 0910821B.HEX (for momentary or reed switches) (IC1) 1 PIC12F617-I/P 8-bit microcontroller programmed with 0910821C.HEX (IC2) 1 ISD1820P audio recording/playback IC with bell sound recorded (IC3) (from module listed above) 1 2N7000 small-signal N-channel MOSFET (Q1) 1 100μF 16V electrolytic capacitor 2 100nF 63V MKT or 50V ceramic capacitors 16 1mm PCB pins Reproduced by arrangement with Resistors (all 1/4W 1% axial metal film) SILICON CHIP magazine 2022. 1 1MΩ 1 100kΩ 1 10kΩ www.siliconchip.com.au 2 4.7kΩ 2 330Ω 1 220Ω super glue on your fingers – unsticking them can be painful! Use tweezers to hold the surfaces together when the glue is setting. Last, Paint the box silver, cut out the hole for the servomotor and then fit the box. (Repeat this build for the other servomotor.) Teach-In 8 CD-ROM Exploring the Arduino EE FR -ROM CD ELECTRONICS TEACH-IN 8 FREE CD-ROM SOFTWARE FOR THE TEACH-IN 8 SERIES FROM THE PUBLISHERS OF This CD-ROM version of the exciting and popular Teach-In 8 series has been designed for electronics enthusiasts who want to get to grips with the inexpensive, immensely popular Arduino microcontroller, as well as coding enthusiasts who want to explore hardware and interfacing. Teach-In 8 provides a one-stop source of ideas and practical information. The Arduino offers a remarkably effective platform for developing a huge variety of projects; from operating a set of Christmas tree lights to remotely controlling a robotic vehicle wirelessly or via the Internet. Teach-In 8 is based around a series of practical projects with plenty of information for customisation. The projects can be combined together in many different ways in order to build more complex systems that can be used to solve a wide variety of home automation and environmental monitoring problems. The series includes topics such as RF technology, wireless networking and remote web access. PLUS: PICs and the PICkit 3 – A beginners guide The CD-ROM also includes a bonus – an extra 12-part series based around the popular PIC microcontroller, explaining how to build PIC-based systems. £8.99 INTRODUCING THE ARDUINO • Hardware – learn about components and circuits • Programming – powerful integrated development system • Microcontrollers – understand control operations • Communications – connect to PCs and other Arduinos PLUS... PIC n’MIX PICs and the PICkit 3 - A beginners guide. The why and how to build PIC-based projects Teach In 8 Cover.indd 1 04/04/2017 12:24 PRICE £8.99 Includes P&P to UK if ordered direct from us SOFTWARE The CD-ROM contains the software for both the Teach-In 8 and PICkit 3 series. ORDER YOUR COPY TODAY! JUST CALL 01202 880299 OR VISIT www.epemag.com 30 Practical Electronics | July | 2022