2

I'm trying to get this CO2 sensor to work with a Pi 3B:

http://www.dfrobot.com/index.php?route=product/product&path=36_85&product_id=1023#.V1efIFUrLb0

This seems like it should be simple, but it's not exactly plug and play the way it is with an Arduino.

Is there a way for this to go directly to the Pi, or does it have to go through the Arduino first?

I'm trying to write a Python script that will pull the sensor's readings and do things based on those readings.

Sorry for this basic-seeming question, I've just never tried to do Arduino stuff with a Pi before! Thank you in advance for any advice you might have.

  • 1
    This appears to be an analog sensor. If you want to use it on the Pi you will need an ADC, because the Pi has no analog inputs. – Milliways Jun 8 '16 at 5:22
5

To read this sensor on the Pi, you can use one of two methods.

First of all, you could have Arduino read the sensor and send the readings back to the Raspberry Pi, over a connection, either I2C, Serial or USB. For an example of the USB method, check out Simon Monk's blog at: http://www.doctormonk.com/2012/04/raspberry-pi-and-arduino.html Be aware that if you use a pin-to-pin connection, you might need a level converter in there somewhere to make sure that the Arduino's 5V is not transmitted to the Pi's 3v3 pin logic.

Alternatively, you could connect up an analog to digital converter and communicate with the chip over SPI. There are a number of blog posts out there, but the first one to look at is over at Raspberry Pi Spy - http://www.raspberrypi-spy.co.uk/2013/10/analogue-sensors-on-the-raspberry-pi-using-an-mcp3008/ This will give you a clear example of how to wire up the chip. If you don't want to wire up the chip yourself, I recommend the RasPiO Analog Zero board which has just gone on pre-order (and will be available very soon otherwise I wouldn't have mentioned it!) at http://rasp.io/analogzero You might need a voltage divider to take the 5V output of the gas sensor down to 3V3. However, in my experience of using multiple gas sensors with the same analog-to-digital chip, you can just put the 5V of the gas sensor into the MCP3008 and the Pi will be fine.

If you are going to use an analog-to-digital converter, take a look at Alex Eames' blog post here: http://raspi.tv/2016/using-mcp3008-to-measure-temperature-with-gpio-zero-and-raspio-pro-hat He takes you through using the GPIO Zero library (http://gpiozero.readthedocs.io) to read an analog sensor through an MCP3008.

Circuit diagram for the MCP 3008 from Raspberry Pi Spy

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.