Advertisement
microrobotics

Hydrogen Gas Sensor - MQ-8

Mar 31st, 2023
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The MQ-8 is an analog gas sensor used to detect hydrogen gas concentrations. Here's a simple Arduino code to read the sensor's output and display it on the Serial Monitor:
  3.  
  4. To wire the MQ-8 sensor, connect its A0 (analog output) pin to the MQ8_PIN (analog pin A0) on the Arduino. Connect the VCC pin to the 5V pin on the Arduino and the GND pin to the ground.
  5.  
  6. This code will continuously read the sensor's output and print the raw readings and the corresponding voltage on the Serial Monitor. To convert the voltage value to hydrogen concentration in parts per million (ppm), you will need the appropriate calibration curve for the specific sensor and environmental conditions. The calibration curve can be determined experimentally by exposing the sensor to known concentrations of hydrogen gas and measuring the corresponding output voltage.
  7. */
  8.  
  9. const int MQ8_PIN = A0; // MQ-8 sensor connected to analog pin A0
  10.  
  11. void setup() {
  12.   Serial.begin(9600);
  13. }
  14.  
  15. void loop() {
  16.   int sensorValue = analogRead(MQ8_PIN);
  17.   Serial.print("Sensor Value: ");
  18.   Serial.println(sensorValue);
  19.  
  20.   // Convert the analog reading to voltage
  21.   float voltage = sensorValue * (5.0 / 1023.0);
  22.   Serial.print("Voltage: ");
  23.   Serial.print(voltage);
  24.   Serial.println(" V");
  25.  
  26.   // You can further convert the voltage value to ppm (parts per million) if
  27.   // you have the appropriate calibration curve for the specific sensor and
  28.   // environmental conditions.
  29.  
  30.   delay(1000); // Wait 1 second between readings
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement