Arduino 101: Alcohol sensor circuit using MQ-3 module
What Will I Learn?
- You will learn how to use an alcohol sensor with the arduino uno.
- You will learn the working principle of how alcohol sensor works.
- You will learn how digital input and output works and be able to program the arduino board.
Requirements
Hardware
Software
- Arduino Software / Arduino IDE
Knowledge
- Basic electronics and programming knowledge
Difficulty
- Basic
Project description
In this project we will be using an MQ-3 alcohol sensor to measure the amount of alcohol in one's breath. This sensor is very sensitive to ethanol, which is a type of alcohol that is found in every alcoholic beverages like beer, liquor and wine. This circuit can be used as a breath analyzer to check the person's alcohol level.
Component description
Arduino Uno - a board that is produced by arduino and it is the most regularly utilized by specialist/hobbyist due to its robust and strong outline. It is packed with a microcontroller board that depends on ATMega328P with 14 advanced I/O pins (6 are PWM outputs), 6 analog inputs, 16 Mhz quartz crystal, a power jack, a USB port, an ICSP header and a reset button.
MQ-3 alcohol sensor - Just like a common breath analyzer, this sensor is suitable in detecting alcohol concentration present in the breath. This device has high sensitivity and fast response time, so it can take the measurements as fast as possible.
Tutorial Contents
Step 1: Gather the parts
- You can buy the components at your local electronics shop or order it up online.
Step 2: Construct the circuit
Connect the sources
- Connect the 5V pin of the arduino uno board into the top/bottom row of the breadboard (the connections here are horizontally connected).
- Connect the GND pin of the arduino uno board into the top/bottom row of the breadboard.
- Note: Make sure not to short them out to avoid damage.
Connect the sensor
- Connect the +5 volts pin of the alcohol sensor to the positive terminal in the breadboard.
- Connect the GND pin of the alcohol sensor to the negative terminal in the breadboard.
- Connect the analog output pin of the alcohol sensor to analog pin number 0 in the arduino board.
- Connect the digital output pin of the alcohol sensor to pin number 8 of the arduino uno board.
Connect the LED
- Connect the anode(+) of the LED to pin number 13 of the arduino.
- Connect the cathode(-) of the LED to the GND pin of the arduino.
Step 3: Programming
Connect the arduino board to the computer by using the USB type a to b cable.
Image sourceOpen the arduino IDE and then head to Tools > Board : > then select Arduino/Genuino Uno.
Copy the codes below and paste it into your sketch in arduino IDE.
const int Apin=0; //sets the Analog pin of the alcohol sensor into analog pin A0 of the arduino
const int Dpin=8; //sets the Digital pin of the alcohol sensor into digital pin D8 of the arduino
const int ledPin=13;//sets the anode of the LED to digital pin D13 of the arduino
int limit;
int value;
void setup() {
pinMode(Dpin, INPUT); //sets the pin as an input to the arduino
pinMode(ledPin, OUTPUT); //sets the pin as an output of the arduino
}
void loop()
{
value= analogRead(Apin);//reads the analaog value from the alcohol sensor's AOUT pin
limit= digitalRead(Dpin);//reads the digital value from the alcohol sensor's DOUT pin
if (limit == HIGH){
digitalWrite(ledPin, HIGH);//if limit has been reached, LED turns on as status indicator
}
else{
digitalWrite(ledPin, LOW);//if threshold not reached, LED remains off
}
}
What this code does is very simple, first it declares the pins of the alcohol sensor and LED as
cons int
meaning it will be a read-only variable and cannot be changed. Then it sets up the Dpin as the input and the ledpin as the output. This will read the data from the alcohol sensor and the LED will indicate the output. In the loop setup, it will read the Apin of the alcohol sensor in integer values, it would also read the data from Dpin and store those values into the integer limit. The numeric values will be ranging from 0 (no alcohol) - 1023 (maximum level of alcohol), if the alcohol intake detected is under the threshold level, the value would be a LOW but If the alcohol intake is detected above the threshold, the value would be a HIGH thus turning ON the LED.
- After typing the code into your arduino IDE, click the Verify button to save it and start compiling the sketch.
- Once there is no errors found in the code, click Upload to install the program into the arduino uno board.
Step 4: Testing
- Once the installation has been completed, remove the arduino uno from your computer and connect some battery packs to it to activate the circuitry.
- Now test it to someone who just had a booze, let him breath to the sensor. If he's alcohol intake is high enough this should light up the LED but if not, the LED will stay OFF.
- If none is working, redo the previous steps carefully and make sure to follow it.
Curriculum
Here are some of my arduino tutorials that you may also like:
- Arduino 101: Using 2 ultrasonic sensors and servo motor
- Arduino 101: Automated parking gate circuit using ultrasonic and servo motor
- Arduino 101: Motion activated Servo motor with Arduino
- Arduino 101: PIR based burglar alarm with Piezoelectric buzzer and Arduino
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Thank you😁
Hey @ted7 I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x