Advertisement
pleasedontcode

Sensor Display rev_01

Jan 11th, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Sensor Display
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-11 08:20:49
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* To make arduino uno on and collect mq2, mq4, */
  21.     /* mq7,mq135 values and display in 16x2 lcd screen, */
  22.     /* and also sent those values to blynk iot */
  23.     /* application through esp8266 wifi module */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Arduino.h>
  28. #include <Wire.h>
  29. #include <MQ135.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF I2C PINS *****/
  36. const uint8_t Hii_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  37. const uint8_t Hii_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  38. const uint8_t Hii_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. MQ135 mq135_sensor(A2); // Instantiate MQ135 object
  42.  
  43. float temperature = 21.0;
  44. float humidity = 25.0;
  45.  
  46. void setup(void)
  47. {
  48.     // put your setup code here, to run once:
  49.     Serial.begin(9600);
  50.     // Initialize LCD screen
  51.     Wire.begin();
  52.     Wire.beginTransmission(Hii_LCD1602I2C_I2C_SLAVE_ADDRESS);
  53.     Wire.write(0x00);
  54.     Wire.endTransmission();
  55. }
  56.  
  57. void loop(void)
  58. {
  59.     // put your main code here, to run repeatedly:
  60.     float rzero = mq135_sensor.getRZero();
  61.     float correctedRZero = mq135_sensor.getCorrectedRZero(temperature, humidity);
  62.     float resistance = mq135_sensor.getResistance();
  63.     float ppm = mq135_sensor.getPPM();
  64.     float correctedPPM = mq135_sensor.getCorrectedPPM(temperature, humidity);
  65.  
  66.     Serial.print("MQ135 RZero: ");
  67.     Serial.print(rzero);
  68.     Serial.print("\t Corrected RZero: ");
  69.     Serial.print(correctedRZero);
  70.     Serial.print("\t Resistance: ");
  71.     Serial.print(resistance);
  72.     Serial.print("\t PPM: ");
  73.     Serial.print(ppm);
  74.     Serial.print("\t Corrected PPM: ");
  75.     Serial.print(correctedPPM);
  76.     Serial.println("ppm");
  77.  
  78.     // Display values on LCD screen
  79.     Wire.beginTransmission(Hii_LCD1602I2C_I2C_SLAVE_ADDRESS);
  80.     Wire.write(0x80); // Set cursor to first line
  81.     Wire.write("MQ135 RZero: ");
  82.     Wire.write(String(rzero).c_str());
  83.     Wire.write("\t Corrected RZero: ");
  84.     Wire.write(String(correctedRZero).c_str());
  85.     Wire.write("\t Resistance: ");
  86.     Wire.write(String(resistance).c_str());
  87.     Wire.write("\t PPM: ");
  88.     Wire.write(String(ppm).c_str());
  89.     Wire.write("\t Corrected PPM: ");
  90.     Wire.write(String(correctedPPM).c_str());
  91.     Wire.endTransmission();
  92.  
  93.     delay(300);
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement