-
Notifications
You must be signed in to change notification settings - Fork 0
/
breath.ino
69 lines (63 loc) · 1.85 KB
/
breath.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Breathalyser Circuit using the following items:
* 1. An Arduino Nano (AtMega 328P).
* 2. MQ-3 Ethanol sensor
* 3. Single red LED
*
* This is all pre-calibration so one of the main bugs currently need
* attention is the LED lights on detection of ethanol and goes out when
* ethanol removed.
*
* However the analogue sensor is detecting correctly.
*
* @TODO: Add extra sensors such as toxic gases and CO then finally a buzzer for local alarm functionality.
*/
/**
* The digital and analog pins of the sensor ad where they go on the Arduino * Nano
*/
const int DOUTpin=8;
const int AOUTpin=0;
//The digital pin assigned to the LED output
const int ledPin=13;
int limit;
int sensorValue;
/**
* Setting up serial caud rate as 115200
* Setting the pinMode for pin 8 to INPUT (it will recieve 1 or 0 dependent on
* alcohol dtection)
* Setting digital pin 13 as the OUTPUT pin for the LED to show if ethanol is
* detected.
*/
void setup() {
Serial.begin(115200);
pinMode(DOUTpin, INPUT);
pinMode(ledPin, OUTPUT);
}
/**
* Main loop which constantly draws a reasing from the analog pinf of the
* sensor and outputs this to the Serial Monitor.
*
* @TODO output readings to LCD or LED display
* @TODO calibrate using a friend with different units of alcohol to get the
* best callibration level on the potentiometer on the sennsors rear.
* @TODO Refactor method to make more DRY
*/
void loop()
{
sensorValue = analogRead(AOUTpin);
limit = digitalRead(DOUTpin);
Serial.print("Alcohol sensorValue: ");
Serial.println(sensorValue);
delay(100);
if (limit == HIGH){
Serial.print("Detetcted Alcohol: ");
Serial.print(limit);
Serial.println("\n");
digitalWrite(ledPin, HIGH);
} else {
Serial.print("No Detetcted Alcohol");
Serial.print(limit);
Serial.println("\n");
digitalWrite(ledPin, LOW);
}
}