Metal touch sensor, KY036

Download the sketch from my GitHub here.

This seems to be a switch known as an AC hum switch. When you touch the bare wire folded over the end of the transistor mains hum present all around us in a modern house or office is injected into a high gain amplifier. The output of this amplifier is connected to a comparator ic such as an LM358 and the induced AC signal is converted to a square wave as the AC sine wave switches the comparator. The level that switches the circuit is set by the small blue variable resistor and when the output is switched on a LED is lit. If you look carefully at the LED while it is on it appears to be almost flickering rather than steadily lit. This is due to the output being a 50 Hz square wave rather than a steady HIGH voltage.

A typical AC hum detector is shown here.


The output from the DO pin could be simply connected to any Arduino Digital pin and, say, the onboard LED switched on when the signal goes HIGH. However, the 50 Hz square wave output will be constantly switching the LED on and off. The sketch below overcomes this by latching the output ON the first time the signal goes HIGH and stays that way until the sensor is touched again, turning the output OFF.

This shows the squarewave output from DO (AO seems to be an inverted version of DO).

scope

The AC hum switch is an interesting circuit but has a number of disadvantages and if you need a touch switch then it is better to use a Capacitance touch switch, that does not rely on a nearby mains wiring being available. I really can’t see any time I would use this little board, but it was good fun getting it to work.

/*******************************************************
KY036 Metal Touch Sensor
Connect;
AO to Arduinp pin A3
DO to Arduino pin 2
G to Arduino Gnd
Vcc to Arduino 5v
*******************************************************/


// setup touch sensor on pin 2
const int touchPin = 2;
// setup LED on pin 13
const int ledPin = 13;
// store thetime when the last event happened
unsigned long lastEvent = 0;
// store the state of the LED
boolean ledOn = false;
void setup() {
// setup pins
pinMode(touchPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
// read the touch sensor state
int touchState = digitalRead(touchPin);
// only interested in HIGH
if(touchState == HIGH){
// if 50ms have passed since the last HIGH pulse
// touch sensor has been touched or released
if(millis() - lastEvent >50){
// toggle LED and set the output
ledOn = !ledOn;
digitalWrite(ledPin, ledOn ? HIGH : LOW);
}
// remember when the last event happened
lastEvent = millis();
}
}

Advertisements

1 thought on “Metal touch sensor, KY036”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s