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

0
program for interface the mq2 with atmega8

pls

1 Answer

0

I got the code below from the following forum (http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=32353), 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. https://www.virtuabotix.com/productpage/609224532276-bulk/

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)
{
ad_index=0;
}

ADMUX = ADC_VREF_TYPE + ad_channel[ad_index];

// Start the AD conversion
ADCSRA |= BIT_ADCSRA_ADSC;

}

Your Answer

No comments yet.

Leave a Reply