Devices & Components
Micro-USB to USB Cable (Generic)
Jumper wires (generic)
Temperature Sensor
Arduino MKR1000
Phototransistor HW5P-1
Breadboard (generic)
Software & Tools
Google Sheets
Maker service
Project description
Code
Direct code - Data collection though IFTTT - temperature and light sensor
arduino
Adapt the WIFI and IFTTT parameters then upload to MKR1000 /!\ Check for updates in the Github version
1/* 2 Dynamic monitoring with IFTTT, MKR1000 and Google Sheets 3 4 Connect to WIFI and IFTTT to monitor temperature as well as light sensor inputs. 5 /!\Adapt the WIFI and IFTTT parameters before uploading to MKR1000 in an ardunio_secrets.h file 6 7 Created 21/03/2021 8 By Sophie Marchand 9 10*/ 11 12#include "arduino_secrets.h" 13#include <WiFi101.h> 14 15//For Internet connection 16const char* MY_SSID = SECRET_SSID; // /!\to define in ardunio_secrets.h file 17const char* MY_PASS = SECRET_PASS; // /!\to define in ardunio_secrets.h file 18int status = WL_IDLE_STATUS; 19 20//For IFTTT 21WiFiClient IftttClient; 22const char* MY_HOST = "maker.ifttt.com"; 23int MY_PORT = 80; 24const char* MY_EVENT = SECRET_EVENT; // /!\to define in ardunio_secrets.h file 25const char* MY_API_KEY = SECRET_API_KEY; // /!\to define in ardunio_secrets.h file 26 27//Sensors inputs management 28int lightPin = A0; 29int temperaturePin = A1; 30float temperatureValueC; 31int lightValue; 32int frenquencyUpdateMs; 33 34void setup() 35{ 36 //Initiate serial and wait for port to open: 37 Serial.begin(9600); 38 while(!Serial); // to comment if you want to power MKR1000 without the computer 39 delay(2000); 40 41 //Connect to Wifi 42 Serial.print("Connecting Wifi... "); 43 while(WiFi.begin(MY_SSID, MY_PASS) != WL_CONNECTED){ 44 Serial.print(". "); 45 delay(500); 46 } 47 Serial.print(WiFi.SSID()); 48 Serial.println(" connected!"); 49 Serial.println(""); 50} 51 52 53void loop() 54{ 55 temperatureValueC = get_temperatureC(); 56 lightValue = get_light(); 57 frenquencyUpdateMs = 1 * 60 * 1000; //update every x min 58 send_values_to_itttf(temperatureValueC, lightValue, frenquencyUpdateMs); 59} 60 61/****************Helper functions*****************/ 62 63float get_temperatureC() 64{ 65 int readPin = analogRead(temperaturePin); 66 float voltage = readPin * 3.3 / 1024.0; //convert ADC reading to voltage - Vcc 3.3 for MKR1000 change if other board used 67 float temperatureC = (voltage - 0.5) * 100; //remove offset and convert to degree Celsius 68 69 return temperatureC; 70} 71 72int get_light() 73{ 74 int light = analogRead(lightPin); 75 76 return light; 77} 78 79void send_values_to_itttf(float temperatureC, int light, int frequencyMs) 80{ 81 String _temperature = String(temperatureC); 82 String _light = String(light); 83 84 if (IftttClient.connect(MY_HOST, MY_PORT)) // Connect to server and send message 85 { 86 Serial.print("Connected to IFTTT, sending... "); 87 IftttClient.println(String("GET ") + "/trigger/" + String(MY_EVENT) + "/with/key/" + String(MY_API_KEY) + "?value1=" + _temperature + "&value2=" + _light + " HTTP/1.1"); 88 IftttClient.println("Host: "+ String(MY_HOST)); 89 IftttClient.println("Connection: close"); 90 IftttClient.println(); 91 92 Serial.print("temperature in C: "); 93 Serial.print(_temperature); 94 Serial.print(" and light: "); 95 Serial.println(_light); 96 97 delay(frequencyMs); 98 IftttClient.stop(); // Disconnect from the server 99 } 100 else 101 { 102 Serial.println("Failed to connect to client"); 103 } 104}
Github - Data collection though IFTTT - temperature and light sensor
Adapt the WIFI and IFTTT parameters then upload to MKR1000
Direct code - Data collection though IFTTT - temperature and light sensor
arduino
Adapt the WIFI and IFTTT parameters then upload to MKR1000 /!\ Check for updates in the Github version
1/* 2 Dynamic monitoring with IFTTT, MKR1000 and Google Sheets 3 4 Connect to WIFI and IFTTT to monitor temperature as well as light sensor inputs. 5 /!\Adapt the WIFI and IFTTT parameters before uploading to MKR1000 in an ardunio_secrets.h file 6 7 Created 21/03/2021 8 By Sophie Marchand 9 10*/ 11 12#include "arduino_secrets.h" 13#include <WiFi101.h> 14 15//For Internet connection 16const char* MY_SSID = SECRET_SSID; // /!\to define in ardunio_secrets.h file 17const char* MY_PASS = SECRET_PASS; // /!\to define in ardunio_secrets.h file 18int status = WL_IDLE_STATUS; 19 20//For IFTTT 21WiFiClient IftttClient; 22const char* MY_HOST = "maker.ifttt.com"; 23int MY_PORT = 80; 24const char* MY_EVENT = SECRET_EVENT; // /!\to define in ardunio_secrets.h file 25const char* MY_API_KEY = SECRET_API_KEY; // /!\to define in ardunio_secrets.h file 26 27//Sensors inputs management 28int lightPin = A0; 29int temperaturePin = A1; 30float temperatureValueC; 31int lightValue; 32int frenquencyUpdateMs; 33 34void setup() 35{ 36 //Initiate serial and wait for port to open: 37 Serial.begin(9600); 38 while(!Serial); // to comment if you want to power MKR1000 without the computer 39 delay(2000); 40 41 //Connect to Wifi 42 Serial.print("Connecting Wifi... "); 43 while(WiFi.begin(MY_SSID, MY_PASS) != WL_CONNECTED){ 44 Serial.print(". "); 45 delay(500); 46 } 47 Serial.print(WiFi.SSID()); 48 Serial.println(" connected!"); 49 Serial.println(""); 50} 51 52 53void loop() 54{ 55 temperatureValueC = get_temperatureC(); 56 lightValue = get_light(); 57 frenquencyUpdateMs = 1 * 60 * 1000; //update every x min 58 send_values_to_itttf(temperatureValueC, lightValue, frenquencyUpdateMs); 59} 60 61/****************Helper functions*****************/ 62 63float get_temperatureC() 64{ 65 int readPin = analogRead(temperaturePin); 66 float voltage = readPin * 3.3 / 1024.0; //convert ADC reading to voltage - Vcc 3.3 for MKR1000 change if other board used 67 float temperatureC = (voltage - 0.5) * 100; //remove offset and convert to degree Celsius 68 69 return temperatureC; 70} 71 72int get_light() 73{ 74 int light = analogRead(lightPin); 75 76 return light; 77} 78 79void send_values_to_itttf(float temperatureC, int light, int frequencyMs) 80{ 81 String _temperature = String(temperatureC); 82 String _light = String(light); 83 84 if (IftttClient.connect(MY_HOST, MY_PORT)) // Connect to server and send message 85 { 86 Serial.print("Connected to IFTTT, sending... "); 87 IftttClient.println(String("GET ") + "/trigger/" + String(MY_EVENT) + "/with/key/" + String(MY_API_KEY) + "?value1=" + _temperature + "&value2=" + _light + " HTTP/1.1"); 88 IftttClient.println("Host: "+ String(MY_HOST)); 89 IftttClient.println("Connection: close"); 90 IftttClient.println(); 91 92 Serial.print("temperature in C: "); 93 Serial.print(_temperature); 94 Serial.print(" and light: "); 95 Serial.println(_light); 96 97 delay(frequencyMs); 98 IftttClient.stop(); // Disconnect from the server 99 } 100 else 101 { 102 Serial.println("Failed to connect to client"); 103 } 104}
Github - Data collection though IFTTT - temperature and light sensor
Adapt the WIFI and IFTTT parameters then upload to MKR1000
Downloadable files
Schema wiring MKR1000 with temperature and light sensor
Schema wiring MKR1000 with temperature and light sensor

Comments
Only logged in users can leave comments