n00b question-Controlling a motor with a piezo disc.

Hello, I'm very new to arduino and this is my first time using it for a class project. My idea is to have a piezo sensor connected to the arduino UNO and have the vibrations that the sensor picks up control a small motor. The motor would be used to open a small door or container.

I was wondering if there is actually a way to have the vibrations that the piezo picks up control a motor and if anyone knows how to go about doing this. I'm guessing that there is some code that can make this possible but I haven't been able to find anything so far.

Any advice would be greatly appreciated.

what exactly do you want the motor to do? if the piezo detects vibration(someone hitting it?) turn on?

int sensorValue;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(A4);
  Serial.println(sensorValue, DEC);
  if (sensorValue > 50) //50 is the threshold
  { 
      //do something if tap detected
  } 
}

Yea I wanted the motor to turn on when the piezo detects vibrations.

Basically what I thinking was a game for cats. The piezo would be attached to a cat toy and would detect the vibrations from when the cat strikes it. I was hoping that there would be a way to have the values from the piezo control the speed of the motor. The motor would end up controlling some kind of door (not completely thought out yet) that would have cat food or something behind it. So after the cat plays with the toy (piezo) long enough the motor would open the door to the prize.

Again I'm really new to all of this so any advise would be great.

you could use the map function to control the speed:

MotorVal = map(PiezoVal,InLow,InHigh,OutLow,OutHigh);

so maybe:

if (sensorValue > 50) //50 is the threshold
  { 
      MotorVal = map(sensorValue,50,300,0,180);
//write MotorVal to a servo etc here
  }

Thanks for the help! so far everything seems to be working great!