Arduino Uno, Capacitive sensor, triggers small vibration motor

Hey Guys,

For a Project I am using a Arduino Uno, with a Capacitive Sensor. I want it so that when the sensor is touched the motor will go on for a curtain time, and then go off again, until the sensor is touched again.

I have a working code for the capacitive Sensor, that also gives a reading. But I don't know how to add the motor into the code correctly, can someone please help me?

#include <CapacitiveSensor.h>

/*
 * Uses a high value resistor of 10M ohm between send pin and receive pin 
 * change with the Capacitive Sensor will trigger a small vibration motor
 */


CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired


void setup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
}

void loop()                    
{
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);
    

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing

    Serial.print(total1);                  // print sensor output 1
    Serial.print("\t");
    

    delay(10);                             // arbitrary delay to limit data to serial port 
}

Do you have code to run the motor? If you need help making the motor run, we need data sheets for the motor and motor driver. What is the motor power source? Does the motor turn in one direction or do you need forward and reverse rotation.

For using millis() for timing (don't use delay()) see millis() for beginners and blink without delay and the several things at a time tutorial.