tarun
Published © GPL3+

Spinet

Our project name is spinet.our project deals with music so we have chosen the title as Spinet. Spinet mean a small piano.

IntermediateFull instructions provided2 hours3,047
Spinet

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Arduino MKR1000
Arduino MKR1000
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

spinet

Schematics

spinet

Code

project spinet.docx

Arduino
No preview (download only).

Project Spinet

Arduino
int trig = 2;

int echo = 3;
int pin = 9;
void setup()
{
  Serial.begin(9600);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(pin, OUTPUT);
}
void loop()
{
  int duration , distance;
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = (duration / 2) / 21.9;
  Serial.print(distance);
  Serial.print("cm");
  delay(50);

  if (distance < 3)

  {

    tone(pin, 1318.5);
  }
  else if ((3 < distance) && (distance < 6))
  {
    tone(pin, 1244.5);

  }
  else if ((6< distance) && (distance < 9))
  {
    tone(pin, 1174.7);
  }
  else if ((9 < distance) && (distance < 12))
  {
    tone(pin, 1108.7);
  }
  else if ((12 < distance) && (distance < 15))
  {
    tone(pin, 1046.5);
  }
  else if ((15 < distance) && (distance < 18))
  {
    tone(pin, 987.77);
  }
  else if ((18 < distance) && (distance < 21))
  {
    tone(pin, 932.33);
  }
  else if ((21 < distance) && (distance < 24))
  {
    tone(pin, 880);
  }
  else if ((24 < distance) && (distance < 27))
  {
    tone(pin, 830.61);
  }
  else if ((27 < distance) && (distance < 30))
  {
    tone(pin, 783.99);
  }
  else if ((30 < distance) && (distance < 33))
  {
    tone(pin, 739.99);

  }
  else if ((33 < distance) && (distance < 36))
  {
    tone(pin, 698.46);
  }
 

  
  else
  {
    noTone(pin);
  }
}

Credits

tarun

tarun

0 projects • 7 followers
I coding micro controllers and connect them to the web and make some applications.I am an organizer of IoT User Group Hyderabad.

Comments