Introduction: MQ2 Shield on PcDuino

Picture of 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

Picture of Wire Diagram

Step 2: Get Arduino-ish Programming API

Picture of 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 http://www.github.com/pcduino/c_enviroment

Step 3: C Code

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

const int analogInPin =0;

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

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

void loop() {

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

if(count1==3000)
{
count1=0;

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

The above code can also be downloaded from here.

Step 4: Compile

modify\test\Makefile:
LIBS=-L../../sample/core -larduino -lspi
INCS=-I../../sample/core/include
TARGET=../../sample/test

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 $@
clean:
@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

Picture of 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.

Comments

About This Instructable

1,360views

11favorites

License:

More by pcduino:Use Button to Control LED on pcDuino with JavaUse Arduino and RS232 Shield to interface Integrated UHF RFID reader LSID-0702Experiment 4 Serial Port Communication
Add instructable to: