Bonjour à tous, je suis en train d'essayer d'inclure un capteur de température à mon projet .
Mais voila, la valeur renvoyé est toujours de 0,00
J'ai pourtant bien inclus la librairie DHT, bien connecté mes fils ( broche de gauche sur 5V, 2eme broche connecté à une résistance 6 k puis au 5V, 2 eme broche également à la pin digital 34 de ma méga, la 3 ème broche n'est pas connectée, et la dernière au GND. Ou est le problème ? le capteur est HS ?
voici mon code
// ---------------------------------------------------------------------------------------------------------
// zimmermann frédéric
// Arduino + ethernet shield control by iOS
// Mai 2015
// ----------------------------------------------------------------------------------------------------------
#include <LiquidCrystal.h>
#include <Ethernet.h>
#include <SPI.h>
#include <DHT.h>
#define DHTPIN 34
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
// Ethernet shield settings
// Change the MAC in hex, your IP, Gateway, subnet mask and webport
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // MAC
byte ip[] = {192, 168, 0, 254}; // Shield IP
byte gateway[] = {192, 168, 0, 1}; // Gateway
byte subnet[] = {255, 255, 255, 0}; // Subnet mask
byte dnsserver[] = {213, 166, 201, 3};
int port = 85; // Webport
// ---------------------------------------------------------------------
EthernetServer server(port);
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
EthernetClient client2;
int Cloture1 = 30;
int led = 22;
int bouton = 6;
int etatbouton ;
int val = 0;
int precedetat = 0;
long previousMillis = 0;
long interval = 250;
boolean pushenvoi = true;
boolean cloture1Allume = true;
boolean clotureOFFiphone;
boolean lastConnected = false;
char DEVID1[] = "v1F51D72F4A163BD"; //sénario cloture 1 allumé
char DEVID2[] = "v7F928A69AAD2196"; //sénario cloture 1 éteinte
char DEVID3[] = "v10DB6F8487D22F0"; //sénario cloture 2 allumé
char DEVID4[] = "vDEDA46A8C5E4D79"; //sénario cloture 2 éteinte
char serverName[] = ("api.pushingbox.com");
// Serial speed
int speedSerial = 9600;
// Buffer size
int sizeString = 80;
String stringInput = String(sizeString);
// Setup
void setup() {
Serial.begin(speedSerial);
lcd.begin(16, 2);
// Digital Pins 10, 11, 12 , 13 utilisé par le shield ethernet
pinMode(Cloture1, OUTPUT);
pinMode(led, OUTPUT);
pinMode(bouton, INPUT);
// Start ethernet shield webserver
Ethernet.begin(mac, ip, dnsserver, gateway, subnet);
Serial.println (Ethernet.localIP ());
dht.begin();
server.begin();
}
void loop() {
float t = dht.readTemperature();
val = digitalRead (bouton);
Serial.print("CLOTURE");
Serial.print(" ");
Serial.println(cloture1Allume);
delay(500);
Serial.print("bouton");
Serial.print(" ");
Serial.println(etatbouton);
Serial.print("Temperature: ");
Serial.println(t);
//------------------------------ GESTION DE L'APPUI SUR LE BOUTON DE LA CLOTURE 1--------------------------------
if (val == HIGH && precedetat == LOW) {
etatbouton = !etatbouton;
delay(10);
}
precedetat = val;
if (etatbouton == 0 && cloture1Allume == true) { // si bouton n'a pas encore été appuyé et cloture allumée
lcd.setCursor(0, 0);
lcd.print("Clot1. ON.Bouton ");
}
if (etatbouton == 1 && cloture1Allume == true) { // si bouton appuyé et cloture allumée
cloture1Allume = false;
lcd.setCursor(0, 0);
lcd.print("Clot1.OFF.Bouton ");
} // alors on éteint
if (etatbouton == 0 && cloture1Allume == false) { // si bouton pas appuyé et cloture éteinte
cloture1Allume = true;
lcd.setCursor(0, 0);
lcd.print("Clot1. ON.Bouton "); // alors on allume
}
if (etatbouton == 0 && cloture1Allume == true && clotureOFFiphone == true) { // si bouton pas appuyé, cloture allumé et iphone Off
cloture1Allume = false;
lcd.setCursor(0, 0);
lcd.print("Clot1.OFF.Iphone ");
} // alors on éteint
if(cloture1Allume == false && clotureOFFiphone == true && etatbouton == 1){ // si bouton appuyé, alors que l'iphone a éteint, on peut rien faire
lcd.setCursor(0, 0);
lcd.print("Manip.impossible");
delay(1000);
etatbouton = 0;
}
//---------------------------------CONNEXION AU SERVEUR-------------------------
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
stringInput = "";
if (client.connected()) {
while (client.available()) {
char c = client.read();
if (stringInput.length() < sizeString) {
stringInput.concat(c);
}
if (c == '\n' && currentLineIsBlank) {
digitalRead(Cloture1);
client.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
client.println("<agridomotique>");
// Pin 30 Cloture1
client.print("<Pin>");
client.print("<namePin>CLOTURE 1</namePin>");
client.print("<digitalPin>");
// Digital pin to control
client.print("</digitalPin>");
client.print("<Etat>");
if (cloture1Allume == 1) {
client.print (" ALLUMEE");
}
if (cloture1Allume == 0) {
client.print (" ETEINTE");
}
client.print("</Etat>");
client.print("</Pin>");
client.println("</agridomotique>");
break;
}
if (c == '\n') {
Serial.print(stringInput);
Serial.println();
if (stringInput.indexOf("GET") != -1) {
// si iphone ON
if (stringInput.indexOf("Cloture1=ON") != -1) {
cloture1Allume = true;
clotureOFFiphone = false;
lcd.setCursor(0, 0);
lcd.print("Clot1. ON.Iphone ");
}
// si off iphone
if ((stringInput.indexOf("Cloture1=OFF") != -1) && (cloture1Allume == true)) {
cloture1Allume = false;
clotureOFFiphone = true;
lcd.setCursor(0, 0);
lcd.print("Clot1.OFF.Iphone ");
}
}
currentLineIsBlank = true;
stringInput = "";
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
//----------------------------------------- COMMMANDE ET PUSH DE LA Cloture 1 --------------------------------------------
if (cloture1Allume == true ) { // ON ALLUME LA CLOTURE1
digitalWrite (Cloture1, HIGH);
digitalWrite (led, HIGH);
}
if (cloture1Allume == false ) { // ON ETEINT LA CLOTURE1
digitalWrite (Cloture1, LOW);
digitalWrite (led, LOW);
}
if ( cloture1Allume == true && pushenvoi == true ) { // si la cloture1 est allumé on envoi un push
// On envoi un push allumé
sendToPushingBox(DEVID1);
pushenvoi = false;
}
if ( cloture1Allume == false && pushenvoi == false ) { // si la cloture1 est éteinte en onvoi un push
// On envoi un push éteint
sendToPushingBox(DEVID2);
pushenvoi = true;
}
}
//---------------------------------Fonction permettant d'envoyer un push PushingBox---------------------
void sendToPushingBox(char devid[]) {
//demarre connexion ethernet
;
Serial.println("connecting...");
if (client2.connect(serverName, 80)) {
Serial.println("connected");
Serial.println("sendind request");
client2.print("GET /pushingbox?devid=");
client2.print(devid);
client2.println(" HTTP/1.1");
client2.print("Host: ");
client2.println(serverName);
client2.println("User-Agent: Arduino");
client2.println("Connection: close");
client2.println();
while (client2.connected ())
if (client2.available ())
Serial.write(client2.read());
client2.stop ();
Serial.println("succes");
}
else {
Serial.println("connection failed");
}
client2.stop();
}
/code]