• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoArduino-ish ProgramADCMQ2 Shield on pcDuino
Previous Next

MQ2 Shield on pcDuino

Posted by: Yang , October 30, 2013

[vc_row][vc_column][vc_column_text]LinkSprite has a neat MQ2 shiled. In this tutorial, we just need to add a MQ 2 shield after T board on pcDuino.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Wire Diagram” tab_id=”1383117568-1-47″][vc_column_text]MQ2_1[/vc_column_text][/vc_tab][vc_tab title=”Get Arduino-ish programming API” tab_id=”1383117568-2-30″][vc_column_text]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[/vc_column_text][/vc_tab][vc_tab title=”C Code” tab_id=”1383120986050-2-5″][vc_column_text]

/* 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.

[/vc_column_text][/vc_tab][vc_tab title=”Compile” tab_id=”1383122462554-3-8″][vc_column_text]

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[/vc_column_text][/vc_tab][vc_tab title=”Run” tab_id=”1383125345638-4-7″][vc_column_text]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.

600px-MQ2_2[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: ADC, Arduino-ish Program

Share!
Tweet

Yang

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors