Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Amal Mathew
Published © GPL3+

Proximity Lamp Using Arduino

Build a proximity sensor using aluminium foil and a high value resistor.

BeginnerFull instructions provided15 minutes9,966

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
10 mega ohm resistor
×1
LED (generic)
LED (generic)
×1
Aluminium foil Paper
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Schematic Diagram

Bill of Materials

Fritzing Files

Code

Arduino sketch for Proximity Lamp Using Arduino

Arduino
#include <CapacitiveSensor.h>

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

int in = 2; 
int out = 4;  
         

void setup()
{
  Serial.begin(9600);  // // initialize serial communication at 9600 bits per second:
  pinMode(4, INPUT);
  pinMode(9, OUTPUT);
}
void loop()                    
{
  long start = millis();
long total1 = cs_2_4.capacitiveSensor(30);  //sensor resoultion. Default 30.
                                           // increase for higher resolution, but slower performance.
Serial.print(millis() - start);           // check on performance in milliseconds
Serial.print("\t");                       //tab character for debug window spacing
Serial.println(total1);                   // print sensor output 1
delay(10);                                // arbitrary delay to limit data to serial port

 
 if(total1>=140)        // change this based on serial Monitor's output 
 {
 analogWrite(9, total1); 
 
}
else
{
  digitalWrite(9,LOW);
}

}

Credits

Amal Mathew
24 projects • 79 followers
Maker | Not much to boast about – just a human, open-source believer. Simple as that.

Comments