Skip to content

Instantly share code, notes, and snippets.

@Sidchou
Last active March 24, 2020 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sidchou/dd3c076a534bbf97afabb30a3badec4c to your computer and use it in GitHub Desktop.
Save Sidchou/dd3c076a534bbf97afabb30a3badec4c to your computer and use it in GitHub Desktop.
MQ2 sensor test
/*
simple code to test MQ-2 Gas Sensor Detection Module
*/
const int digitalPin = 3;
const int analogPin = A0;
//declare input pins
void setup() {
// put your setup code here, to run once:
pinMode(digitalPin, INPUT);
pinMode(analogPin, INPUT);
//declare pinmode
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int analogReading = analogRead(analogPin);
bool digitalReading = digitalRead(digitalPin);
Serial.print(analogReading);
Serial.print("\t");
Serial.println(digitalReading);
//print sensor reading on Serial
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment