woodwarddigital
Published © MIT

May the 4th be with you

Celebrate Star Wars day with an Arduino!

BeginnerFull instructions provided13
May the 4th be with you

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Buzzer
Buzzer
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Sketch

Code

May the 4th be with you

Arduino
Upload to an Arduino and map the pins correctly.
// Script Name: May the 4th be with you - 2021
// Created By: Woodward.Digital
// Credit to: Nick James, https://gist.github.com/nicksort for The Imerial March code
// Website: https://woodward.digital
// Email: contact@woodward.digital

#include <LiquidCrystal.h>

// Set pins for LCD interface
// Details the pin on the LCD = the Arduino pin
const int rs = 12;
const int en = 11;
const int d4 = 5;
const int d5 = 4;
const int d6 = 3;
const int d7 = 2;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
// Initialize all the notes for the Imperial March
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int b = 466;
const int cH = 523;
const int cSH = 554;
const int dH = 587;
const int dSH = 622;
const int eH = 659;
const int fH = 698;
const int fSH = 740;
const int gH = 784;
const int gSH = 830;
const int aH = 880;
int counter = 0;

// Set the pin for the buzzer
const int buzzerPin = 9;

void setup() {
lcd.begin (16,2); //Initialize the LCD
lcd.home ();
pinMode(buzzerPin, OUTPUT);
}
 
void loop() {
delay(1000);
lcd.setCursor(0,0);
lcd.print("May the 4th");
lcd.setCursor(0,1);
lcd.print("Be with you!");

//Play first section
firstSection();

//Play second section
secondSection();

//Variant 1
beep(f, 250);  
beep(gS, 500);  
beep(f, 350);  
beep(a, 125);
beep(cH, 500);
beep(a, 375);  
beep(cH, 125);
beep(eH, 650);

delay(500);

//Repeat second section
secondSection();

//Variant 2
beep(f, 250);  
beep(gS, 500);  
beep(f, 375);  
beep(cH, 125);
beep(a, 500);  
beep(f, 375);  
beep(cH, 125);
beep(a, 650);  
 
delay(650);
delay(10000);
}
 
void beep(int note, int duration)
{
//Play tone on buzzerPin
tone(buzzerPin, note, duration);

delay(duration); 
 
//Stop tone on buzzerPin
noTone(buzzerPin);
 
delay(50);
 
//Increment counter
counter++;
}
 
void firstSection()
{
beep(a, 500);
beep(a, 500);    
beep(a, 500);
beep(f, 350);
beep(cH, 150);  
beep(a, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 650);
 
delay(500);
 
beep(eH, 500);
beep(eH, 500);
beep(eH, 500);  
beep(fH, 350);
beep(cH, 150);
beep(gS, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 650);

delay(500);
}
 
void secondSection()
{
beep(aH, 500);
beep(a, 300);
beep(a, 150);
beep(aH, 500);
beep(gSH, 325);
beep(gH, 175);
beep(fSH, 125);
beep(fH, 125);    
beep(fSH, 250);

delay(325);
 
beep(aS, 250);
beep(dSH, 500);
beep(dH, 325);  
beep(cSH, 175);  
beep(cH, 125);  
beep(b, 125);  
beep(cH, 250);  

delay(350);
}

Credits

woodwarddigital

woodwarddigital

0 projects • 0 followers

Comments