An old rotary phone is remade into a Taylor Swift is calling phone. By programming an Arduino Nano to activate the solenoid to ring the bell when the sonar sensor detects an object withing three feet of the phone, a passerby is encouraged to pick up this phone receiver. When the receiver is picked up a clip of a Taylor Swift song is played. This project was made for a Glens Falls Girl’s STEM day in 2024 and it was well received.
Taylor Swift is Calling ARDUINO CODE
int bellPin = 9; //solenoid pin
#define sensorPin A2 //distance sensor
#define ledPin 8
#define hookPin 7 //reading if phone is on or off hook
bool offHook = false, wasOffHook = false, isNear = false, wasNear = false;
int rings = 0, microRings=0, ringLimit=5, microRingLimit=30, microRingDelay=20, ringDelay=400;
int distance = 0;
unsigned long myStartTime, myPlayTime;
int playTime = 44000;//longer than longest song
#include <SoftwareSerial.h>
#define ARDUINO_RX 5//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 6//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell to myserial wich pins are TX and RX
static int8_t Send_buf[8] = {0} ;//The MP3 player undestands orders in a 8 int string
//0X7E FF 06 command 00 00 00 EF;(if command =01 next song order)
#define NEXT_SONG 0X01
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed 0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)
#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
#define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED
#define STOP_PLAY 0X16
void setup()
{
Serial.begin(9600);//Start our Serial coms for serial monitor in our pc
mySerial.begin(9600);//Start our Serial coms for THE MP3
delay(500);//Wait chip initialization is complete
sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card
delay(200);//wait for 200ms
pinMode(hookPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(bellPin, OUTPUT);
// no pinMode for sensor pin?
}
void loop()
{
wasNear = isNear;
isNear = checkIfNear();
wasOffHook = offHook;
offHook = digitalRead(hookPin);
print_data();
digitalWrite(ledPin, HIGH);
if((isNear == true) && (wasNear == false) && (offHook == false)){
ring_phone();
}
}//end of loop
void sendCommand(int8_t command, int16_t dat)
{
delay(20);
Send_buf[0] = 0x7e; //starting byte
Send_buf[1] = 0xff; //version
Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
Send_buf[3] = command; //
Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
Send_buf[5] = (int8_t)(dat >> 8);//datah
Send_buf[6] = (int8_t)(dat); //datal
Send_buf[7] = 0xef; //ending byte
for(uint8_t i=0; i<8; i++)//
{
mySerial.write(Send_buf[i]) ;//send bit to serial mp3
Serial.print(Send_buf[i],HEX);//send bit to serial monitor in pc
}
Serial.println();
}
bool checkIfNear() {
distance = analogRead(sensorPin) * 1;
if(distance <= 100){
return true;
}
else{
return false;
}
}
void print_data() {
Serial.print("distance = ");
Serial.print(distance);
Serial.println(" cm");
}
bool ring_phone(){
rings=0;
while(rings<ringLimit){
rings=rings+1; microRings=0;
while((offHook==false) && (microRings<microRingLimit)){
microRings=microRings+1;
wasOffHook=offHook;
offHook=digitalRead(hookPin);
digitalWrite(bellPin, HIGH); digitalWrite(ledPin, HIGH); delay(microRingDelay); digitalWrite(bellPin, LOW);digitalWrite(ledPin, LOW); delay(microRingDelay);
if(offHook==true){play_song(); return true;};}; //end of microRings<microRingLimit loop
delay(ringDelay); }; //end of while rings<rigLimit loop
return false;
}//end of ring_phone()
int play_song(){
int rand = random(1,14);
switch(rand){
case 1:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F01); break;
case 2:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F02); break;
case 3:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F03); break;
case 4:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F04); break;
case 5:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F05); break;
case 6:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F06); break;
case 7:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F07); break;
case 8:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F08); break;
case 9:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F09); break;
case 10:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F0A); break;
case 11:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F0B); break;
case 12:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F0C); break;
case 13:
sendCommand(CMD_PLAY_WITHVOLUME, 0X3F0D); break;
}
myStartTime=millis();
while(((millis()-myStartTime)<playTime) && offHook == true){
wasOffHook = offHook; offHook = digitalRead(hookPin); delay(250);}
sendCommand(STOP_PLAY, 0X16);
rings = 6;
return;
}
PARTS LIST
Arduino Nano
Small Push – Pull Solenoid 12 VDC
Catalex SD card player
Maxbotix Ultrasonic Rangefinder – LV-EZ1
old rotary phone
9 VDC 1000mA regulated switching power adapter
Diffused Red 10mm LED
10mm Plastic Bevel LED Holder
3D Printing STL file
https://www.thingiverse.com/thing:6671296

