/ adafruitio-temp-motion-wing / adafruitio-temp-motion-wing.ino
adafruitio-temp-motion-wing.ino
1 // SPDX-FileCopyrightText: 2019 Brent Rubell for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 // Adafruit IO - Analog Devices ADT7410 + ADXL343 Example 6 // 7 // Adafruit invests time and resources providing this open source code. 8 // Please support Adafruit and open source hardware by purchasing 9 // products from Adafruit! 10 // 11 // Written by Brent Rubell for Adafruit Industries 12 // Copyright (c) 2019 Adafruit Industries 13 // Licensed under the MIT license. 14 // 15 // All text above must be included in any redistribution. 16 17 /************************ Adafruit IO Config *******************************/ 18 // visit io.adafruit.com if you need to create an account, 19 // or if you need your Adafruit IO key. 20 #define IO_USERNAME "YOUR_IO_USERNAME" 21 #define IO_KEY "YOUR_IO_KEY" 22 23 /******************************* WiFi Config ********************************/ 24 #define WIFI_SSID "WIFI_NAME" 25 #define WIFI_PASS "WIFI_PASS" 26 27 // comment out the following two lines if you are using fona or ethernet 28 #include "AdafruitIO_WiFi.h" 29 AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); 30 31 /************************** Configuration ***********************************/ 32 // time between sending data to adafruit io, in seconds. 33 #define IO_DELAY 5 34 /************************ Example Starts Here *******************************/ 35 #include <Wire.h> 36 #include <Adafruit_Sensor.h> 37 #include "Adafruit_ADT7410.h" 38 #include <Adafruit_ADXL343.h> 39 40 float tempC, accelX, accelY, accelZ; 41 42 // Create the ADT7410 temperature sensor object 43 Adafruit_ADT7410 tempsensor = Adafruit_ADT7410(); 44 45 // Create the ADXL343 accelerometer sensor object 46 Adafruit_ADXL343 accel = Adafruit_ADXL343(12345); 47 48 // set up the 'temperature' feed 49 AdafruitIO_Feed *huzzah_temperature = io.feed("temperature"); 50 51 // set up the 'accelX' feed 52 AdafruitIO_Feed *huzzah_accel_x = io.feed("accelX"); 53 54 // set up the 'accelY' feed 55 AdafruitIO_Feed *huzzah_accel_y = io.feed("accelY"); 56 57 // set up the 'accelZ' feed 58 AdafruitIO_Feed *huzzah_accel_z= io.feed("accelZ"); 59 60 void setup() 61 { 62 // start the serial connection 63 Serial.begin(115200); 64 65 // wait for serial monitor to open 66 while (!Serial) 67 ; 68 69 Serial.println("Adafruit IO - ADT7410 + ADX343"); 70 71 /* Initialise the ADXL343 */ 72 if(!accel.begin()) 73 { 74 /* There was a problem detecting the ADXL343 ... check your connections */ 75 Serial.println("Ooops, no ADXL343 detected ... Check your wiring!"); 76 while(1); 77 } 78 79 /* Set the range to whatever is appropriate for your project */ 80 accel.setRange(ADXL343_RANGE_16_G); 81 82 /* Initialise the ADT7410 */ 83 if (!tempsensor.begin()) 84 { 85 Serial.println("Couldn't find ADT7410!"); 86 while (1) 87 ; 88 } 89 90 // sensor takes 250 ms to get first readings 91 delay(250); 92 93 // connect to io.adafruit.com 94 Serial.print("Connecting to Adafruit IO"); 95 io.connect(); 96 97 // wait for a connection 98 while (io.status() < AIO_CONNECTED) 99 { 100 Serial.print("."); 101 delay(500); 102 } 103 104 // we are connected 105 Serial.println(); 106 Serial.println(io.statusText()); 107 } 108 109 void loop() 110 { 111 // io.run(); is required for all sketches. 112 // it should always be present at the top of your loop 113 // function. it keeps the client connected to 114 // io.adafruit.com, and processes any incoming data. 115 io.run(); 116 117 /* Get a new accel. sensor event */ 118 sensors_event_t event; 119 accel.getEvent(&event); 120 121 accelX = event.acceleration.x; 122 accelY = event.acceleration.y; 123 accelZ = event.acceleration.z; 124 125 /* Display the results (acceleration is measured in m/s^2) */ 126 Serial.print("X: "); Serial.print(accelX); Serial.print(" "); 127 Serial.print("Y: "); Serial.print(accelY); Serial.print(" "); 128 Serial.print("Z: "); Serial.print(accelZ); Serial.print(" ");Serial.println("m/s^2 "); 129 130 // Read and print out the temperature 131 tempC = tempsensor.readTempC(); 132 Serial.print("Temperature: "); Serial.print(tempC); Serial.println("C"); 133 134 Serial.println("Sending to Adafruit IO..."); 135 huzzah_temperature->save(tempC, 0, 0, 0, 2); 136 huzzah_accel_x->save(accelX); 137 huzzah_accel_y->save(accelY); 138 huzzah_accel_z->save(accelZ); 139 Serial.println("Data sent!"); 140 141 Serial.print("Waiting ");Serial.print(IO_DELAY);Serial.println(" seconds..."); 142 // wait IO_DELAY seconds between sends 143 for (int i = 0; i < IO_DELAY; i++) 144 { 145 delay(1000); 146 } 147 }