hey i wish that ur all fine ( i m sorry for some mistakes because i dont have a good english);
i wish that u gonna hepl me to solve this problem;
in my project i have to commande the DS18B20 by ARDUINO MEGA 2560 and if if the Temperature > Tempmax = 26 than the LED-Green ( i called in the programme Vent) is high and if the Temperature < Tempmin = 10 than the LED-Red ( i called in the programme Resi) is high .
But that problem is when i do the project in ISIS (Proteus ) that the Led-Green(i called Vent) is always high and the Led-Red ( i calledd Resi) is high just in the case that the temperature is negative.
This is the programme :
#include<OneWire.h> // librairie du capteur DS18B20
// declaration
float Tempmax = 26;
float Tempmin = 10;
int Resi = 3; //LED qui represente la resistance au pin3
int Ven = 4; //LED qui represente le ventilateur au pin4
int HighByte, LowByte, TReading, Temperature;
OneWire ds(10);
void setup() {
Serial.begin(9600);
pinMode(Resi,OUTPUT);
pinMode(Ven,OUTPUT);
}
void loop() {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
Serial.print("No more addresses.\n");
ds.reset_search();
return;
}
Serial.print("R=");
for( i = 0; i < 8; i++) {
Serial.print(addr*, HEX);*
- Serial.print(" ");*
- }*
- if ( OneWire::crc8( addr, 7) != addr[7]) {*
- Serial.print("CRC is not valid!\n");*
- return;*
- }*
- if ( addr[0] == 0x10) {*
- Serial.print("Device is a DS18S20 family device.\n");*
- }*
- else if ( addr[0] == 0x28) {*
- Serial.print("Device is a DS18B20 family device.\n");*
- }*
- else {*
- Serial.print("Device family is not recognized: 0x");*
- Serial.println(addr[0],HEX);*
- return;*
- }*
- ds.reset();*
- ds.select(addr);*
- ds.write(0x44,1); *
- delay(1000); *
- present = ds.reset();*
- ds.select(addr); *
- ds.write(0xBE); *
- Serial.print("P=");*
- Serial.print(present,HEX);*
- Serial.print(" ");*
- for ( i = 0; i < 9; i++) { // on a besoin de 9 bit*
_ data = ds.read();_
_ Serial.print(data*, HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print( OneWire::crc8( data, 8 ), HEX);
Serial.println();*_
//Convertir la temperature en degres Celsius
* LowByte = data[0];*
* HighByte = data[1];*
* TReading = (HighByte << 8 ) + LowByte;*
_ Temperature = (6 * TReading) + TReading / 4; // La valeur de temperature_
* Serial.print(" Temperature");*
* Serial.print(Temperature);*
* //Comparer la Temperature au Tempmin et Tempmax*
* if( Temperature < Tempmin ){*
* digitalWrite(Resi,HIGH);*
* delay(1000);*
* digitalWrite(Resi,LOW); *
* }*
* else if( Temperature > Tempmax ){*
* digitalWrite(Ven,HIGH);*
* delay(1000);*
* digitalWrite(Ven,LOW); *
* }*
* delay(5000);*
}
This is the schema of the project in ISIS :
