3

I am working on a gas/fire detector project using a Raspberry Pi 2. I would like to gather input from the following sensors:

Adafruit AM2302 (wired DHT22) temperature-humidity sensor
MQ-2 Gas Sensor
MQ-7 Gas Sensor
Universal Sensor 595391 (IR flame sensor)

For the last 3 sensors (which require an analogue input) I have also purchased an MCP3008 analogue to digital converter. Right now I have the AM2302 hooked up and recording temperature/humidity data through wiringPi and storing it in MySQL.

I would like to add the other 3 sensors and record data through wiringPi to be stored in MySQL, but I have had a lot of trouble finding anything about whether or not these 5V sensors will need a voltage divider before connecting to the MCP3008.

When reading the datasheet for the MCP3008 the specifications say that the chip can operate with a power level between 2.7 to 5.5 volts, but I am not sure if the output to the Pi's GPIO pin will exceed 3.3 volts and cook it if the MCP3008 is hooked up to 3 sensors running 5 volts.

I have also read that the MQ-X sensors or at least the MQ-7 can run on 3.3 volts which runs contrary to its data sheet - see Digital sensors and the Raspberry Pi with the smoke detector MQ-X as example.

My question is: How should I connect these sensors to be used on the Raspberry Pi 2 in order to be read through wiringPi?

I am new to working with Raspberry Pi GPIO so any help would be greatly appreciated.

4

If the smoke sensors output up to 5V it is best to power the MCP3008 from 5V.

Of the connections between the Pi and the 5V MCP3008 MOSI, SCLK, and CEx are Pi outputs and the MCP3008 will be happy with the Pi's 3V3 signals.

The only connection to be concerned about is MISO from the MCP3008 to the Pi. This will be 5V and as such is too much for the Pi's 3V3 gpio. The simplest and safest solution is to use a pair of resistors as a voltage divider to drop the 5V to a Pi safe 3V3.

  • The simplest solution would be using a voltage divider. The safest solution would involve using a proper level-shifting arrangement using transistors. But yeah, what you said. – WineSoaked Aug 11 '15 at 3:08
  • @WineSoaked Interesting. From a non electronics view point I have always assumed a purely passive solution (e.g. resistors) would be inherently safer than an active solution (e.g. transistors). What is it about using transistors that makes it safer? – joan Aug 11 '15 at 9:43
  • So far the voltage divider has worked perfectly! However I am still trying to setup wiringPi correctly for the MCP3008 so I can't say if the data is coming in correctly yet, but I can report that the Pi hasn't been cooked! – user2395126 Aug 12 '15 at 20:34
  • I used this tutorial (shaunsbennett.com/piblog/?p=266) to get the code working. The only other thing I needed to do hardware-wise was connect the chip select (CS) pin from the MCP3008 to GPIO 8 on the Pi 2. Thanks for the excellent answer! – user2395126 Aug 15 '15 at 15:27

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.