Advertisement
Guest User

Ammonia Gas Sensor Code (PPM)

a guest
Apr 1st, 2020
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #define RL 1 //I only used 1K instead of 47K
  2. #define m_136 -0.2519296225 //Enter calculated Slope
  3. #define b_136 -0.2299293912 //Enter calculated intercept
  4. #define Ro_136 9 //Enter found Ro value
  5. #define MQ_sensor_136 A0 //Sensor is connected to A0
  6.  
  7. void setup() {
  8.   Serial.begin(9600);
  9. }
  10.  
  11. void loop() {
  12.   float VRL_136; //Voltage drop across the MQ sensor
  13.   float Rs_136; //Sensor resistance at gas concentration
  14.   float ratio_136; //Define variable for ratio
  15.  
  16.   VRL_136 = analogRead(MQ_sensor_136)*(5.0/1023.0); //Measure the voltage drop and convert to 0-5V
  17.   Rs_136 = ((5.0*RL)/VRL_136)-RL; //Use formula to get Rs value
  18.   ratio_136 = Rs_136/Ro_136; // find ratio Rs/Ro
  19.  
  20.   float ppm_136 = pow(10, ((log10(ratio_136)-b_136)/m_136)); //use formula to calculate ppm
  21.  
  22.   Serial.println(ppm_136);
  23.   delay(5000);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement