Novelty Clock That Plays Melody If Wrong Wire Is Cut

by sigmatechelysium in Circuits > Arduino

33 Views, 0 Favorites, 0 Comments

Novelty Clock That Plays Melody If Wrong Wire Is Cut

IMG20240519174451.jpg
novelty Clock that plays melody if wrong wire is cut

I bought a digital clock that is quite boring, so I decided to make an interesting stand for it.

The wires around it are functional, only one interrupts the operation of the clock, the others play the melody.


Fake Defusable Alarm Clock that is DIY-No-Mite ... lol

It is just novelty for decoration, a conversation piece for the coffee table.


Definition of Novelty:

- the quality of being new, original, or unusual.

- a small and inexpensive toy or ornament.

Supplies

Supplies:

  • AT89C2051 Digital 4 Bits Electronic Clock DIY Kit
  • Ardunio Nano
  • Wires - different colors
  • 3.5mm dc connector
  • PVC conduit for electrical wire installation 2m/20mm
  • A4 paper with printed texture
  • Heat shrink tube
  • 5V DC power supply



Basic DIY Tools:

  • soldering iron
  • saw (with small teeth)
  • heat gun or lighter
  • tape and zip ties
  • wire cutter, box cutter
  • smaller pliers
  • drill

Electronics Testing

Untitled.png
Untitled2.png
01i.jpg

This is a short diagram of the connection between the Arduino and the clock.

I will use the buzzer speaker from the clock also for the Arduino


I use the Arduino Nano because it is small, I don't need anything powerful and because of its dimensions it will fit in one of the pipes. And everything is first tested on a test board.

It is important to pay attention to which pins what is connected, in my case the buzzer is connected to Pin 7 

and the cable that starts the program to Pin 4 (you can connect on on any of pin 2, 3,4 or 5 - i have chosen 4).

If pin 4 is present, that is - if it is connected to ground, the Arduino does not start the program, 

as soon as the connection with pin 4 is broken, the program starts / or what in my case is the melody.

There will be 5 wires connected in series and the 6th wire will be connected to the power supply plus so that if it is cut 

it will shut down everything. the odds of guessing which wire to cut are 6:1


It is simple to make Arduino play some melody. For initial testing, I also used the Arduino simulator from the site: https://wokwi.com/

Programming

Programming is not my strong point, so I use Chat GPT, but it's not perfect, it's much better to use code from others,

which i did. I used code from user Rowan07 on web site Project HUB Arduino.

https://projecthub.arduino.cc/rowan07


I only used Chat GPT to change the code:

  • no text just melody
  • power off if pin 4 is on high state ( i had a lot problems with this)


It made my job a lot easier. I only had to make a few changes myself.

Basically, any song can be added, there are many projects and pages online, so it can be easily changed if you want to add your touch.

Everything has been tested and both hardware and software work, the rest should be easier, although this wasn't too much of a problem either.


/*
  RickRollCode


  AUTHOR: Rowan Packard
  rowanpackard@gmail.com


  DISCLAIMER: The song "Never Gonna Give You Up" by Rick Astley
  is not the creative property of the author. This code simply
  plays a Piezo buzzer rendition of the song.
*/


#define a3f 208   // 208 Hz
#define b3f 233   // 233 Hz
#define b3 247    // 247 Hz
#define c4 261    // 261 Hz MIDDLE C
#define c4s 277   // 277 Hz
#define e4f 311   // 311 Hz    
#define f4 349    // 349 Hz 
#define a4f 415   // 415 Hz  
#define b4f 466   // 466 Hz 
#define b4 493    //  493 Hz 
#define c5 523    // 523 Hz 
#define c5s 554   // 554  Hz
#define e5f 622   // 622 Hz  
#define f5 698    // 698 Hz 
#define f5s 740   // 740 Hz
#define a5f 831   // 831 Hz 


#define rest -1


int piezo = 7; // Connect your piezo buzzer to this pin or change it to match your circuit!
int led = LED_BUILTIN; 


volatile int beatlength = 100; // determines tempo
float beatseparationconstant = 0.3;


int switchPins[] = {2, 3, 4, 5}; // Switch pins
int numSwitches = 4;


int a; // part index
int b; // song index


boolean flag;


// Parts 1 and 2 (Intro)


int song1_intro_melody[] = {
  c5s, e5f, e5f, f5, a5f, f5s, f5, e5f, 
  c5s, e5f, rest, a4f, a4f
};


int song1_intro_rhythmn[] = {
  6, 10, 6, 6, 1, 1, 1, 1, 
  6, 10, 4, 2, 10
};


// Parts 3 or 5 (Verse 1)


int song1_verse1_melody[] = {
  rest, c4s, c4s, c4s, c4s, e4f, rest, c4, b3f, a3f,
  rest, b3f, b3f, c4, c4s, a3f, a4f, a4f, e4f,
  rest, b3f, b3f, c4, c4s, b3f, c4s, e4f, rest, c4, b3f, b3f, a3f,
  rest, b3f, b3f, c4, c4s, a3f, a3f, e4f, e4f, e4f, f4, e4f,
  c4s, e4f, f4, c4s, e4f, e4f, e4f, f4, e4f, a3f,
  rest, b3f, c4, c4s, a3f, rest, e4f, f4, e4f
};


int song1_verse1_rhythmn[] = {
  2, 1, 1, 1, 1, 2, 1, 1, 1, 5,
  1, 1, 1, 1, 3, 1, 2, 1, 5,
  1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 3,
  1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4,
  5, 1, 1, 1, 1, 1, 1, 1, 2, 2,
  2, 1, 1, 1, 3, 1, 1, 1, 3
};


// Parts 4 or 6 (Chorus)


int song1_chorus_melody[] = {
  b4f, b4f, a4f, a4f,
  f5, f5, e5f, b4f, b4f, a4f, a4f, e5f, e5f, c5s, c5, b4f,
  c5s, c5s, c5s, c5s,
  c5s, e5f, c5, b4f, a4f, a4f, a4f, e5f, c5s,
  b4f, b4f, a4f, a4f,
  f5, f5, e5f, b4f, b4f, a4f, a4f, a5f, c5, c5s, c5, b4f,
  c5s, c5s, c5s, c5s,
  c5s, e5f, c5, b4f, a4f, rest, a4f, e5f, c5s, rest
};


int song1_chorus_rhythmn[] = {
  1, 1, 1, 1,
  3, 3, 6, 1, 1, 1, 1, 3, 3, 3, 1, 2,
  1, 1, 1, 1,
  3, 3, 3, 1, 2, 2, 2, 4, 8,
  1, 1, 1, 1,
  3, 3, 6, 1, 1, 1, 1, 3, 3, 3, 1, 2,
  1, 1, 1, 1,
  3, 3, 3, 1, 2, 2, 2, 4, 8, 4
};


void setup() {
  pinMode(piezo, OUTPUT);
  pinMode(led, OUTPUT);
  
  for (int i = 0; i < numSwitches; i++) {
    pinMode(switchPins[i], INPUT_PULLUP);
  }


  digitalWrite(led, LOW);
  Serial.begin(9600);
  flag = true;
  a = 4;
  b = 0;
}


void loop() {
  bool anySwitchOff = true;
  for (int i = 0; i < numSwitches; i++) {
    if (digitalRead(switchPins[i]) == LOW) {
      anySwitchOff = false;
      break;
    }
  }


  if (anySwitchOff) {
    // play next step in song
    if (flag == true) {
      play();
    }
  }
}


void play() {
  int notelength;
  if (a == 1 || a == 2) {
    // intro
    notelength = beatlength * song1_intro_rhythmn[b];
    if (song1_intro_melody[b] > 0) {
      digitalWrite(led, HIGH);
      tone(piezo, song1_intro_melody[b], notelength);
    }
    b++;
    if (b >= sizeof(song1_intro_melody) / sizeof(int)) {
      a++;
      b = 0;
    }
  } else if (a == 3 || a == 5) {
    // verse
    notelength = beatlength * 2 * song1_verse1_rhythmn[b];
    if (song1_verse1_melody[b] > 0) {
      digitalWrite(led, HIGH);
      tone(piezo, song1_verse1_melody[b], notelength);
    }
    b++;
    if (b >= sizeof(song1_verse1_melody) / sizeof(int)) {
      a++;
      b = 0;
    }
  } else if (a == 4 || a == 6) {
    // chorus
    notelength = beatlength * song1_chorus_rhythmn[b];
    if (song1_chorus_melody[b] > 0) {
      digitalWrite(led, HIGH);
      tone(piezo, song1_chorus_melody[b], notelength);
    }
    b++;
    if (b >= sizeof(song1_chorus_melody) / sizeof(int)) {
      a++;
      b = 0;
    }
  }
  delay(notelength);
  noTone(piezo);
  digitalWrite(led, LOW);
  delay(notelength * beatseparationconstant);
  if (a == 7) { // loop back around to beginning of song
    a = 1;
  }
}


Arts and Crafts

04i.jpg
03i.jpg
02i.jpg
05i.jpg
06i.jpg
07i.jpg

I call this segment Arts and Crafts because we are essentially making a model/prop bomb.


For the wires, I use a cable that has different colors and the copper core is full it is one wire, which will make it easier

 to bend the it at the end and it will stay where I want it.

For the fake dynamite, I will use a PVC pipe that is used for electrical installations. 

I should have taken a little bigger one but everything turned out fine in the end. 

I thought of making it shorter, but somehow it looked better if the pipes were a little longer.


I marked the first pipe so I used it as a template to cut the others.

I didn't bother with how the edges look because they will all be covered up later.

It was much faster and cheaper with the tube, my original idea was to 3D print, which would be more precise and

 it would be easier to hide the components, but in the end I think it looks better this way and it is so much easier.


All the components are here and now it's time to figure out how everything will look and where will everything fit.


I tied it with tape to see the layout and after a bit of sanding the plan was there.

The Arduino gave me little challenge because it is a couple of millimeters wider than the inside of the pipe, 

but that problem was also solved with sandpaper.

As I said, if I were to do it again, I would take a tube that is 5 mm larger in diameter. 

It would be easier to fit the Arduino, power connector and wires and also to put batteries in it If I ever want a battery-powered clock.


Now it's time to wrap the plastic pipes. I decided to do it for the better look. 

And for that I have printed the texture of some old paper.

I would start with one end and roll the sheet of paper so I can tape the ends. The tape will not be visible because I will 

turn the pipe so that the glued part is down.

I was surprised how well it looks, I think it will look great when everything is assembled.

I didn't wrap them all because I still need to modify few pipes for cables.


One of the hardest moments of making this clock was when I had to run cables, drill holes and figure out how to hide 

the wires going to the Arduino and the clock.


The best way is to drill all the holes, if possible, then wrap the pipe and drill the paper. 

To grab the wires from the pipe, I used a paper clip that I bent a little at the tip to look like a hook.

The Arduino and the clock are powered by 5V, so I ran the wires from the main connector to the Arduino and 

from it to the clock. Also from the Arduino there are 4 additional wires for signal, sound and ground.


Wherever possible, I made sure that the joints were strong and that everything was covered with heat shrink tube.

All in all, this is easy to make, the biggest problem was pulling the cables and rearranging pipes that are constantly moving.


It helped me a lot to use elastic bands to hold the tube while I combine the rest.


TEST

IMG20240519174404.jpg
IMG20240519174359.jpg
IMG20240519174458.jpg
08i.jpg

I am satisfied with the dimensions, everything works perfectly.

It will surely be a good and funny conversation piece.


CREDITS:

I surfed on a WWW a lot and looked for inspiration online, there are also similar projects on Instructables, so it's hard for me to name exactly someone who inspired me. The only thing I can tell you is to look at similar projects on this page as well.

As far as I've seen, no one has made it play if the wire is cut, at least that is unique :)