engineer2you
Published © CC BY

Gas detector CO & CH4

This project guide how to make portable gas detector CO & CH4

IntermediateFull instructions provided196
Gas detector CO & CH4

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Axial Fan, 12 V
Axial Fan, 12 V
×1

Story

Read more

Schematics

Gas detector circuit

Code

Gas detector

Arduino
///Arduino Sample Code
#include <Adafruit_GFX.h>       // Include core graphics library for the display
#include <Adafruit_SSD1306.h>   // Include Adafruit_SSD1306 library to drive the display
#include <Fonts/FreeMonoBold18pt7b.h>  // Add a custom font
#include <Fonts/FreeMono9pt7b.h>  // Add a custom font

Adafruit_SSD1306 display(128, 64);            //Create display


void setup()
{
  Serial.begin(9600); //Set serial baud rate to 9600 bps

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // Initialize display with the I2C address of 0x3C
  display.clearDisplay();  // Clear the buffer
  display.setTextColor(WHITE);  // Set color of the text
  
}
void loop()
{
  double val;
  val=analogRead(0);//Read Gas value from analog 0; value 0~1023
  val=(val/1023)*100;
  Serial.println(val,DEC);//Print the value to serial port
  delay(300);

  display.clearDisplay();  // Clear the display so we can refresh

  // Print text:
  display.setFont(&FreeMono9pt7b);
  display.setCursor(45,20);  // (x,y)
  display.println("GAS");  // Text or value to print

  // Print temperature
  char string[10];  // Create a character array of 10 characters
  // Convert float to a string:
  dtostrf(val, 3, 0, string);  // (<variable>,<amount of digits we are going to use>,<amount of decimal digits>,<string name>)
  
  display.setFont(&FreeMonoBold18pt7b);  // Set a custom font
  display.setCursor(20,50);  // (x,y)
  display.println(string);  // Text or value to print
  display.setCursor(90,50);  // (x,y)
  display.println("%");  // Text or value to print


  display.display();  // Print everything we set previously

  
}

Credits

engineer2you
24 projects • 93 followers
i'm mechatronics engineer who loves making funny project and sharing for you. See me at: https://www.youtube.com/c/engineer2you

Comments