Project

General

Profile

Files » arduingaz.ino

code arduino pour prototype de capteur de gaz - Frédéric Blanc, 2018-05-15 09:57

 
/**
* @file arduingaz.ino
* @brief mesure de resistance
* @author frederic BLANC LAAS-CNRS
* @version 1.0
* @date 14/05/2018
*/
#define VCC 5
#define DELAY_MS 100
#define VG 4.0 //tension de changement de gamme
void setup() {
Serial.begin(9600);
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(11,INPUT);
pinMode(10,INPUT);
}

void loop() {
float Rl=10E+6; //10Mohms
pinMode(13,OUTPUT);
digitalWrite(13, LOW);
pinMode(12,INPUT);
pinMode(11,INPUT);
pinMode(10,INPUT);
delay(DELAY_MS);
int Vs_raw = analogRead(A0);
float Vs= Vs_raw * (VCC / 1023.0);
if(Vs>VG)
{
Rl=1E+6; //1Mohms
pinMode(13,INPUT);
pinMode(12,OUTPUT);
digitalWrite(12, LOW);
pinMode(11,INPUT);
pinMode(10,INPUT);
delay(DELAY_MS);
Vs_raw = analogRead(A0);
Vs= Vs_raw * (VCC / 1023.0);
if(Vs>VG)
{
Rl=100E+3; //100kohms
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(11,OUTPUT);
digitalWrite(11, LOW);
pinMode(10,INPUT);
delay(DELAY_MS);
Vs_raw = analogRead(A0);
Vs= Vs_raw * (VCC / 1023.0);
if(Vs>VG)
{
Rl=10E+3; //10K
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(11,INPUT);
pinMode(10,OUTPUT);
digitalWrite(10, LOW);
delay(DELAY_MS);
Vs_raw = analogRead(A0);
Vs= Vs_raw * (VCC / 1023.0);
}
}
}
float Rs= Rl*VCC/Vs-Rl;
Serial.println(Rs);
}
(1-1/9)