Skip to main content

mcp3008

8-channel 10-bit ADC for reading multiple analog sensors via SPI interface.

Overview

The mcp3008 node reads analog voltages using the MCP3008 8-channel ADC via SPI. This affordable chip provides 10-bit resolution across 8 channels, making it ideal for reading multiple analog sensors like potentiometers, light-dependent resistors (LDRs), and analog temperature sensors.

10-bit
Resolution (1024)
8
Channels
200 ksps
Sample Rate
SPI
Interface

Wiring

MCP3008 to Pi

VDD → 3.3V

VREF → 3.3V

AGND → GND

DGND → GND

CLK → GPIO 11 (SCLK)

DOUT → GPIO 9 (MISO)

DIN → GPIO 10 (MOSI)

CS → GPIO 8 (CE0)

Enable SPI

sudo raspi-config
# Interface Options → SPI → Enable

# Verify:
ls /dev/spi*
# Should show /dev/spidev0.0

Properties

Property Type Default Description
channel number/string 0 Channel (0-7) or "all"
device string "/dev/spidev0.0" SPI device path
vref number 3.3 Reference voltage for calculation
interval number 1000 Reading interval (ms)

Output

Single Channel
{
  "payload": 2.15,
  "channel": 0,
  "raw": 667,
  "voltage": 2.15,
  "percent": 65.1
}
All Channels
{
  "payload": [
    {"ch": 0, "voltage": 2.15},
    {"ch": 1, "voltage": 1.65},
    ...
  ]
}

Example: Multi-Sensor Dashboard

Read multiple analog sensors and display on dashboard.

// Function node: Parse multi-channel data
// CH0: Temperature (TMP36)
// CH1: Light (LDR)
// CH2: Potentiometer
// CH3: Moisture sensor

var channels = msg.payload;
var result = {};

channels.forEach(function(ch) {
    switch(ch.ch) {
        case 0: // TMP36: 10mV/°C, 500mV at 0°C
            result.temperature = (ch.voltage - 0.5) * 100;
            break;
        case 1: // LDR: Higher voltage = darker
            result.light = 100 - (ch.voltage / 3.3 * 100);
            break;
        case 2: // Potentiometer: 0-3.3V
            result.dial = ch.voltage / 3.3 * 100;
            break;
        case 3: // Moisture: Higher = drier
            result.moisture = 100 - (ch.voltage / 3.3 * 100);
            break;
    }
});

msg.payload = result;
return msg;

MCP3004 vs MCP3008

MCP3004

  • • 4 channels
  • • 10-bit resolution
  • • Smaller package (14-pin)
  • • Lower cost

MCP3008

  • • 8 channels
  • • 10-bit resolution
  • • Standard package (16-pin)
  • • More flexibility

Related Nodes