Étape 3 : Programmer l’Arduino Nano
Télécharger le code ici
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
ou consultez-le ici :
#include <VirtualWire.h> //Download Here#include "DHT.h"DHT dht(2, DHT11);int Sensor1Data; int Sensor2Data; char Sensor1CharMsg[4]; char Sensor2CharMsg[4];void setup() { vw_set_ptt_inverted(true); // Required by the RF module vw_setup(2000); // bps connection speed vw_set_tx_pin(3); // Arduino pin to connect the receiver data pin //Serial.begin(9600); //uncomment to debug dht.begin(); Serial.println();}void loop() { Serial.println("\n"); Sensor1Data = dht.readTemperature(true); Sensor2Data = dht.readHumidity(); delay(2000); // Convert integer data to Char array directly itoa(Sensor1Data, Sensor1CharMsg, 10); itoa(Sensor2Data, Sensor2CharMsg, 10); Serial.print("Read sensor: "); char astr[4] = {'t', 'e', 'm', 'p',}; char bstr[4] = {'h', 'u', 'm', 'i',}; Serial.print("Humidity (%): "); Serial.println((float)dht.readHumidity(), 2); Serial.print("Temperature (oC): "); Serial.println((float)dht.readTemperature(true), 2); delay(1000); //Message to send: digitalWrite(13, true); // Turn on a light to show transmitting vw_send((uint8_t *)astr, 4); vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg)); vw_send((uint8_t *)bstr, 4); vw_send((uint8_t *)Sensor2CharMsg, strlen(Sensor2CharMsg)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(13, false); // Turn off a light after transmission delay(9000); }