Feature

Musical Meccano

Arduino-based F1 Meccano Car that plays the Aussie Anthem

Johnny "Meccano"

Issue 73, August 2023

We check out this Meccano-based F1 car with its Arduino Nano and motor circuit that generates the Australian National Anthem.

You may not be into Meccano, however, you can adapt what you see here to other projects if you want to generate tunes for your project.

The following is what Johnny has to say about his project.

I saw the Red Bull F1 car playing the Australian National Anthem on YouTube. There was a guy with a laptop so I figured he was controlling the car’s motor speed and I reckoned I could emulate that.

The first step is to rig up a motor to make a loud sound. I used a French Meccano motor but any 'can' motor will do.

To make the sound, I used a plastic Pulley with 3 lengths of wire attached so they hit the Plate.

Figure 5

My first prototype used a Bushwheel with string (Fig 5), but it wasn’t loud enough and the weight of the Bushwheel meant too much inertia so it didn’t change speed fast enough.

Figure 4

The plastic Pully with wire (Fig 4) was lighter and louder.

Figure 6

My test jig is shown in Fig. 6 and was first tested with a PWM before I moved on to the Arduino control.

The Arduino is capable of PWM control but the PWM pins can’t supply enough current for a motor drawing 1A so you need a transistor. I chose a BD681 Darlington pair simply because there was one in my parts drawer and it fitted the specs.

Figure 7

The circuit diagram (Fig 7) shows how it’s connected. The diode is to prevent back EMF and the 1µF capacitor is to suppress noise. My test jig worked from a 9V battery as long as the Nano was powered from the USB port but it failed when I ran the 9V to the Vin of the Nano.

Using my benchtop power supply worked, so I deduced that the combined current draw of the Nano and the motor was too much for a 9V battery. Rather than use a cumbersome benchtop PS, I had a few laptop AC adaptors laying around and they provide a regulated 12V 5A supply.

Figure 2

Unfortunately, my motor was getting hot with 12V so I added a voltage regulator to bring it down to 9V.

My original Fritzing was not an exact representation of my actual breadboard as I had difficulty adding parts without obscuring other parts, but the DIYODE team re-illustrated it to make it clearer. Use the circuit diagrams in Fig 2 and Fig 7, plus my actual breadboard photo in Fig 8, and you’ll get the full picture.

Figure 3

The Code

You can copy/paste the sketch from this article straight into your Arduino IDE as I have found a way to add code without losing the colour and formatting. Thanks to Dr Paul Dale for helping me with this code.

const int motorPin = 9; 
  const int startPin = 8; 
  #define note_C0 90 
  #define note_D1 100 // D 
  #define note_F1s 124 // F# 
  #define note_A1 146 // A 
  #define note_B1 170 // B 
  #define note_C1s 182 // c# 
  #define note_D2 200 // d 
  #define note_E2 215 // e 
  #define note_F2s 241 // f# 
  #define note_G2 255 // g 
  #define NOTE(freq, dur) { note_ ## freq, dur } 
  static const struct { unsigned char freq, dur; }     
    notes[] = { 
      NOTE(A1, 2), // Write noteA Aust 
      NOTE(B1, 2), // Write noted stral 
      NOTE(A1, 2), // Write noteA yans 
      NOTE(D1, 2), // Write noteFsharp all 
      NOTE(A1, 2), // Write noteA let 
      NOTE(D2, 3), // Write noted us 
      NOTE(D2, 1), // Write noted re 
      NOTE(D2, 2), // Write noted joice 
      NOTE(G2, 2), // Write notefsharp For 
      NOTE(C1s, 2), // Write notee we 
      NOTE(A1, 2), // Write noted are 
      NOTE(F1s, 2), // Write notecsharp young 
      NOTE(B1, 2), // Write noted and 
      NOTE(G2, 4), // Write notee free 
      NOTE(A1, 2), // Write noteA with 
      NOTE(B1, 2), // Write noted gol 
      NOTE(A1, 2), // Write noteA den 
      NOTE(D1, 2), // Write noteFsharp soil 
      NOTE(C0, 2), // Write noteA and 
      NOTE(A1, 3), // Write noted wealth 
      NOTE(A1, 1), // Write noted for 
      NOTE(A1, 2), // Write noted toil 
      NOTE(G2, 2), // Write notefsharp our 
      NOTE(C1s, 2), // Write notee home 
      NOTE(A1, 2), // Write noted is 
      NOTE(F1s, 2), // Write notecsharp girt 
      NOTE(D1, 2), // Write noted by 
      NOTE(C0, 4), // Write notee sea 
  }; 
  static void play() { 
      for (unsigned int i = 0; i < sizeof(notes)/sizeof(*notes); i++) { 
        analogWrite(motorPin, notes[i].freq); 
        delay(300 * (unsigned short)notes[i].dur); 
        analogWrite(motorPin, 0); 
        delay(100); 
      }; 
  } 
  void setup() { 
      pinMode(motorPin, OUTPUT); 
      pinMode(startPin, INPUT); 
      digitalWrite(startPin,HIGH); 
  } 
  void loop() { 
      if(digitalRead(startPin) == LOW) 
        play(); 
        digitalWrite(startPin,HIGH); 

The code uses the digitalWrite command to send a PWM signal from pin 9. The values are 0-255 with 0 stopped and 255 full throttle.

My tests showed that the motor wouldn’t run under 90 so the range had to be between 90-255. My mathematical formulas for mapping the pitch frequencies to values between 90 and 255 failed because the relationship was not linear. It really came down to using your ear so my daughter’s keyboard was used to listen to each note and adjust the PWM digitalWrite value until it sounded right to my ear. You can see all the values for each note in the #define entries in the sketch to the left. It is easy to change and I’m sure you may need to change them to suit your setup.

Figure 9

Fig 9 shows you the notes so use this to get your revs correct. Any change to the enclosure, motor, wire gauge or length, etc alters the notes so a final retune will be required.

You can simplify the electronics if you use a motor that’s happy with 12V as you can dispense with the voltage regulator.

Fig 10 shows the ‘echo chamber’ that I used. Unfortunately, the wire will rip the paint to shreds so use sacrificial Meccano Plates or tin.

Final words

This article is about the Arduino control of a motor to play songs. You can change it to play any National Anthem or even Happy Birthday and you can use any car or even an empty can of Coke if you like!

If you want to build the Meccano Renault F1 model the manual can be downloaded for free from the NZMeccano site.