Skip to main content

interfacing alcohol sensor with the led

Programmed the Arduino to have the alcohol sensor play with the LED display.

I had the display show either "open" or "lock" depending on the alcohol sensor level.

Here is the result:



Notice that this has a very notable flaw with respect to its potential use as a "breathalyzer lock": it stays "open" as long as there is alcohol present, which only then "lock"s. This means that currently, if you leave it alone (no breathing into it), it will keep the device unlocked.

This is something I will have to resolve.


code used for this:

int del = 5000;
int gasPin = 0;
int value = 0;
int lastValue = 0;

void setup(){
//  Serial.begin(9600);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);

}

void loop(){
  lastValue = value;
  value = analogRead(gasPin)/2;
//  Serial.print("Sensor:");
//  Serial.println(value);

  if(value - lastValue > 10 || value > 400) {
    lockPrint();
  } else {
    openPrint();
  }

}

void lockPrint() {
  pickDigit(1);
  digitalWrite(8, HIGH);
  digitalWrite(1, HIGH); // A
  digitalWrite(2, HIGH); // B
  digitalWrite(3, HIGH); // C
  digitalWrite(4, LOW); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, HIGH); // G
  delayMicroseconds(del);
  pickDigit(2);
  digitalWrite(8, HIGH);
  digitalWrite(1, LOW); // A
  digitalWrite(2, LOW); // B
  digitalWrite(3, LOW); // C
  digitalWrite(4, LOW); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, HIGH); // G
  delayMicroseconds(del);
  pickDigit(3);
  digitalWrite(8, HIGH);
  digitalWrite(1, LOW); // A
  digitalWrite(2, HIGH); // B
  digitalWrite(3, HIGH); // C
  digitalWrite(4, LOW); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, HIGH); // G
  delayMicroseconds(del);
  pickDigit(4);
  digitalWrite(8, HIGH);
  digitalWrite(1, LOW); // A
  digitalWrite(2, HIGH); // B
  digitalWrite(3, LOW); // C
  digitalWrite(4, HIGH); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, LOW); // G
  delayMicroseconds(del);
}

void openPrint() {
  pickDigit(1);
  digitalWrite(8, HIGH);
  digitalWrite(1, LOW); // A
  digitalWrite(2, LOW); // B
  digitalWrite(3, LOW); // C
  digitalWrite(4, LOW); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, HIGH); // G
  delayMicroseconds(del);
  pickDigit(2);
  digitalWrite(8, HIGH);
  digitalWrite(1, LOW); // A
  digitalWrite(2, LOW); // B
  digitalWrite(3, HIGH); // C
  digitalWrite(4, HIGH); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, LOW); // G
  delayMicroseconds(del);
  pickDigit(3);
  digitalWrite(8, HIGH);
  digitalWrite(1, LOW); // A
  digitalWrite(2, HIGH); // B
  digitalWrite(3, HIGH); // C
  digitalWrite(4, LOW); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, LOW); // G
  delayMicroseconds(del);
  pickDigit(4);
  digitalWrite(8, HIGH);
  digitalWrite(1, LOW); // A
  digitalWrite(2, LOW); // B
  digitalWrite(3, LOW); // C
  digitalWrite(4, HIGH); // D
  digitalWrite(5, LOW); // E
  digitalWrite(6, LOW); // F
  digitalWrite(7, HIGH); // G
  delayMicroseconds(del);
}

void pickDigit(int x){
  digitalWrite(12, LOW); // dig 1
  digitalWrite( 11, LOW); // dig 2
  digitalWrite(10, LOW); // dig 3
  digitalWrite( 9, LOW); // dig 4

  switch(x){
    case 1: digitalWrite(9, HIGH); break;
    case 2: digitalWrite(10, HIGH); break;
    case 3: digitalWrite(11, HIGH); break;
    case 4: digitalWrite(12, HIGH); break;  
  }
}

Comments

Popular posts from this blog

duty cycle testing

Now that I saw a physical response, I should try to make it similar to how a servo should be controlled. Servos are actuators that receive (expect) position input (as opposed to motors, which receive speed/intensity input). Simply put, it registers input as pulses, decoding the ratio of high (a "on" signal) to low in a given period as a position value.  A better explanation :  http://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor/servo-motors As I am waiting for my servo to be shipped, I will continue to work with the LED light.  As opposed to my previous setup of having the light turn on every time the request is given, I will have the light turn on and off in a regular pattern until a request is given, upon which the pattern will change for one "cycle" (on-and-off pair). The on-and-off logic (previously the LED control logic) will be run in a separate thread: def dCycle(*args):    global dCVal   ...

dabbling with android

I've been wanting to dabble with Android development recently, and yesterday I realized that there is a Socket.IO client API available for Java/Android. The API is pretty straightforward, so I loaded a test Android project I had made for going through Android basics and connected to the OpenSesame Node server. and it works! I mean, the interface is non-existent and it's really just bare-bones, but having the servo respond through an Android application was pretty refreshing. (the web client and the android client "communicating" with each other--messaging is pretty much for debugging purposes)

playing with servos

some servos that I had ordered were delivered. the instructions suggested another brand/model of servos, but these were a much more economical (cheap).  I tried adding them to the hand: I'll have to print the "pulley" pieces that will be attached to the servos. meanwhile, I did somewhat (hackily) got the wrist to work, for now: you keep hearing the "usb plugged out" sound in the background, and that's because the servo was being powered by the arduino. the servo's power draw appears to be causing a shutdown of the device. will need a better power source for the servos. it feels like these pieces that are supposed to be plugged into the servo will have size issues.