Introduction: MQ2 Shield on PcDuino

LinkSprite has a neat MQ2 shiled. In this tutorial, we just need to add a MQ 2 shield after T board on pcDuino.

Step 1: Wire Diagram

Step 2: Get Arduino-ish Programming API

We need to use github to get Arduino-ish programming API for pcDuino.

If your pcDuino hasn’t yet installed git, you need to install git first using command below:

$sudo apt-get install git

After that, we use the installed git to get Arduino-ish programming API for pcDuino:

ubuntu@ubuntu:~$ git clone

Step 3: C Code

/* Sample code for MQ2 Smoke Sensor Shield for pcDuino
#include <core.h>

const int analogInPin =0;

int sensorValue = 0;        // value read from the pot
int count1;

void setup() {
pinMode(7, OUTPUT);

void loop() {

// read the analog in value:
sensorValue = analogRead(analogInPin);


printf("sensor=%d\n", sensorValue);

The above code can also be downloaded from here.

Step 4: Compile

LIBS=-L../../sample/core -larduino -lspi

OBJS = io_test adc_test pwm_test spi_test adxl345_test MQ2

all: $(OBJS)
@mkdir -p $(TARGET)
@mv $(OBJS) $(TARGET)

io_test: io_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

MQ2: MQ2.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

adc_test: adc_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

pwm_test: pwm_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

spi_test: spi_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

adxl345_test: adxl345_test.c
$(CC) &lt; -o $@
@for i in $(OBJS); do rm -f $(TARGET)/$$i; done
MQ2: MQ2.c in the middle is the new added program.

Reopen the terminal to make library file:

ubuntu@ubuntu:~$ cd c_enviroment

ubuntu@ubuntu:~/c_enviroment $ make

Step 5: Run

Now we run the following under test directory:

$sudo ./MQ2

When we light the lighter next to the sensor, we can see the ADC reading goes up immediately.