DIY Lie Detector with Arduino Uno

This project has been a long, hard one. I used this website as a reference for my project:

The project is a simple DIY Lie Detector made with Arduino Uno and a few other easy-accessible supplies. I
started the project with the assumption that it was going to be easy, but I, being one that had never even heard of Arduino, was totally surprised.

I followed all of the instructions, and I believe I have all of the wires and resistors connected properly, but I am having a lot of trouble with Processing. I downloaded both the Arduino and Processing applications.

I used the example
File>Examples>Communication>Graph on the Arduino application and everything went fine, I believe. I think it transferred to the Arduino itself.
Then, I copied and pasted the graph example to the Processing application and there were areas that weren’t compatible with it. It said it couldn’t find “Serial.begin”. Then, I deleted a couple of lines it suggested. I ran the “fixed” code again, and when I expected a graph to appear, it didn’t. I got a tiny, blank, gray box with the sketch name on the top left, instead. I waited a few minutes, but nothing appeared.

I’m sorry this is somewhat jumbled up. I would really appreciate some help from someone who knows what they’re doing with Arduino. Thank you for your consideration.

Here’s the code:

void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  // send the value of analog input 0:
  Serial.println(analogRead(A0));
  // wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:
  delay(2);
}
// Graphing sketch


// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return

// Created 20 Apr 2005
// Updated 24 Nov 2015
// by Tom Igoe
// This example code is in the public domain.

import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph
float inByte = 0;

void setup () {
  // set the window size:
  size(400, 300);

  // List all the available serial ports
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[0], 9600);

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // set inital background:
  background(0);
}
void draw () {
  // draw the line:
  stroke(127, 34, 255);
  line(xPos, height, xPos, height - inByte);

  // at the edge of the screen, go back to the beginning:
  if (xPos >= width) {
    xPos = 0;
    background(0);
  } else {
    // increment the horizontal position:
    xPos++;
  }
}


void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }
}

*/

diy-polygraph-machine-detect-lies-with-tin-foil-wire-and-arduino.w654.jpg

Show yer code and circuit please.

ps, read "How to use this forum" (at the top of the post list) first.

Uh... yeah. Slow down, include your code, include the text of any error messages.

Read the "how to use these forums" link for information about how to include your code with code tags so we can easily read it.

Also, consider using linebreaks. Your post is a wall of text that's a little hard to follow...

void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  // send the value of analog input 0:
  Serial.println(analogRead(A0));
  // wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:
  delay(2);
}
// Graphing sketch


// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return

// Created 20 Apr 2005
// Updated 24 Nov 2015
// by Tom Igoe
// This example code is in the public domain.

import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph
float inByte = 0;

void setup () {
  // set the window size:
  size(400, 300);

  // List all the available serial ports
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[0], 9600);

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // set inital background:
  background(0);
}
void draw () {
  // draw the line:
  stroke(127, 34, 255);
  line(xPos, height, xPos, height - inByte);

  // at the edge of the screen, go back to the beginning:
  if (xPos >= width) {
    xPos = 0;
    background(0);
  } else {
    // increment the horizontal position:
    xPos++;
  }
}


void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }
}

*/

Thank you.

diy-polygraph-machine-detect-lies-with-tin-foil-wire-and-arduino.w654.jpg

Ok, I take it that you hold both of the wires while being asked questions, etc, right? Or use medical skin electrodes, that you tape to the subject? Either way should work.

What the circuit does is make the body between the two wires a resistor, which makes the second leg of a simple voltage divider. Then when the subject becomes emotional, they sweat slightly, and their skin, becoming moist, has a lower electrical resistance.

If you run the sketch, and then open the serial monitor window, you should see a rapidly scrolling list of numbers that range from 0 to 1023. If it’s always zero, or always 1023, then you need to use a different resistor, different skin contact electrodes, or both. It should change when the subject becomes emotionally excited. Accomplish that however you want.

The Graph tutorial uses Processing to display serial data on your attached computer. I never use Processing, so someone else will have to help you with that.

Okay, I'll check that out.

I may have to use different electrodes.

What do you use instead of Processing? If you don't mind my asking.

Also, thank you.

Here's a picture of the electrodes it suggested that I make. Do you think I should probably go a different route?

Destiny_34: Okay, I'll check that out.

I may have to use different electrodes.

What do you use instead of Processing? If you don't mind my asking.

Also, thank you.

Here's a picture of the electrodes it suggested that I make. Do you think I should probably go a different route?

I don't see a picture.

One moment. I've exceeded the amount that I can post within five minutes.

The pictures did not upload over a mobile device.

Here are the GSR electrodes.

diy-polygraph-machine-detect-lies-with-tin-foil-wire-and-arduino.w654 (2).jpg

Destiny_34: Here are the GSR electrodes.

I've seen several such devices. The best electrodes are metal balls that you can grab onto. Metal doorknobs work well.

What do you use instead of Processing? If you don't mind my asking.

When I need to debug or monitor the output of an Arduino device I send the result to the serial monitor. The statement, Serial.print() sends text and numbers to the serial monitor. You can open the serial monitor window by clicking the little magnifying glass icon in the top right corner of the IDE window.

Other than that, I don't send stuff to the computer for the display. If I need a display, I use indicator LEDs (there is one built into most Arduino boards, usually on pin 13), or there are a LED and LCD displays, with chips to control them - often sold bundled together on a "breakout board" that you just 'plug into' a circuit. My favorite kind of display is the monochrome OLED. I think they are really cool, and you can use a communication protocol like I2C that makes using them very easy.

Okay, I will probably be changing out the electrodes and using LEDs instead of graphs.

So, is there a code that makes LEDs respond to GSR?

Also, what code do I use just to send the results to the serial monitor? Instead of making a graph.

I really appreciate the advice.

If you upload the sketch from your first post to your Arduino (which you will have wired as in your diagram), you will see numbers scrolling. Touch the wires and see if the numbers change.

To output to LEDs, you will have to first experiment with your electrodes and the serial monitor as above. Notice what the numbers are for different conditions (excited, not excited, bored, lying, etc...) Then you can 'digitalWrite' to pins that you have an LED and 1K resistor wired to, to turn the LED on and off depending on the level you 'analogRead' from the voltage divider.

It would be a good idea to do a few of the tutorials in the Examples menu of the Arduino IDE. Like especially the one called AnalogInOutSerial. It's just like your project, but you are using someone's skin instead of a potentiometer. Don't worry, you won't even feel the 5 volts.

Oh, and PS: I don't mean to 'diss' Processing. I don't use it cause I don't know it, but I have seen some really neat stuff done with it.

Okay! Thanks for the help!

You are welcome. Please keep us posted with your progress on the project!

Quick update:

The serial monitor is repeating neither 0 nor 1023!

Destiny_34: Quick update:

The serial monitor is repeating neither 0 nor 1023!

That is a good thing! Does it change at random, or does the average change when you touch both wires?

It changes when I touch both wires, and changes when I touch just one wire.

This is much better than earlier today!

Excellent. heh.

Now you should try to quantify the response of the system. Sit comfortably for a few minutes. As a friend to sneak up on you and startle you at some random time. Try not to anticipate them. Measure the reading during the event.

These two average levels will represent the signals that will be used in the working sketch. Let's make some hypothetical data:

When resting the levels look like: 328 573 495 603 387 ... etc. if you average them they come to about 500.

When startled, the average of, let's say, 680 730 928 766 843, ... is about 800.

The difference is between the two is (let's say) 300. Over a range of 700-1000 or so 300 is significant, so it'll make good data. Wire up a circuit like this:

Then try it with a sketch like this (warning, I have not run, nor tested this sketch!)

// lie detector test

#define LED1 10
#define LED2 9
#define gsrElectrode A0

int gsrSignal = 512; // right in the middle

void setup () {
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);

  Serial.begin(9600);
}

void loop() {

  gsrSignal = analogRead(gsrElectrode);

  if (gsrSignal >= 650) { // 650 is right between 500 and 800
    analogWrite(LED1, HIGH); // show LED1 - a 'high' signal means lying
    analogWrite(LED2, LOW);
  } else {
    analogWrite(LED2, HIGH); // show LED2 - a 'low' signal means truthing
    analogWrite(LED1, LOW);
  }
}

Go from there. Take lots of data using the circuit you have now. Develop your own data,and use that. Experiment until you get a number that (mostly) works. This sketch makes no attempt to sample and average, or to adjust for individual gsr. Those are math concepts you might want to practice programming, or at least making into a step by step algorithm.

ps, if R is more than 10,000 ohms, you can touch the electrodes together to see an artificial high (lying) signal. But don’t touch them if the value of R is less than that (well, I’m including a safety margin, but …) do not short them (ie, touch them together.) It will put over-amperage stress on your Arduino board.

The allowable current of the Arduino pin is (40 milliamps for a short while. Mostly keep it under) 20 milliamps. so with a voltage of 5 volts, the resistor should be …? What. A basic tenant of electronics is called “Ohm’s Law”. Use VequalsIR to figure out the resistor to use for R, given an average GSR of …, well - google that too.

Ok, I confess, I’m developing online content for my job (administering a - relevant - community college engineering class. Win-win, eh? Or, uh, learn-learn?