Skip to content

Commit 25d3592

Browse files
committed
MQ3 Sensor with Arduino Code and Schematic
1 parent 6667ecb commit 25d3592

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

MQ3 Sensor with Arduino/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [Interfacing 16x2 LCD with Arduino](https://circuitdigest.com/microcontroller-projects/interfacing-16x2-lcd-with-arduino)
2+
3+
<img src="https://github.com/Circuit-Digest/Basic-Arduino-Tutorials-for-Beginners-/blob/d72d720d083c663016516b760d49e7d76e152fe6/Interfacing%2016x2%20LCD%20with%20Arduino/Image/16x2-LCD_Title-image.jpg" width="" alt="alt_text" title="image_tooltip">
4+
<br>
5+
6+
<br>
7+
<a href="https://circuitdigest.com/tags/arduino"><img src="https://img.shields.io/static/v1?label=&labelColor=505050&message=Arduino Basic Tutorials Circuit Digest&color=%230076D6&style=social&logo=google-chrome&logoColor=%230076D6" alt="circuitdigest"/></a>
8+
<br>
9+
10+
[<h1>Click here](https://circuitdigest.com/tags/arduino) for the complete tutorials on Arduino basics.</h1>
11+
12+
13+
<br>
14+
<br>
15+
<br>
16+
In this digital age, we come across LCDs all around us from simple calculators to smartphones, computers and television sets etc. The LCDs use liquid crystals to produce images or texts. The LCDs are categorized into different categories based on different criteria like type of manufacturing, monochrome or colour, and weather Graphical or character LCD. In this tutorial, we will be talking about the 16X2 character LCD Modules.
17+
<br>
18+
The 16x2 LCDs are very popular among the DIY community. Not only that you can also find them in many laboratory and industrial equipment. It can display up to 32 characters at a time. Each character segment is made up of 40 pixels that are arranged in a 5x8 matrix. We can create alphanumeric characters and customs characters by activating the corresponding pixels. Here is a vector representation of a 16x2 LCD, in which you can see those individual pixels.
19+
<br>
20+
[Note: As this projects are very simple we are only providing the code, schemaitic, and a few essential images if you want to get the images or code explanations do check out the Circuit Digest website.
21+
<br>
22+
<br>
23+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#define Sober 200 // Define max value that we consider sober
2+
#define Drunk 400 // Define min value that we consider drunk
3+
#define MQ3 0
4+
#define ledPin 6
5+
float sensorValue; //variable to store sensor value
6+
void setup() {
7+
Serial.begin(9600); // sets the serial port to 9600
8+
pinMode(ledPin, OUTPUT);
9+
digitalWrite(ledPin, LOW);
10+
Serial.println("MQ3 Heating Up!");
11+
delay(2000); // allow the MQ3 to warm up
12+
}
13+
void loop() {
14+
sensorValue = analogRead(MQ3); // read analog input pin 0
15+
Serial.print("Sensor Value: ");
16+
Serial.print(sensorValue);
17+
// Return analog moisture value
18+
// Determine the status
19+
if (sensorValue < Sober) {
20+
Serial.println(" | Status: Sober");
21+
} else if (sensorValue >= Sober && sensorValue < Drunk) {
22+
Serial.println(" | Status: Drinking but within legal limits");
23+
} else {
24+
Serial.println(" | Status: DRUNK");
25+
}
26+
unsigned int outputValue = map(sensorValue, 0, 1023, 0, 255);
27+
if (sensorValue > 700) {
28+
analogWrite(ledPin, outputValue); // generate PWM signal
29+
}
30+
else {
31+
digitalWrite(ledPin, LOW);
32+
}
33+
return outputValue;
34+
delay(2000); // wait 2s for next reading
35+
}
Loading
Loading
204 KB
Loading

0 commit comments

Comments
 (0)