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);
}
//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);
}
// 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);
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().