Sei sulla pagina 1di 6

RESUMEN

El método capacitiveSensor conmuta un pin de envío del microcontrolador a


un nuevo estado y luego espera a que el pin de recepción cambie al mismo
estado que el pin de envío. Una variable se incrementa dentro de un bucle while
a tiempo el cambio de estado del pin de recepción. El método entonces informa
el valor de la variable, que está en unidades arbitrarias. La configuración física
incluye una resistencia de medio a alto valor (100 kilohm - 50 megohm) entre el
pin de envío y el pin de recepción (sensor). El pin de recepción es el terminal del
sensor. Un cable conectado a este pin con una hoja de papel en el extremo hace
un buen sensor. Para muchas aplicaciones, se obtiene un rango de valores más
útil si el sensor está cubierto con papel, plástico u otro material aislante, de modo
que los usuarios no toquen realmente la lámina metálica. La investigación ha
demostrado que un condensador pequeño (100 pF) o así de la clavija del sensor
a la tierra mejora la estabilidad y la repetibilidad.
Cuando el pin de envío cambia de estado, eventualmente cambiará el estado
del pin de recepción. El retardo entre el cambio de pasador de envío y el cambio
de pasador de recepción se determina mediante una constante de tiempo RC,
definida por R * C, donde R es el valor de la resistencia y C es la capacitancia
en la clavija de recepción, más cualquier otra capacitancia (por ejemplo,
Interacción del cuerpo humano) presente en el pasador del sensor (recepción).
Para el cálculo del tiempo del descarga esta puede ser obtenida mediante la

siguiente ecuación donde Vo, R y C son conocidos, y C representa


una pequeña capacitancia entre (40-100)pF dada por el cuerpo al tocar el pin de
recepción y por el circuito en cuestión, por otro lado sabemos que V o= 5V luego
empieza el ciclo de descarga, cuando el pin de recepción llegue al valor del pin
de envió esta lectura será tomada para posteriormente ejecutar la acción
deseada, que en este caso es el sonar de una nota musical.
SIMULACION EN PROTEUS 8 ESQUEMA
CODIGO

Created by:

Hai Seng || Junny 07 November 2013

Edit by Javier Peres December 8, 2016

// Import the CapacitiveSensor Library.

#include <CapacitiveSensor.h>

// Name the pin as led.

#define speaker 11

// Set the Send Pin & Receive Pin.

CapacitiveSensor noteDo = CapacitiveSensor(2,3); // 10M resistor between pins 4 & 2, pin


2 is sensor pin, add a wire and or foil if desired

CapacitiveSensor noteDo_ = CapacitiveSensor(2,4);

CapacitiveSensor noteRe = CapacitiveSensor(2,5); // 10M resistor between pins 4 & 6, pin


6 is sensor pin, add a wire and or foil

CapacitiveSensor noteRe_ = CapacitiveSensor(2,6);

CapacitiveSensor noteMi = CapacitiveSensor(2,7); // 10M resistor between pins 4 & 8, pin


8 is sensor pin, add a wire and or foil

CapacitiveSensor noteFa = CapacitiveSensor(2,8); // 10M resistor between pins 4 & 8, pin


8 is sensor pin, add a wire and or foil

CapacitiveSensor noteFa_ = CapacitiveSensor(2,9);

CapacitiveSensor noteSol = CapacitiveSensor(2,10); // 10M resistor between pins 4 & 8,


pin 8 is sensor pin, add a wire and or foil

CapacitiveSensor noteSol_ = CapacitiveSensor(2,12);

CapacitiveSensor noteLa = CapacitiveSensor(2,13); // 10M resistor between pins 4 & 8,


pin 8 is sensor pin, add a wire and or foil

CapacitiveSensor noteLa_ = CapacitiveSensor(2,14);

CapacitiveSensor noteSi = CapacitiveSensor(2,15); // 10M resistor between pins 4 & 8, pin


8 is sensor pin, add a wire and or foil

CapacitiveSensor noteDo_oct = CapacitiveSensor(2,16);

void setup()

{
noteDo.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as
an example

// Arduino start communicate with computer.

Serial.begin(9600);

void loop()

// Set a timer.

long start = millis();

// Set the sensitivity of the sensors.

long ValueDo = noteDo.capacitiveSensor(30);

long ValueDo_ = noteDo_.capacitiveSensor(30);

long ValueRe = noteRe.capacitiveSensor(30);

long ValueRe_ = noteRe_.capacitiveSensor(30);

long ValueMi = noteMi.capacitiveSensor(30);

long ValueFa = noteFa.capacitiveSensor(30);

long ValueFa_ = noteFa_.capacitiveSensor(30);

long ValueSol = noteSol.capacitiveSensor(30);

long ValueSol_ = noteSol_.capacitiveSensor(30);

long ValueLa = noteLa.capacitiveSensor(30);

long ValueLa_ = noteLa_.capacitiveSensor(30);

long ValueSi = noteSi.capacitiveSensor(30);

long ValueDo_oct = noteDo_oct.capacitiveSensor(30);

Serial.print(millis() - start); // check on performance in milliseconds

Serial.print("\t"); // tab character for debug windown spacing

Serial.print(ValueDo); // print sensor output 1

Serial.print("\t"); // Leave some space before print the next output


Serial.print(ValueDo_); // print sensor output 1

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueRe); // print sensor output 2

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueRe_); // print sensor output 2

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueMi); // print sensor output 3

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueFa); // print sensor output 4

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueFa_); // print sensor output 4

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueSol); // print sensor output 5

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueSol_); // print sensor output 5

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueLa); // print sensor output 6

Serial.print("\t"); // Leave some space before print the next output

Serial.print(ValueLa_); // print sensor output 6

Serial.print("\t"); // Leave some space before print the next output

Serial.println(ValueSi); // print sensor output 7

// "println" - "ln" represent as "line", system will jump to next line after
print the output.

Serial.print(ValueDo_oct); // print sensor output 1

Serial.print("\t"); // Leave some space before print the next output

// When hand is touched the sensor, the speaker will produce a tone.

// I set a threshold for it, so that the sensor won't be too sensitive.

if (ValueDo > 150) tone(speaker,523);

if (ValueDo_ > 150) tone(speaker,554);

if (ValueRe > 150) tone(speaker,587);

if (ValueRe_ > 150) tone(speaker,622);


if (ValueMi > 150) tone(speaker,659);

if (ValueFa > 150) tone(speaker,698);

if (ValueFa_ > 150) tone(speaker,740);

if (ValueSol > 150) tone(speaker,784);

if (ValueSol_ > 150) tone(speaker,830);

if (ValueLa > 150) tone(speaker,880);

if (ValueLa_ > 150) tone(speaker,932);

if (ValueSi > 150) tone(speaker,988);

if (ValueDo_oct > 150) tone(speaker,1047);

// When hand didn't touch on it, no tone is produced.

if (ValueDo<=150 & ValueDo_<=150 & ValueRe<=150 & ValueRe_<=150 & ValueMi<=150 &
ValueFa<=150 & ValueFa_<=150 & ValueSol<=150 & ValueSol_<=150 & ValueLa<=150 &
ValueLa_<=150 & ValueSi<=150 & ValueDo_oct<=150)

noTone(speaker);

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

Potrebbero piacerti anche