Miission 12 - Lie Detector - Self Calibrating
 DuinoKit Essentials - View Only. See new "Mission Manual" forum for manual and code   Started by Daniel Alich   2017-06-27 21:30:50 -04:00   Comments: 1    Viewed: 913

  1. Daniel Alich
    Daniel Alich Member Staff Member
    252_1511882915_Mission 12 – Lie Detect

    /*


    The circuit:
    * LCD RS pin to A5
    * LCD Enable pin A4
    * LCD D4 pin to A3
    * LCD D5 pin to A2
    * LCD D6 pin to A1
    * LCD D7 pin to A0
    * LCD R/W pin to ground
    * 10K resistor:
    * ends to +5V and ground
    * wiper to LCD VO pin (pin 3)

    */

    int redPin = 9;
    int greenPin = 10;
    int bluePin = 11;

    int buzzerPin = 6;

    int sensorPin = A7;
    int i;
    int base=5;

    int band = 5; // adjust for sensitivity
    boolean inGame;

    // include the library code:
    #include <LiquidCrystal.h>
    #include <Tone.h>

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(A5, A4, A3, A2, A1, A0);
    // ( RS, E, D4, D5, D6, D7)


    void setup()
    {
    pinMode(sensorPin, INPUT);
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    pinMode(buzzerPin, OUTPUT);
    Serial.begin(9600); //Turn on serial monitor to observe values
    lcd.begin(16, 2);
    lcd.clear();

    }
    void loop()
    {
    int gsr = 0; //analogRead(sensorPin);
    int sum = 0; //analogRead(sensorPin);

    for(i=0; i < 10; i++) // Take i readings of A0 pin
    {
    delay (75); // Place a small delay between reading
    gsr=gsr+analogRead(sensorPin);
    // sum = sum+gsr;
    // Serial.print (gsr);
    // Serial.print (" ");
    }

    gsr=gsr/i; // Get avg gsr value


    Serial.print("base ");
    Serial.print(base);
    Serial.print(" gsr ");
    Serial.println(gsr);




    if (gsr > base + band)
    {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
    lcd.clear();
    lcd.setCursor(8, 1);
    lcd.print("WARNING!") ;

    beep();

    }
    else if (gsr < base - band)
    {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
    lcd.clear();
    lcd.print("Calibrating...");

    }
    else if (gsr < 4) // Connections poor. Trun off LED
    {

    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
    lcd.clear();
    lcd.print("Lie Detector...");
    lcd.setCursor(0, 1);
    lcd.print("Grasp Sensor!") ;
    // inGame=true;
    // delay(1500);



    }
    else {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
    digitalWrite(bluePin, LOW);
    lcd.clear();
    lcd.print("Ask Questions");
    lcd.setCursor(0, 1);
    lcd.print("Now...") ;

    }

    if (gsr > base) // These next few lines will adjust the base reading throught test.
    {
    base=base+1; // Raise base setting
    if (abs(gsr-base)>6) {
    base=base+abs((gsr-base)/2); // Adjust base value quickly for large difference
    lcd.clear();
    lcd.print("Calibrating...");
    }


    }
    else if (gsr < base)
    {
    base=base-1; // Lower base setting
    if (abs(gsr-base)>6) {
    base=base-abs((gsr-base)/2); // Adjust base value quickly for large difference

    lcd.clear();
    lcd.print("Calibrating...");
    }
    }
    }
    void beep()
    {
    for (int i=0; i<1000; i++)
    {
    digitalWrite(buzzerPin, HIGH);
    delayMicroseconds(100);
    digitalWrite(buzzerPin, LOW);
    delayMicroseconds(100);

    }
    }
    Daniel Alich, 2017-06-27 21:30:50 -04:00
  2. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!