mq2 senseur de gaz

salut à tous, me voilà en possession du senseur de gaz mq2

comme ici

désolé je n'ai pas réussi a faire un lien plus court
Edit de Jean-François : moi, oui XD

et un duino.

comme les mecs l'ont fait sur instructable, j'ai respecté le brochage du mq4, qui je pense (du moins je l'espere) est le même.

comme ces gens, j'aimerais réaliser un detecteur de pet... ben oui, y faut, c'est super utile XD


apparament j'ai un 5v, un analog out et un ground, tout ce qu'il faut quoi.

maintenant coté brochage duino, ok, coté code...

je dois creer un analog in. qu'écrire pour voir la valeur du taux de gaz??

merci biennnn

The most important part of the emitter is:

Prepare the radio transmitter like this:
Radio.remoteAddress = 1;
Radio.txMode(3);

This is just an example to show how you can transfer an array.
Radio.data[0] = 22;
Radio.data[1] = 33;


You read the analog pin
val = analogRead(potpin);

Then you map it to the servo motor.
When you have 1023, that is the max position of the servo motor, 179.
val = map(val, 0, 1023, 0, 179);

You then take the value and send it to the receiver.
Radio.data[2] = val;
Radio.write(); 

The receiver is also very simple

wait for signal
while(!Radio.available());

Read it
Radio.read();

if(Radio.data[0] == 22 && Radio.data[1] == 33 )
{

Get the servo value in the array
    val = Radio.data[2];
Move the servo, I subtracted the voltage offset since there is no gas, the value read is 1.3V
    myservo.write(val-40);
    delay(15);
}

hello, ben oui ce code, mais il définit les valeurs pour la transmission radio entre le senseur et l'arduino.

il récupère les valeurs et les balance au servomoteur.

mais moi perso, je voudrais simplement voir ces valeurs sur un écran.

tu vois ce que je veux dire?

Ah bah tu met un "serialprint" pour les voir sur le serial moniteur ou un "lcdprint" pour les voir sur un lcd :wink:

genre ça?

//this outputs pot value to screen in ohms

int gasSensor = 1; // select input pin for gasSensor
int val = 0; // variable to store the value coming from the sensor

void setup() {
 
pinMode(1,INPUT); // gaz
Serial.begin(9600);
}

void loop() {
val = analogRead(gasSensor); // read the value from the pot
Serial.println( val );
delay(100);
}

apres j'enclenche le serialport monitor et ça me crache un millon de 0 et si je depine la pin, ben la ça pete dans les 300 280 quelque chose comme ça...

est ce que en disant int gasSensor = 1, ça ouvre mon analog A1?

ouaiiiiiiiiiiiiiiiiiiis, ca fonctionne quand c'est bien branché

//this outputs pot value to screen in ohms

int gasSensor = 0; // select input pin for gasSensor
int val = 0; // variable to store the value coming from the sensor

void setup() {
 

Serial.begin(9600);
}

void loop() {
val = analogRead(gasSensor); // read the value from the pot
Serial.println   ( val );
delay(100);
}

comme ca, ça fonctionne :slight_smile:

mon servo moteur reste mou du slip chef... :drooling_face:

// Controlling a servo position using a gaz (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int gazpin = 0;  // analog pin used to connect the gaz
int val;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(gazpin);       // reads the value of the gaz (value between 0 and 1023) 
  Serial.println (val);
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 

  delay(200);                           // waits for the servo to get there 
}

ca ca vous semble correct? mon servo est d'apres moi connecté correctement... qu'est ce qui n'irait pas?

  val = analogRead(gazpin);       // reads the value of the gaz (value between 0 and 1023) 
  Serial.println (val);
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);

C'est pas le fait d'avoir deux fois "val" qui fou le bronx ?
Moi j'aurais fait ça un truc dans ce genre

  val = analogRead(gazpin);       // reads the value of the gaz (value between 0 and 1023) 
  Serial.println (val);
  serv = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(serv);

Apres je suis pas du tout sur que ça vienne de la mais la j'ai l'impression que le val qui va être utilisé dans myservo ça va être le val = analogRead(gazpin) et pas le val = map(val, 0, 1023, 0, 179);

non j'ai trouvé, c'est parceque je suis un peu c*n parfois, mauvais brochage.

ben là du coup mon servo bouge en fonction de la teneur en méthane de l'air... ça fait plaisir

vj_muddy:
non j'ai trouvé, c'est parceque je suis un peu c*n parfois, mauvais brochage.

ben là du coup mon servo bouge en fonction de la teneur en méthane de l'air... ça fait plaisir

Encore un qui se la pète.... XD

chicotore:

  val = analogRead(gazpin);       // reads the value of the gaz (value between 0 and 1023) 

Serial.println (val);
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);




C'est pas le fait d'avoir deux fois "val" qui fou le bronx ?

C'est tout à fait correct, il faut juste garder en tête que val sera écrasée par la valeur retournée par la fonction map(). Par contre il ne faut plus avoir besoin de la valeur retournée par analogRead() par la suite...

chicotore:
Moi j'aurais fait ça un truc dans ce genre

  val = analogRead(gazpin);       // reads the value of the gaz (value between 0 and 1023) 

Serial.println (val);
  serv = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(serv);




Apres je suis pas du tout sur que ça vienne de la mais la j'ai l'impression que le val qui va être utilisé dans myservo ça va être le val = analogRead(gazpin) et pas le val = map(val, 0, 1023, 0, 179);

Non, ce sera bien la valeur val retournée par la fonction map() qui sera passée en argument à myservo.write().