Modifications

Cestpasidiot

133 octets supprimés, 16 septembre 2015 à 13:26
récepteur pour capteur DHT + luxmètre : + détecteur de mouvement
Le dispositif sera présenté dans le cadre de ces deux évènements :
* Le FESTIVAL D les 26 et 27 septembre* (encadrement Laurent Neyssensas & Arnaud LE ROI)
* Le Boot camp design Make de l’IRT JV le jeudi 8 octobre* (encadrement Laurent Neyssensas)
* il permet de réagir de façon lumineuse, sonore et tactile aux données reçues
* il permet de fonctionner de façon autonome en énergie sur piles ou accus AA. L'autonomie dépendra de la gourmandise de vos circuits et de l'efficacité de votre code.
 
Des exemples de code sont réunis à la fin de cette page. Ils sont abondamment '''commentés''' afin de faciliter la '''réutilisation''' dans votre projet,particulièrement la partie finale intitulée récepteur. Mind the // !!!
Le travail ayant été simplifié du côté de l'envoi de données (cf liste infra) et sa réception, et les composants sélectionnés et documenter pour vous en faciliter la prise en main, vous pourrez vous focaliser sur la conception de 2 voire 3 propositions <u>ludiques</u> de feedback sensitif pour objets connectés, les soumettre lors d'un PechaKucha. La proposition la plus pertinente sera retenu. A vous ensuite de passer à la mise en oeuvre:
=== Liste et plage de valeurs des données radio émises ===
Température ambiante (°C) = float 0-99,99Degré d'humidité ambiante = float 0-99,99Lumière ambiante (lux) = int 0-9999Bloc de 4 interrupteurs capacitifs = boolean 0 ou 1Capteur de pollution aérienne (fumée) = float 0-99,99 (après étalonnage)télémètre à ultrason (distance en cm) = entier 0-9999 (valeur théorique, de 20 à 120cm dans les faits)Déjà implémentés
* Température ambiante (°C) = float 0-99,99* Degré d'humidité ambiante = float 0-99,99* Lumière ambiante (lux) = int 0-9999 Pas encore implémentés: * Bloc de 4 interrupteurs capacitifs = boolean 0 ou 1* Capteur de pollution aérienne (fumée) = float 0-99,99 (après étalonnage)* télémètre à ultrason (distance en cm) = entier 0-9999 (valeur théorique, de 20 à 120cm dans les faits) D'autres capteurs peuvent être ajoutés à la demande, on . On peut ainsi également envisager de capter des données environnementales en ligne et les insérer dans notre flux. Ex: http://www.airpl.org/Air-exterieur/mesures-en-direct vs https://air.plumelabs.com/Nantes
===Liste des composants fournis ===
Utilisation de la librairie [https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library NeoPixel].
Exemple en français sur le site de [http://mchobby.be/wiki/index.php?title=NeoPixel-UserGuide McHobby.be]
 
* Ajouter un condensateur 1000uF en parallèle entre le pôle - et le pole +
* Ajouter une résistance 470Ohm (jaune violetmarron) en série sur la ligne + (fil rouge)
==assemblage de code fonctionnel==
===récepteurémetteur pour capteur DHT + luxmètre + télémètre ===<pre>#include <VirtualWire.h> // Vous devez télécharger et installer la librairie VirtualWire.h dans votre dossier "/libraries" !#include "DHT.h"#include<stdlib.h>#include <Wire.h>#include <Adafruit_Sensor.h>#include <Adafruit_TSL2561_U.h>#include <NewPing.h> // pour le télémètre DYP-ME007
<pre>// les broches et paramètre du télémètre#define TRIGGER_PIN 12 // This is a demonstration on how to use an input device to broche reliée au trigger changes on your neo pixelsdu télémètre.#define ECHO_PIN 11 // You should wire a momentary push button to connect from ground to a digital IO pinbroche reliée à l'echo du télémètre. When you#define MAX_DISTANCE 99 // press the button it will change to a new pixel animationdistance maximale évaluée (en centimeters). Note that you need to press the// button once to start the first animation!NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
#include <VirtualWire.h>
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2 // Digital IO pin connected to the button. This will beles broches des capteurs #define SENSDHTPIN 4 // driven with a pull-up resistor so the switch shouldla broche dédiée au capteur de température & hygrométrie de l'air #define DHTTYPE DHT22 // pull the pin to ground momentarily. DHT 22 On a high -> low(AM2302) le modèle du capteur // transition the button press logic will execute.DHT dht(SENSDHTPIN, DHTTYPE);
#define PIXEL_PIN 8 // Digital IO pin connected to the NeoPixels.les capteurs I2C sont branchés en série#define RADIO_PIN // attention au 3 ,3V vs 5vAdafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); ////////////////////////////////////////////// broche DATA du récepteur RF#define PIXEL_COUNT 8 //
#define NUMVALUES 8//message à envoyer.char msg[40];
// message reçu.ses élements : les valeurs des capteursfloat tempValue=2000; // variable de températurefloat humidityValue=6000; // variable % hygrométrie de l'airunsigned int msg[NUMVALUES]luxValue=48;float tempValue unsigned int distanceValue=10;// unsigned int sensLight = 0; // variable dédiée au niveau lumièe en luxfloat humidityValue // unsigned int sensProx = 0; // variable de distance// unsigned int luxValue sensBend = 0; // variable du capteur de flexionfloat hygrometryValue // unsigned int sensSwitch = 0; // l'interrupteur
// float sensValues[NUMVALUES];///////////////////////////////////////////////////////////
// Parameter 1 les variables temporelles unsigned long latestSendingMillis = number of pixels in strip, neopixel stick has 8millis(); // Parameter 2 mémorise la dernière fois qu'on a envoyé les valeurs unsigned long latestSensingMillis = pin number millis(most are valid); // Parameter 3 mémorise la dernière fois qu'on a interogé les capteurs unsigned long latestDHTSensingMillis = pixel type flags, add together as needed:millis(); // NEO_RGB la dernière fois qu'on a interogé le capteur temp+hygro Pixels are wired for RGB bitstreamunsigned long i2cSensingIntervalMillis = 1000; // NEO_GRB intervalle de temps avant une nouvelle interrogation des capteurs Pixels are wired for GRB bitstream, correct for neopixel stickunsigned long sensingDHTIntervalMillis = 2500; // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)intervalle de temps avant nouvelle interrogation capteur DHT unsigned long sendingIntervalMillis = 1000; // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stickintervalle de temps avant nouvel envoi de valeursAdafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800) unsigned long time;
bool oldState = HIGH;int showType = 0;/////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
// la communication radio vw_setup(2000); // Bits par seconde(2000 = bonne portée. Si augmente, portée diminue vw_set_rx_pinvw_set_tx_pin(RADIO_PIN3); // La broche 3 pour transmettre la DATA du récepteur vw_rx_start// on lance le capteur de temp + hygro Serial.println("DHTxx test!"); dht.begin(); Serial.println("Light Sensor Test"); Serial.println("Virtual wire started"); pinMode/* Initialise le capteur TSL2561 */ if(BUTTON_PIN!tsl.begin()) { /* There was a problem detecting the ADXL345 ... check your connections */ Serial.print("Ooops, INPUT_PULLUPno TSL2561 detected ... Check your wiring or I2C ADDR!"); while(1); strip.begin} /* Display some basic information on this sensor */ displaySensorDetails(); /* Setup the sensor gain and integration time */ configureSensor(); stripSerial.showprintln(""); // Initialize all pixels to 'off'
}
void loop() { // Get current button state. bool newState = digitalRead(BUTTON_PIN); uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; // Check if state changed from high to low (button press). if (newState == LOW && oldState == HIGH) { // Short delay to debounce button. delay(20); // Check if button is still low after debounce. newState = digitalRead(BUTTON_PIN); if (newState == LOW) { showType++; if (showType > 9) showType=0; Serial.print("type : "); Serial.println(showType); startShow(showType);////////////////// le loooooooop ///////////////////////////////////////
}
}
// Set the last button state to the old state. oldState = newState; if (vw_get_messagevoid loop(buf, &buflen)) // On test afin de savoir si un message est reçu. { int i; int ii; String ficelle = ""; for (i time = 0; i < buflen; i++) { delaymillis(25); //Serial.write getTemp(buf[i]time); // msg lettre par lettre. buf[4] == 5ème lettre envoyéetemp & humidité //Serial.print getLux(" :"time); //for (ii=0; ii < NUMVALUES; ii++) //{ //ficelle += buf[i]; ficelle += bufDeciphergetMsgContent(buf[i]time); //} } ficelle[buflen] = '\0'; // finir on l'array par un NULL en cas de longueur variableimprime //Serial.print getDistance("ficelle : "time); //Serial.println sendMsg(ficelletime); // On saute une ligne pour faciliter la lecture Serial.print("Temp value : "); tempValue=getTempValue(ficelle); Serial.println(tempValue); Serial.print("Humidity value : " ); humidityValue=getHumidityValue(ficelle); Serial.println(humidityValue); Serial.print("Lux value : "); Serial.println(getLuxValue(ficelle)); }on doit assembler les valeurs en tableau de char
}
//============== FIN DU LOOP ==============================//////////////////////// les fonctions ///////////////////////////////////////
void getLux(long time){ if (time - latestSensingMillis > i2cSensingIntervalMillis){ //Serial.println("getting Lux value.."); sensors_event_t event; tsl.getEvent(&event); if (event.light) { luxValue============== emplacements de vos fonctions ==============================event.light; // Serial.print(luxValue); Serial.println(" luxValue");
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Serial.println("Lux Sensor overload");
}
latestSensingMillis = time;
return;
}
}
void getDistance(long time) { if (time - latestDHTSensingMillis > i2cSensingIntervalMillis){ unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). if ((uS / US_ROUNDTRIP_CM)>10){ //============== fonctions pour filtrer les valeurs < à 10 et ne pas modifier =============================décaler le registre d'envoi distanceValue=(uS / US_ROUNDTRIP_CM); }; return; }}
float getTempValuevoid getTemp(String ficellelong time){ String myBuf=ficelle.substringif (0,4time - latestSensingMillis > sensingDHTIntervalMillis);{ //Serial.printprintln("Temp buffer : get"); //Serial.println(myBuf); int ii; float tempValue=0; float mulValue=0; mulValue=bufToFloat(myBuf[0])*10; //Serialdht.printlnreadTemperature(mulValue); tempValue+ humidityValue =mulValue; tempValue+=bufToFloatdht.readHumidity(myBuf[1]); //Serial.println if (bufToFloat(myBuf[1])); //Serial.printlnisnan(tempValue); mulValue=bufToFloat|| isnan(myBuf[2]humidityValue); mulValue/=10; //Serial.println(mulValue); tempValue+=mulValue; // Serial.println(tempValue"capteur DHT injoignable!"); mulValue latestDHTSensingMillis =bufToFloat(myBuf[3])time; mulValue/=100; tempValue+=mulValue return; //Serial.println(tempValue); return tempValue; }
}
float getHumidityValuevoid sendMsg(String ficellelong time){ String myBufint i=ficelle.substring(4,8)0; int ii;if (time - latestSendingMillis > sendingIntervalMillis){ float value msg[0]=(buildMyValue(tempValue))[0]; float mulValue msg[1]=2(buildMyValue(tempValue))[1];// ne marche que pour temp >= 10°C mulValue msg[2]=bufToFloat(myBufbuildMyValue(humidityValue))[0]; msg[3]=(buildMyValue(humidityValue))*[1]; // ne marche que pour humidité >= 10;% value+ msg[4]=mulValue(buildMyValue(luxValue))[0]; value+ msg[5]=bufToFloat(myBufbuildMyValue(luxValue))[1]; // ne marche que pour lux >= 10 et < 100 msg[6]=(buildMyValue(distanceValue))[0]; mulValue msg[7]=bufToFloat(myBufbuildMyValue(distanceValue))[21]); mulValue// ne marche que pour lux >=10et < 100 msg[8]='\0'; value+ for (i =mulValue0; i < strlen(msg);i++) { mulValue=bufToFloat Serial.print(myBufmsg[3i], HEX); Serial.print(' '); } Serial.println(); mulValue vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); //On attend la fin de l'envoi du msg. latestSendingMillis =100time; value+=mulValue //delay(25); return value;}
}
int getLuxValue(String ficelle){ String myBuf=ficelle.substringchar *buildMyValue(8,12); int ii; float luxValue=0; float mulValue=0; mulValue=bufToFloat(myBuf[0]value)*1000; luxValue+=mulValue;{ luxValue+=bufToFloat(myBufchar buffer[140])*100; luxValue+=bufToFloatitoa(myBuf[2])*value, buffer, 10; luxValue+=bufToFloat(myBuf[3]); return luxValue; // return transfrome cequi suit en commentaires Serial.print("Lux buffer : "); Serial.println(myBuf); Serial.print("Lux value : "); Serial.println(luxValue); return luxValue;
}
int bufToFloat//============== fonctions du capteur de luminosité TSL2561 ===================================  // ============= by ADAFRUIT ============== void displaySensorDetails(char srcvoid)
{
float sortie=0sensor_t sensor; switchtsl.getSensor(src&sensor){; case '0': breakSerial.println("------------------------------------"); case '1'Serial.print ("Sensor: sortie+=1 "); breakSerial.println(sensor.name); case '2'Serial.print ("Driver Ver: sortie+=2 "); breakSerial.println(sensor.version); case '3'Serial.print ("Unique ID: sortie+=3 "); breakSerial.println(sensor.sensor_id); case '4'Serial.print ("Max Value: sortie+=4 "); Serial.print(sensor.max_value); breakSerial.println(" lux"); case '5'Serial.print ("Min Value: sortie+=5 "); Serial.print(sensor.min_value); breakSerial.println(" lux"); case '6'Serial.print ("Resolution: sortie+=6 "); breakSerial.print(sensor.resolution); case '7': sortie+=7; breakSerial.println(" lux"); case '8': sortie+=8Serial.println("------------------------------------"); case '9': sortie+=9; breakSerial.println(""); } return sortiedelay(500);
}
char bufDecipher/**************************************************************************//* Configures the gain and integration time for the TSL2561*//**************************************************************************/void configureSensor(char alphavoid)
{
char nombre=0; /* You can also manually set the gain or enable auto-gain support */ switch // tsl.setGain(alphaTSL2561_GAIN_1X){ case 'a': nombre = '0'; /* No gain ... use in bright light to avoid sensor saturation */ break // tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */ case 'b': nombre = '1' tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */ break; case 'c': nombre /* Changing the integration time gives you better sensor resolution (402ms = '2';16-bit data) */ break //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */ case 'd': nombre = '3' tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */ break // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */ case 'e': nombre = '4 /* Update these values depending on what you';ve set above! */ break Serial.println("------------------------------------"); case 'f' Serial.print ("Gain: nombre = '5'"); breakSerial.println("Auto"); case 'g' Serial.print ("Timing: nombre = '6'; break; case 'h': nombre = '7'"); break; case 'i': nombre = '8'; breakSerial.println("101 ms"); case 'j': nombre = '9'; break; } return char Serial.println(nombre"------------------------------------");
}
<//============== fonctions liées à la librairie NeoPixel ==============================pre>
//============== ne pas modifier ici =======================récepteur pour capteur DHT + luxmètre + télémètre + détecteur de mouvement ===<pre>#include <VirtualWire.h> // librairie radio#define RADIO_PIN 3 // broche DATA du récepteur RF // message reçu.float tempValue =0;float humidityValue =0;int luxValue =0;float distanceValue =0;
void startShowsetup(int i) { switch(i){ case 0: colorWipe(stripSerial.Colorbegin(0, 0, 0), 509600); // Black/off break; case 1: colorWipe(strip.Color vw_setup(255, 0, 0), 502000); // RedBits par seconde break; case 2: colorWipe vw_set_rx_pin(strip.Color(0, 255, 0), 50RADIO_PIN); // Green broche DATA du récepteur break; case 3: colorWipe vw_rx_start(strip.Color(0, 0, 255), 50); // Blue break; case 4: theaterChase(strip.Color(127, 127, 127), 50); // White break; case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red break; case 6: theaterChase(stripSerial.Color( 0, 0, 127), 50); // Blue break; case 7: rainbowprintln(20"Virtual wire started"); break; case 8: rainbowCycle(20); break; case 9: theaterChaseRainbow(50); break; }
}
void loop() { // Fill the dots one after the other with a colorGet current button state. uint8_t buf[VW_MAX_MESSAGE_LEN];void colorWipe uint8_t buflen = VW_MAX_MESSAGE_LEN; String ficelle=""; if (vw_get_message(uint32_t cbuf, uint8_t wait&buflen)) // On test afin de savoir si un message est reçu. { int i; int nombre; //Serial.println("nouveau msg"); for(uint16_t i=0; i<strip.numPixels()= buflen; i++) { strip ficelle+=char(buf[i]); // msg lettre par lettre. buf[4] == 5ème lettre envoyée } ficelle[buflen] = '\0'; Serial.print("ficelle : "); Serial.setPixelColorprintln(ificelle); tempValue=(ficelle.substring(0,2).toInt()); humidityValue=(ficelle.substring(2,4).toInt()); luxValue=(ficelle.substring(4,6).toInt()); distanceValue=(ficelle.substring(6,8).toInt()); motionValue=(ficelle.substring(8, c9).toInt()); strip //Serial.showprint(luxValue); delay //Serial.println(wait" lux"); }
}
void rainbow(uint8_t wait) {//============== FIN DU LOOP ============================== //============== emplacements de vos fonctions ============================== uint16_t i, j;
for(j//============== fonctions à ne pas modifier =============================0; j<256; j++) { for(i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); }}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
<//Theatre-style crawling lights.pre>void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j== récepteur pour capteur DHT ++) { //do 10 cycles of chasingluxmètre === for (int q=0; q < 3; q++) {pre> for (int i=0; i < strip// This is a demonstration on how to use an input device to trigger changes on your neo pixels.numPixels(); i=i+3) { strip// You should wire a momentary push button to connect from ground to a digital IO pin.setPixelColor(i+q, c); When you//turn every third press the button it will change to a new pixel onanimation. Note that you need to press the } strip.show();// button once to start the first animation!
delay(wait);#include <VirtualWire.h>
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effectvoid theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (int i=0; i < strip.numPixels(); i=i+#define RADIO_PIN 3) { strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } strip.show(); broche DATA du récepteur RF
delay(wait)// message reçu.float tempValue = 0;float humidityValue = 0;int luxValue = 0;float hygrometryValue = 0;
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.// The colours are a transition r - g - b - back to r.uint32_t Wheelvoid setup(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return stripSerial.Colorbegin(255 - WheelPos * 3, 0, WheelPos * 39600); } ifvw_setup(WheelPos < 1702000) { WheelPos -= 85; // Bits par seconde return strip.Color vw_set_rx_pin(0, WheelPos * 3, 255 - WheelPos * 3RADIO_PIN); // broche DATA du récepteur } WheelPos -= 170vw_rx_start(); return stripSerial.Colorprintln(WheelPos * 3, 255 - WheelPos * 3, 0"Virtual wire started");
}
void loop() { // Get current button state. uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; String ficelle=""; if (vw_get_message(buf, &buflen)) // On test afin de savoir si un message est reçu. { int i; int nombre; //Serial.println("nouveau msg"); for (i = 0; i <= buflen; i++) { ficelle+=char(buf[i]); // msg lettre par lettre. buf[4] == 5ème lettre envoyée } ficelle[buflen] = '\0'; Serial.print("ficelle : "); Serial.println(ficelle); tempValue=(ficelle.substring(0,2).toInt()); humidityValue=(ficelle.substring(2,4).toInt()); luxValue=(ficelle.substring(4,6).toInt()); //Serial.print(luxValue); //pre>Serial.println(" lux");
===émetteur === // ici vous pouvez appeler vos propres fonctions destinées à tirer partie des variables récupérées juste avant
Ce code est à mettre du côté émetteur. A utiliser avec le schéma de câblage afin de reproduire le dispositif au labo.
<pre> }#include <VirtualWire.h> // Vous devez télécharger et installer la librairie VirtualWire.h dans votre dossier "/libraries" !#include "DHT.h"#include<stdlib.h>}
// les broches des capteurs#define SENSDHTPIN 4 // la broche dédiée au capteur de température & hygrométrie de l'air#define DHTTYPE DHT22 // DHT 22 (AM2302) le modèle du capteurDHT dht(SENSDHTPIN, DHTTYPE);============== FIN DU LOOP ==============================
//============== emplacements de vos fonctions ==============================
// les capteurs I2C
// attention au 3,3V vs 5v
//#DEFINE SENSLIGHTPIN = 5 ; // la broche dédiée au luxmètre => I2C
//#DEFINE SENSPROXPIN = 6 ; // la broche dédiée au télémètre
// interrupteur#define SWITCHPIN 2 // le compteur à incrémenterint truc = 0;ici toute la logique de votre programme
// le tableau des valeurs#define NUMVALUES 12float sensValues[NUMVALUES];============== fonctions à ne pas modifier ==============================
//ajouter ici les fonctions Adafruit pour Neopixel par exemple<//////////////////////////////////////////////pre>
//message à envoyer.const char *msg="abcdefghijih";==récepteur pour capteur DHT seul===
// ses élements : les valeurs des capteurschar *tempValue; // variable de températurechar *humidityValue; // variable % hygrométrie de l'airchar *luxValue; unsigned int sensSwitch = 0 ; // variable de l'interrupteur <pre>// unsigned int sensLight = 0 ; // variable dédiée au niveau lumièe en luxThis is a demonstration on how to use an input device to trigger changes on your neo pixels.// unsigned int sensProx = 0 ; // variable de distanceYou should wire a momentary push button to connect from ground to a digital IO pin. When you// unsigned int sensBend = 0; // variable du capteur de flexionpress the button it will change to a new pixel animation. Note that you need to press the// unsigned int sensSwitch = 0; // l'interrupteur button once to start the first animation!
/////////////////////////////////////////////////////////////#include <VirtualWire.h>
// les variables temporelles
unsigned long latestSensingMillis = millis(); // mémorise la dernière fois qu'on a interogé les capteurs
unsigned long latestDHTSensingMillis = millis(); // la dernière fois qu'on a interogé le capteur temp+hygro
unsigned long latestSendingMillis = millis(); // la dernière fois qu'on a envoyé les valeurs
unsigned long sensingIntervalMillis = 500; // intervalle de temps avant une nouvelle interrogation des capteurs
unsigned long sensingDHTIntervalMillis = 2500; // intervalle de temps avant nouvelle interrogation capteur DHT
unsigned long sendingIntervalMillis = 1500; // intervalle de temps avant nouvel envoi de valeurs
unsigned long time;
#define RADIO_PIN 3 ///////////////////////////////////////////////////////////// broche DATA du récepteur RF
void setup(){ Serial.begin(9600); // capteurs & intermessage reçu. pinMode(SWITCHPIN, INPUT_PULLUP)float tempValue = 0; // pour l'interrupteur // la communication radio vw_setup(2000); // Bits par seconde (2000 float humidityValue = bonne portée. Si augmente, portée diminue vw_set_tx_pin(3)0; // La broche 3 pour transmettre la DATA // on lance le capteur de temp + hygro Serial.println("DHTxx test!")int luxValue = 0; dht.begin()float hygrometryValue = 0;}
////////////////////////// le loooooooop ///////////////////////////////////////
void setup() {
Serial.begin(9600);
vw_setup(2000); // Bits par seconde
vw_set_rx_pin(RADIO_PIN); // broche DATA du récepteur
vw_rx_start();
Serial.println("Virtual wire started");
}
void loop(){ // Get current button state.{ uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; time String ficelle= millis""; if (vw_get_message(buf, &buflen)) // On test afin de savoir si un message est reçu. { int i; int nombre; getTemp //Serial.println(time"nouveau msg"); for (i = 0; i <= buflen; i++) { ficelle+=char(buf[i]); //getMsgContentmsg lettre par lettre. buf[4] == 5ème lettre envoyée } ficelle[buflen] = '\0'; Serial.print(time"ficelle : "); Serial.println(ficelle); //on juste après commence l'imprimeappel de fonction qui ajuste les variables sendMsg //on récupère une sous-partie du message ficelle.substring(time0,2); // qu'on doit assembler les valeurs convertit en tableau de charentier .toInt() tempValue=(ficelle.substring(0,2).toInt()); humidityValue=(ficelle.substring(2,4).toInt()); }
}
////////////////////////// les fonctions ///////////////////////////////////////============== FIN DU LOOP ==============================
void getTemp(long time) { float t; float h; if (time - latestDHTSensingMillis > sensingDHTIntervalMillis){ //Serial.println("get"); t = dht.readTemperature(); h = dht.readHumidity(); if (isnan(t) || isnan(h)) Serial.println("capteur DHT injoignable!"); else itoa(t, tempValue, 5); itoa(h, humidityValue, 5); latestDHTSensingMillis = time; return; Serial.println(" "); Serial.print("Temperature : "); Serial.println(t); Serial.print("Humidity : "); Serial.println(h); Serial.println(" "); latestDHTSensingMillis = time; return; }}========== emplacements de vos fonctions ==============================
void sendMsg(long time)
{
if (time - latestSendingMillis > sendingIntervalMillis){
//Serial.println("Msg");
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // On attend la fin de l'envoi du msg.
latestSendingMillis = time;
delay(25);
}
}
char buildMyTempValue(char tempValue){ return;}//============== fonctions à ne pas modifier ==============================
char charCipher(char entier)
{
char lettre='a';
switch(entier){
case '0':
break;
case '1':
lettre = 'b';
break;
case '2':
lettre = 'b';
break;
case '3':
lettre = 'b';
break;
case '4':
lettre = 'b';
break;
case '5':
lettre = 'b';
break;
case '6':
lettre = 'b';
break;
case '7':
lettre = 'b';
break;
case '8':
lettre = 'b';
break;
case '9':
lettre = 'b';
break;
}
return char(lettre);
}
</pre>
[[Catégorie:Projets]]=== code d'exmple pour le PIR (détecteur de mouvement infrarouge ===[[Catégorie:Edna]][[Catégoriehttps:Workshops]]//learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
Emailconfirmed
471
modifications