Capacitive Sensing without library

Hi all,

after playing around with the CapacitiveSensor Library, i had the idea to write a simple capacitive touch sensing solution from scratch. Similar to the library, my idea was to load a LOW Pin via a HIGH Pin and measure the time needed for this. So here's what i came up with:

typedef struct Sensor //struct used for sensing
  int input; //has one input pin
  int output; //has one output pin

int input = 2; //pin 2 used for input
int output = 4; //pin 4 used for output

Sensor createSensor(int in, int out) //create sensor with one input and one output
  Sensor s = {in,out}; //create struct
  pinMode(in,INPUT); //set input pin
  pinMode(out,OUTPUT); //set output pin
  return s; //return struct
unsigned long measureTime(Sensor* s)
  unsigned long start_time = micros(); //starting point for time measurement interval

  digitalWrite(s->output,HIGH); //set output pin high 
  while(digitalRead(s->input) == 0) //while input isnt high yet
    //do nothing
  unsigned long measured_time = micros() - start_time; //calculate loading time
  digitalWrite(s->output,LOW); //reset output
  digitalWrite(s->input,LOW);//reset input
  return measured_time; //return loading time
void setup() {

  Serial.begin(9600); //start serial communication

void loop() {
 Sensor s = createSensor(input,output); //create sensor

 while (1) //main loop
 Serial.println(measureTime(&s));//measure time and print it to serial


Pin 2 and Pin 4 are connected via a 1M resistor, Pin 2 is also connected with a piece of copper foil acting as my sensor. Normally, the loading time is 16 micro seconds. When i touch the foil directly, i can see a huge change in the loading time. However, if i am not touching it directly but only very close with my finger, the loading time doesnt change and stays at 16 micro seconds. Any ideas how to increase sensitivity/range here?

Thank you all for reading and for possible suggestions.