This is only a preview of the July 2021 issue of Silicon Chip.
You can view 41 of the 112 pages in the full issue, including the advertisments.
Items relevant to "20A DC Motor Speed Controller":
Articles in this series:
Articles in this series:
Items relevant to "Model Railway Level Crossing":
Items relevant to "Silicon Labs-based FM/AM/SW Digital Radio":
Items relevant to "Advanced GPS Computer – Part 2":
Purchase a printed copy of this issue for $10.00.
Model Railway Level Crossing BY LES KERR This scale model 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 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 by; 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 46 Silicon Chip 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. 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, Australia’s electronics magazine 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 you need a ‘full bridge’ type driving arrangement that can drive one end of the LEDs high while it drives the other low, or vice versa, to illuminate all the LEDs. Luckily, this is easily achieved with a pair of microcontroller digital output pins. Circuit description Refer now to Fig.1, the Level siliconchip.com.au Fig.1: circuit diagram for the Level Crossing Controller. This project uses two PIC12F617 ICs, this saves on extra components as a 555 timer and some transistors would be needed instead to flash the LEDs. 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 8W speaker. 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 siliconchip.com.au 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 arms slowly down until the servo arm is horizontal. It remains down until a Australia’s electronics magazine couple of seconds after the start switch opens (at which point the flashing lights & 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 desire 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 July 2021 47 Fig.2: a 1:1 scale diagram of the mechanical construction details for the unit. Note that the servomotors have their mounting arms removed 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 siliconchip.com. au/Shop/11/5855 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 48 Silicon Chip 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. 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 Australia’s electronics magazine 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 KS 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 KS metal. You will need two of each of the rail crossing backing plates, track backing plates and stop backing plates. Using a small 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/16in (1.6mm) blank PCB scraps. You siliconchip.com.au An example of what the finished barrier and railway crossing sign looks like. 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. 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 holder LED assembly 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. 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. 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 siliconchip.com.au 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. 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 siliconchip. com.au/Shop/11/5855 and print it on a colour printer using 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. Australia’s electronics magazine Fig.4: the overlay diagram for the Level Crossing. Note the resistors are mounted vertically. 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 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. July 2021 49 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 on the locomotive. 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 coded 09108211 which measures 48 x 43mm. The PCB overlay diagram, 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. Take care to orientate 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, orientated as shown. The wiring diagram (Fig.5) shows how to connect the two post assemblies, the loudspeaker, the trigger 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 purchase preprogrammed micros, or program them yourself using an external programmer before plugging them in. You can download the HEX files from the Silicon Chip website; the one ending in A or B is for IC1 (depending on the type of switch used) and C for IC2. Recording the bell sound Here is an example of the completed project fitted onto a model railway track. 50 Silicon Chip Australia’s electronics magazine 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 overleaf). The simplest way to transfer the bell siliconchip.com.au 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 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 8W 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 level crossing PCB, orientated 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 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. 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 micro servos [eg, Core Electronics SER0006] 1 8W speaker [eg, Jaycar AS3006] 1 ISD1820P-based audio recording/playback module [eg, Jaycar XC4605] 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 & 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 Resistors (all 1/4W 1% axial metal film) 1 1MW 2 4.7kW 1 100kW 2 330W 1 10kW 1 220W and 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, cut out the outline, fold it up into a box and use super glue to hold it together. In this operation, be very careful not to get super glue on your fingers – unsticking them can be painful! Use tweezers to hold the surfaces together when the glue is setting. Paint the box silver, cut out the hole for the servomotor and fit the box. Repeat for the other servomotor. 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 adjacent 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, siliconchip.com.au 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. Australia’s electronics magazine July 2021 51 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. In the end, 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 computer’s output jack is adjusted in level using VR1, then AC-coupled to two op amps, IC2a & 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 & 5. The components at the top of the circuit detect when 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. The ISD1820P is often sold as a module similar to this. This model in particular 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. IC1a amplifies the audio signal by around 83 times and then feeds a diode charge pump (D1 and the 1μF capacitor). This capacitor quickly 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 IC3 (pin 5) low as soon as the charge on that 1μF capacitor exceeds about 3.3V. This also lights LED1. When 8-bit PIC microcontroller IC3 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 record the whole bell sound sequence. So IC3 is acting as a pulse SC stretcher. Fig.7: a circuit I designed to record sound to the ISD1820P module directly from a computer’s audio output jack. 52 Silicon Chip Australia’s electronics magazine siliconchip.com.au