Offline
Jr. Member
Karma: 0
Posts: 56
|
 |
« on: October 25, 2011, 06:18:56 pm » |
salut à tous, me voilà en possession du senseur de gaz mq2 comme icidésolé je n'ai pas réussi a faire un lien plus court Edit de Jean-François : moi, oui  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. http://www.instructables.com/id/Arduino-Fart-O-Meter/step7/Testing-the-methane-sensorcomme ces gens, j'aimerais réaliser un detecteur de pet... ben oui, y faut, c'est super utile  ------------- 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
|
|
|
|
« Last Edit: October 26, 2011, 01:10:12 am by Jean-François »
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 0
Posts: 451
|
 |
« Reply #1 on: October 26, 2011, 05:33:37 am » |
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); }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 56
|
 |
« Reply #2 on: October 26, 2011, 06:19:53 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 0
Posts: 451
|
 |
« Reply #3 on: October 26, 2011, 11:20:34 am » |
Ah bah tu met un "serialprint" pour les voir sur le serial moniteur ou un "lcdprint" pour les voir sur un lcd 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 56
|
 |
« Reply #4 on: October 26, 2011, 03:34:05 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 56
|
 |
« Reply #5 on: October 26, 2011, 05:17:46 pm » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 56
|
 |
« Reply #6 on: October 28, 2011, 09:54:00 am » |
mon servo moteur reste mou du slip chef...  // 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?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 0
Posts: 451
|
 |
« Reply #7 on: October 28, 2011, 10:54:43 am » |
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);
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 56
|
 |
« Reply #8 on: October 28, 2011, 10:58:07 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Forum Moderator
Geneva
Offline
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« Reply #9 on: October 28, 2011, 01:48:02 pm » |
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.... 
|
|
|
|
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 218
|
 |
« Reply #10 on: October 29, 2011, 02:32:40 am » |
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... 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().
|
|
|
|
|
Logged
|
|
|
|
|
|