Skip to content

Commit d76ed0d

Browse files
committed
added all the required files for MQ2 Gas Sensor
1 parent b347dd0 commit d76ed0d

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

Diff for: MQ2 Combustible Gas Sensor with Arduino/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Sensor pins pin D6 LED output, pin A0 analog Input
2+
#define ledPin 6
3+
#define sensorPin A0
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
pinMode(ledPin, OUTPUT);
8+
digitalWrite(ledPin, LOW);
9+
}
10+
11+
void loop() {
12+
Serial.print("Analog output: ");
13+
Serial.println(readSensor());
14+
delay(500);
15+
}
16+
17+
// This function returns the analog data to calling function
18+
int readSensor() {
19+
unsigned int sensorValue = analogRead(sensorPin); // Read the analog value from sensor
20+
unsigned int outputValue = map(sensorValue, 0, 1023, 0, 255); // map the 10-bit data to 8-bit data
21+
22+
if (outputValue > 65)
23+
analogWrite(ledPin, outputValue); // generate PWM signal
24+
25+
else
26+
digitalWrite(ledPin, LOW);
27+
return outputValue; // Return analog moisture value
28+
}
Loading
Loading
Loading

0 commit comments

Comments
 (0)