Wednesday, 24 July 2019

Music and a fun fair


Here is a video of a new addition to my layout.



This is the Faller HO Polyp fairground ride. It comes with an AC motor, which I have discarded and replaced with an Amazon sourced 12V DC motor with gearbox.

12V DC motor

This has been hooked up to an Arduino with complex components. One is an L298N H Bridge motor controller. The other is a DF Player Mini - plays mp3s from a micro SD card.

You can see the resulting mess on the prototyping board here

UserPostedImage


Basically, there are 10 rock and roll tunes on the SD card. The Arduino picks one at random and calculates its length in seconds from an inbuilt table. It the spins the motor up gradually for 14 seconds, runs the ride for the required length and spins it down for 15 seconds. It then delays for a random period and starts all over again. The idea is to recreate the ride that my wife remembers from Raphaels Park, Romford in the 60s when she was a teenager! The L298N is there to drive the motor as the Arduino doesn't have enough oomph. The power to the L298N comes from a Chinese 12V power supply in the pink box behind. This is the source of the hum. I am currently working on a thermistor driven Arduino to go inside the box and control the fan, which is what is making all the noise! Mind you, as it is 85F in my living room at the moment, now is not a good time to work out the settings!

Sunday, 21 July 2019

Arduino, Arduino, Arduino

In case you don't know, an Arduino is a little processor board that can control physical items connected either through digital (on-off) or analogue pins on its board. Up to now, I have used an Arduino to control the level crossing. I now have three more in various stages of completion for the following tasks:

  • Indicators of  arrival in the shadow station
  • Making the "Polyp" ride operate
  • Coordinating 60's rock and roll music to the "Polyp".

Shadow Station

Because of my arthritis, I can't turn to see the trains when they reach the end of the shadow station board and control the loco from the ECOS. The simple answer was to put up some visual indicator of position for each of the shadow station tracks. The final answer was to use light dependent resistors (ldr) buried in the track to control coloured LEDs on the fascia board beside the ECOS. After a lot of messing around due to a faulty ldr, it was all resolved and in place. LDRs are very expensive - NOT. £4.99 for 70! Once I replaced the dodgy one, everything works. I now have this nice little display in front of me where each track is aligned to a coloured LED which lights up when a loco moves over it.


The white light is just to show that it is working because, when there are no locos in the shadow station, all the lights are off so it is nice to have a pilot light.




As the shadow station is dis-mountable, there is a multi-way plug attached which connects to the main board. This plug can only be inserted in one direction. Mind you, I have to remember to unplug it when taking everything down!





Although this is the one for the level crossing, it shows you how the LDR is placed in the track. It is not at all noticeable.

Making the Polyp ride operate

The Faller kit for a fairground ride is called the "Polyp". It looks like our Octopus ride. My wife remembers going on something similar in her early teens at the Funfair in Raphael's Park in Romford. I think that she remembers "The Whip" where the boys from the ride would hit the brake in one of the compartments to make it swing round. As she say, she always remembers not only the ride but the music that was played. This was all the excuse I needed. First off, I have to make the ride operate. It comes with a motor but this is a simple 16VAC motor that can be turned on and off. It needs an AC power supply, which I didn't have. I had a nice 12V Chinese PS sitting there from an earlier attempt to put under-shelf LED lighting in my old railway room. I was able to get a nice little 12V motor and gearbox from Amazon and fit it instead of the provided one.






The problem was making a "lightweight" Arduino control a motor that would pull current in excess of the Arduino's capability. The answer turned out to be an L298N Dual H Bridge Stepper Motor Driver . This sits between the Arduino and the motor and provides the extra power required. It can also be controlled for speed and direction. Here is the L298N attached to the Arduino and wired into the motor. The pink box contains the Chinese PS as the 240V connections were somewhat exposed!


The Arduino program drives the motor for a period and then keeps it still for another - random - period when the whole things starts over again. Notice that it starts up slowly and slows down nicely at the end.


Now, we have the problem of the "rock" music. That's the next step.

Coordinating 60's rock and roll music to the "Polyp".

There are so many cheap add-ons for the Arduino that you can manage almost anything that you can think of. I have a little thing called a DF PLayer Mini which is a little board that wires into the Arduino and provides music off a mini-SD card. All for £3.50 or so. This little thing can manage up to 100 folders with MP3 files inside. It can be started, stopped, make a selection, etc. The trick is to get it working! I had to mess about for a good few hours trying to get the correct include files and the matching code until I hit on the right combination. 


Currently, I am running it through a Boombar Bluetooth speaker but I have a natty little AUX driven one coming. Along with all of this, I have got hold of a set of CDs for Dion and the Belmonts, Del Shannon and Eddie Cochran. Tunes from these such as "Runaway" and "The Wanderer" should provide a great background to the fair. 

Now to tie it all in


Now, the big problem! I have to make the Arduino running the ride drive the other one running the music. Amazingly, there is an include file called Wire which does all of this. Provided I keep to a single character, I can send it from one to the other. '0' to '9' should do for the tracks, 'G' for Go and 'S' for stop should make it all workable.

The ride will decide on a random tune. Both will know how long the tune is. The ride can tell the music which track and when to start it. They will both run for the length of the tune and then the ride will tell the music to stop. The ride will then wait a random time and it will all start again.

Needless to say, it will be a bit like Christmas songs in a shop! Hence, we change the tunes by refreshing the SD card and we can turn the whole thing off on demand. This is where an LDR comes in. Sitting on the ground in the fun fair will be a police car. When the ride is active, the police car will be over the LDR. To stop the ride, just pick up the car and move it sideways to expose the LDR. Job done!