Archives de catégorie : Capteurs

LM35DZ – capteur de temperature analogique

version qui fonctionne.

NB : pas prévu pour fonctionnement en dessous de 0

cf : http://www.ladyada.net/learn/sensors/temp36.html

A RETENIR : 
sensorValue = analogRead(sensorPin);
tension = 5.0*sensorValue*1000/1024;
temperature = (tension )/10;
int sensorPin = A0; //
int ledPin = 13; // select the pin for the LED
int Relais1Pin = 7;
int Relais2Pin = 8;
int sensorValue = 0; // variable to store the value coming from the sensor
double temperature = 0;
double tension = 0;
void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT); 
 digitalWrite(ledPin, LOW); 
 pinMode(Relais1Pin, OUTPUT); 
 pinMode(Relais2Pin, OUTPUT); 
 //digitalWrite(Relais1Pin, LOW); //ON
 //digitalWrite(Relais2Pin, LOW); //ON
 digitalWrite(Relais1Pin, HIGH); //OFF
 digitalWrite(Relais2Pin, HIGH); //OFF
 Serial.begin(9600);
}
void loop() {
 // read the value from the sensor:
 sensorValue = analogRead(sensorPin); 
 // Voltage at pin in milliVolts = (reading from ADC) * (5000/1024)
 //This formula converts the number 0-1023 from the ADC into 0-5000mV (= 5V)
 tension = 5.0*sensorValue*1000/1024;
 // Centigrade temperature = [(analog voltage in mV) - 500] / 10
 //temperature = (tension - 500)/10;
 temperature = (tension )/10;
 
 Serial.print(sensorValue);
 Serial.print(" --> ");
 Serial.print(tension);Serial.print(" mV --> ");
 Serial.print(temperature);Serial.println(" C");
 
 // turn the ledPin on
 digitalWrite(ledPin, HIGH); 
 //digitalWrite(Relais1Pin, LOW); 
 //digitalWrite(Relais2Pin, HIGH); 
 // stop the program for <sensorValue> milliseconds:
 delay(2000); //ms 
 // turn the ledPin off: 
 digitalWrite(ledPin, LOW); 
 //digitalWrite(Relais1Pin, HIGH);
 delay(1000); //ms 
}