Computers, Development Boards & Shields
Educational & Robotics Kits
Electronic Sensors
Motors & Controllers
Communication & Display
Electronic Components
Soldering & Lab Tools

program for interface the mq2 with atmega8


1 Answer


I got the code below from the following forum (, maybe it will help. But basically you just need to read analog data using the built in ADC on your ATMEGA8 and translate that raw data to a PPM based on the sensor datasheet.

On a regular Arduino/Versalino you should be able to just say analogRead(yourMQ2Pin); and process the data accordingly, but below is something that may work in machine code. Atmel should have more examples available depending on the MCU you are using.

// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
// Read the AD conversion result
adc_raw[ad_index] = ADCW;

// Select next ADC input
if (++ad_index >= ad_count)

ADMUX = ADC_VREF_TYPE + ad_channel[ad_index];

// Start the AD conversion


Your Answer

No comments yet.

Leave a Reply