Go Down

Topic: MQ-3 alcohol sensor (Read 1 time) previous topic - next topic

santoshaxl

Oct 06, 2012, 05:20 pm Last Edit: Oct 06, 2012, 05:27 pm by santoshaxl Reason: 1
dear experts
i have purchased alcohol sensor from the sparfun.com and according to data sheet i have connected 10k ohm resistor accross it and switche on for one whole day and night after that i try to write code and when alchol is not detected 200 value shows in the lcd i it should have shown value o how to solve this problem any idea ?
here is the code
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int ledPin = 13;
int sensorPin = A0;
int value = 0;

const int threshold = 350;

void setup()
{

Serial.begin(9600);
lcd.begin(16,2);

}

void loop()
{
int Value = analogRead(sensorPin);
value = analogRead(0);

if (Value > threshold)
{
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin,LOW);
  }

 
lcd.print("alcohollevel:");
lcd.println(value);
Serial.println(value,DEC);


if (Value > threshold)
{
    lcd.print("alert");
    Serial.print ("alert");
  }
  else {
    lcd.print("normal");
    Serial.print("normal");
   
  }
   
delay(1000);
lcd.clear();

}

Riva

Have you wired it up correctly? You say i have connected 10k ohm resistor accross it but 10K resistor should not be connected across device but is to ground.

Your reading the pin twice
Code: [Select]
int Value = analogRead(sensorPin);
value = analogRead(0);

You don't need the second one. The device really needs calibrating using known alcohol concentrations.
http://forum.arduino.cc/index.php?action=unread;boards=5,67,10,11,66,12,15,17,21,22,23,24,25,29;ALL

santoshaxl

if i remove second line value is displayed always zero what is the problem then .

santoshaxl

yes 10k is connected to the ground and when the alcohol is present value varies from 200 to 1024 but when alcohol is not present shows value 200 my wiring is correct

Riva

Your confusing 'Value' with 'value'. C++ is case sensitive so these are totally separate variables.
Get rid of this line as it's not needed
Code: [Select]
int value = 0;


Correct case of these two lines so they say Value and not value
Code: [Select]
    lcd.println(value);
    Serial.println(value,DEC);

http://forum.arduino.cc/index.php?action=unread;boards=5,67,10,11,66,12,15,17,21,22,23,24,25,29;ALL

tuxduino


if i remove second line value is displayed always zero what is the problem then .


Value is not value

(edit: whops, it seems I was late :P )

santoshaxl

oh yes that was my mistake i will check now :)

Go Up