Slap-O-Meter 3000 – Hind & Maimuna

We present you our “Slap-O-Meter 3000″ 👋👋👋

In this week’s assignment we are expected to create a Musical Instrument. Initially we planned to create a Marble Shaker- using the Servo to shake a box of marble from both sides. That was not quite successful because either the box would move completely or not move at all. We were fixated on using the servo and it just clicked about hit sticks on a box using the servo.

Final Product
We used the Ultrasonic sensor to change the speed of the Servo i.e. the hands of the Slap-O-Meter. The closer an object gets to the sensor, the faster the hands moves. The hands are adjusted at an angle to the box so regardless of the speed, it hits the box properly. Here is the code that we used to control the servo and the ultrasonic sensor:

# include <Servo.h>

Servo servo;
const int trig = 12;
const int echo = 13;

int duration = 0;
int distance = 0;

void setup() 
  pinMode(trig , OUTPUT);
  pinMode(echo , INPUT);


void loop()
  digitalWrite(trig , HIGH);
  digitalWrite(trig , LOW);

  duration = pulseIn(echo , HIGH);
   distance = (duration / 2) * 0.0343;

  int constdistance = constrain(distance, 0, 30);
  int mappedDisValue = map(constdistance, 0, 30, 0, 180);
  int constrainedDisValue = constrain(mappedDisValue, 0, 180);
  int servoSpeed = map(constdistance, 0, 30, 100, 500);



We had a lot of fun implementing it! No major challenges apart from some software issues on my laptop and so we just ended up connecting both Arduino to Hind’s laptop.

Leave a Reply