0

So I am making a Mq135 sensor and the wiring can be found on: circuit.io/app?components=9443,200000,398790 It isn't shown but the AO is connected to channel0 via the breadboard

the code is :

#!/usr/bin/python
import spidev
import RPi.GPIO as GPIO
import time
import sys
import math


spi = spidev.SpiDev()  # create spi object
spi.open(0, 0)  # open spi port 0, device (CS) 0, for the MCP8008
spi.max_speed_hz=100000 # !!!

def readadc(adcnum):  # read out the ADC
    if ((adcnum > 7) or (adcnum < 0)):
        return -1
r = spi.xfer2([1, (8 + adcnum) << 4, 0])
adcout = ((r[1] & 3) << 8) + r[2]
return adcout


while True:
  adc = readadc(0)
v = adc * (3.3 / 1023.0)  # Convert value to voltage
ppm=3.027*math.exp(1.0698*(v)) 
print(str(ppm)+" ppm "+str(v)+" voltage "+str(adc) + " value")
print (ppm)
time.sleep(1)

So the problem I am having is that, it outputs a value of around 3.93...ppm and this is whilst it is placed outside a window. I read the datasheet but i'm unsure if this is correct. surely a ppm of 3. something value cannot be correct for the outside?

is there something wrong with my code or wiring?

all help is appreciated. thanks in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.