Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
samnajiyousseftekriti
Published © MIT

Laser Guitar

In this project, we replaced the strings of an old guitar with lasers and DIY beam splitters.

IntermediateFull instructions provided3,936
Laser Guitar

Things used in this project

Hardware components

Laser Diode, 655 nm
Laser Diode, 655 nm
×3
LDR, 5 Mohm
LDR, 5 Mohm
×6
Arduino UNO
Arduino UNO
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

MIDI loop
Hairless MIDI
Apple GarageBand

Hand tools and fabrication machines

Mircroscope slides

Story

Read more

Schematics

Circuit Design

Code

Programming and algorithm

Arduino
#include <MIDI.h> // this code uses MIDI arduino library (previous codes used)
// Created and binds the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();
// Piano Guitar sample 12/24/16
// User settable variables
//*****************************************************************************************************
int strings=3;//number of strings
int frets=2;//number of frets
int TOTAL=strings*(frets+1);// number of LDRs
int PlayNote[9];
int Onetime[ ]={0,0,0};// to make sure a note doesn’t play twice.
int string=0;
int DELAY=200; // This puts time difference until next MIDI is sent
//******************************************************************************************************
//Internal Use Variables
//******************************************************************************************************
int pin;
int note0=10;
int note1=10;
int note2=10;
int NOWnote=0;
int hit;
//boolean error=false;
//******************************************************************************************************
//Setup
//******************************************************************************************************
void setup()
{
Serial.begin(115200);
}
//******************************************************************************************************
//Main Program
//******************************************************************************************************
void loop()
{
// takes sensors input
 for (pin=0; pin < strings ; pin++) // takes inputs from pin responsible for the plucking
{ // lowest note assigned to first pin
 hit = digitalRead(pin); // read the input pin
 PlayNote[pin]=hit;// stores the results from the pins inputs
}
 for (pin=strings; pin < TOTAL ; pin++) // takes inputs from pin responsible for the plucking
{ // lowest note assigned to first pin
 hit = digitalRead(pin); // read the input pin
 PlayNote[pin]=hit;
}
//******************************************************************************************************
//Play music
//******************************************************************************************************

 if(note0!=-2&&note1!=-2&&note2!=-2)// check if there is an error or not.
 {
 if (PlayNote[0]==1&&Onetime[0]!=1) // pluck string 0 // makes sure not to play two notes
 {
 NOWnote=note0;
 Onetime[0]=1; // played and waits untill ur the finger is off
 }
 else if (PlayNote[1]==1&&Onetime[1]!=1) // pluck string 1
 {
 NOWnote=note1;
 Onetime[1]=1; // played and waits untill ur the finger is off
 }
 else if (PlayNote[2]==1&&Onetime[2]!=1) // pluck string 2
 {
 NOWnote=note2;
 Onetime[2]=1; // played and waits untill ur the finger is off
 }
 MIDI.sendNoteOn(NOWnote,127,0);
 delay(DELAY); //play note: meaning pluck
 }
 else // find the right note
 {
 note0=find_note(PlayNote,0);
 note1=find_note(PlayNote,1);
 note2=find_note(PlayNote,2);
 }

 for(int i=0;i<strings;i++)// resets the logic test
 {
 if (PlayNote[i]==0)
 {
 Onetime[i]=0;
 }
 }
}
//******************************************************************************************************
//Find MIDI note
//******************************************************************************************************
int find_note(int PlayNote[9] ,int string )
{
int AllNote[3][3] ={ {50,68,69} , {62,63,64} , {66,67,68} }; // order is importent
int note=-2;
int j=0;
int notes[ ]={50,68,69};
int Play[]={0,0};
//loading the notes
for (int i=0;i<4;i++)
{
notes[i]=AllNote[string][i];
}
//take the frets input
for (int i=2*string+3;i<2*string+5;i++) //loading the inputs
{
Play[j]=PlayNote[i];
j++;
}
//logic
 if (Play[1]==0 && Play[2]==0) // no fretting
 {
 note=notes[0]; //open string
 }
 else if (Play[0]==1 && Play[1]==1) // fret 1 which blocks two LDRs in a row
 {
 note=notes[1]; //first fret is pressed
 }
 else if (Play[0]==0 && Play[1]==1 ) // fret 2 which only blocks last LDR in a row
 {
 note=notes[2]; //second fret is pressed
 }
 else
 {
 // error=true;
 note=-2;
 }
 return note;
}
[/code]

Credits

samnaji
2 projects • 0 followers
Contact
yousseftekriti
2 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.