/* Project Title- DIY WATER TOUCHPAD
Author- Sumit Aich
Project Summary- The basic idea behind this sensor is the use of a parallelopiped water container
as a water potentiometer device. It is similar to a 3-pin slide pot used in electronic circuits,
with the 2 aluminium electrodes equivalent to the 2 end pins of a slide pot,
and the right index fingertip is equivalent to the middle pin (voltage output) of a slide potentiometer.
*/
#define ELECTRODE_0 2 //left water electrode
#define ELECTRODE_1 3 //right water electrode
#define SENSOR_ADC 0 //right index fingertip (Vout of water potentiometer)
#define OFFSET_0 1 //left offset pin
#define OFFSET_1 2 //right offset pin
#define BAUDRATE 2000000
long offset_0, //voltage at left offset pin
offset_1, //voltage at right offset pin
read_0, //fingertip voltage
m, m1; //horizontal displacement of fingertip from OFFSET_0 pin (range from 0 to 50000)
void setup() {
pinMode(ELECTRODE_0, OUTPUT);
pinMode(ELECTRODE_1, OUTPUT);
//set both water electrodes to +5V to pause electrolysis for a while
digitalWrite(ELECTRODE_0, 1);
digitalWrite(ELECTRODE_1, 1);
Serial.begin(BAUDRATE);
analogReference(DEFAULT);
}
void loop() {
//Phase 1
//swap polarity of voltage drop across water
digitalWrite(ELECTRODE_0, 0);
offset_0 = analogRead(OFFSET_0);
offset_1 = analogRead(OFFSET_1);
read_0 = analogRead(SENSOR_ADC);
//check whether fingertip is inside or outside water
digitalWrite(ELECTRODE_0, 1);
if (analogRead(SENSOR_ADC) != 1023)
{
m = 51000;
}
else {
m = constrain((50000 * (read_0 - offset_0) / (offset_1 - offset_0)), 0, 50000);
}
Serial.print('$');//format requirement for SerialPortPlotter.exe
Serial.print(m);//print horizontal displacement of fingertip from OFFSET_0 pin (range from 0 to 50000)
Serial.println('\;');//format requirement for SerialPortPlotter.exe
/*this delay is just a frequency restriction imposed by SerialPortPlotter.exe
otherwise, it is not required if you are NOT using SerialPortPlotter.exe.
*/
delay(10);
//Phase 2
//swap polarity of voltage drop across water
digitalWrite(ELECTRODE_1, 0);
offset_0 = analogRead(OFFSET_0);
offset_1 = analogRead(OFFSET_1);
read_0 = analogRead(SENSOR_ADC);
//check whether fingertip is inside or outside water
digitalWrite(ELECTRODE_1, 1);
if (analogRead(SENSOR_ADC) != 1023)
{
m = 51000;
}
else {
m1 = constrain((50000 * (offset_0 - read_0) / (offset_0 - offset_1)), 0, 50000);
}
Serial.print('$');//format requirement for SerialPortPlotter.exe
Serial.print(m);//print horizontal displacement of fingertip from OFFSET_0 pin (range from 0 to 50000)
Serial.println('\;');//format requirement for SerialPortPlotter.exe
/*this delay is just a frequency restriction imposed by SerialPortPlotter.exe
otherwise, it is not required if you are NOT using SerialPortPlotter.exe.
*/
delay(10);
}