Line 27: Line 27:
 
==Arduino code for Breath Analyser==
 
==Arduino code for Breath Analyser==
 
<html>
 
<html>
<script src="https://gist.github.com/Xplorer001/d47aa824054672af6785.js"></script>
+
<script src="https://gist.github.com/raghavendrahassy/af23ae587fcd90b34c76.js"></script>
 
</html>
 
</html>
  

Latest revision as of 12:32, 14 October 2015

Guru (talk) 11:27, 14 October 2015 (IST)


1-1-DSC04302.JPG


Components/Boards Used

1 Explore One for Arduino
2 OLED Display Module 128X64
3 Alcohol Gas Sensor (MQ3) board


4 Mini Breadboard


5 [ 3 cell Battery Holder]

Arduino code for Breath Analyser

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
int TIME_UNTIL_WARMUP = 50; // in seconds
unsigned long time;
int analogPin = 0;
int val = 0;
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop() {
delay(100);
val = readAlcohol();
printTitle();
printWarming();
time = millis()/1000;
if(time<=TIME_UNTIL_WARMUP)
{
time = map(time, 0, TIME_UNTIL_WARMUP, 0, 100);
display.drawRect(10, 50, 110, 10, WHITE); //Empty Bar
display.fillRect(10, 50, time,10,WHITE);
}else
{
printTitle();
printAlcohol(val);
printAlcoholLevel(val);
}
display.display();
}
void printTitle()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(22,0);
display.println("Breath Analyzer");
}
void printWarming()
{
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println("Warming up");
}
void printAlcohol(int value)
{
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(45,25);
display.println(val);
}
void printAlcoholLevel(int value)
{
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10,55);
if(value<500)
{
display.println("You are sober.");
}
if (value>=500 && value<600)
{
display.println("You had a beer.");
}
/*if (value>=280 && value<350)
{
display.println("Two or more beers.");
}
if (value>=350 && value <450)
{
display.println("I smell Oyzo!");
}*/
else
{
display.println("You are drunk!");
}
}
int readAlcohol()
{
int val = 0;
int val1;
int val2;
int val3;
display.clearDisplay();
val1 = analogRead(analogPin);
delay(10);
val2 = analogRead(analogPin);
delay(10);
val3 = analogRead(analogPin);
val = (val1+val2+val3)/3;
return val;
}
view raw Breathlyser hosted with ❤ by GitHub

Downloads


References and Credits