Temperature, humidity, and water level monitoring
In this project, we used DHT11 to detect temperature and humidity and water level sensor to detect water level. There are 4 LEDs to indicate
Apps and platforms
1
PushingBox
1
Arduino Web Editor
1
Google Sheets
Project description
Code
Untitled file
c_cpp
1//----------------------------------------------- 2//Since Arduino can't https, we need to use Pushingbox API (uses http)to run 3//the Google Script (uses https). Alternatly use Ivan's SecureWifi encryption 4 5 6#include <WiFi101.h> 7#include "DHT.h" 8 9#define DHTPIN 6 // what pin we're connected to, pin1 is 5th pin from end 10 11// Uncomment whatever DHT sensor type you're using! 12#define DHTTYPE DHT11 // DHT 11 13//#define DHTTYPE DHT21 // DHT 21 14 15 16DHT dht(DHTPIN,DHTTYPE); 17 18const char WEBSITE[] = "api.pushingbox.com"; //pushingbox API server 19const String devid = "v8FF17EFF7B58B29"; //device ID on Pushingbox for our Scenario 20 21const char* MY_SSID = "VIRGIN610"; 22const char* MY_PWD = "3745E496949E"; 23 24 25int status = WL_IDLE_STATUS; 26// if you don't want to use DNS (and reduce your sketch size) 27// use the numeric IP instead of the name for the server: 28//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) 29 30int led1 = 1; 31int led2 = 2; 32int led3 = 3; 33int led4 = 4; 34 35void setup() { 36 // initialize the digital pins as an outputs. 37 pinMode(led1, OUTPUT); 38 pinMode(led2, OUTPUT); 39 pinMode(led3, OUTPUT); 40 pinMode(led4, OUTPUT); 41 42 //Initialize serial and wait for port to open: 43 Serial.begin(9600); 44 while (!Serial) 45 { 46 ; // wait for serial port to connect. Needed for native USB port only 47 } 48 49 // check for the presence of the shield: 50 if (WiFi.status() == WL_NO_SHIELD) { 51 Serial.println("WiFi shield not present"); 52 // don't continue: 53 while (true); 54 } 55 56 // attempt to connect to Wifi network: 57 while (status != WL_CONNECTED) 58 { 59 Serial.print("Attempting to connect to SSID: "); 60 Serial.println(MY_SSID); 61 //Connect to WPA/WPA2 network.Change this line if using open/WEP network 62 status = WiFi.begin(MY_SSID, MY_PWD); 63 64 // wait 10 seconds for connection: 65 delay(10000); 66 } 67 68 Serial.println("Connected to wifi"); 69 printWifiStatus(); 70 dht.begin(); 71 72} 73 74void loop() { 75 76 // Wait between measurements. 77 delay(10000); 78 79 //prefer to use float, but package size or float conversion isnt working 80 //will revise in future with a string fuction or float conversion function 81 82 int humidityData = dht.readHumidity(); 83 // Read temperature as Celsius (the default) 84 int celData = dht.readTemperature(); 85 // Read temperature as Fahrenheit (isFahrenheit = true) 86 int fehrData = dht.readTemperature(true); 87 88 // read the input on analog pin 1: 89 int waterLevel = analogRead(A1); 90 91 digitalWrite(led1, LOW); 92 digitalWrite(led2, LOW); 93 digitalWrite(led3, LOW); 94 digitalWrite(led4, LOW); 95 if (waterLevel > 10) {digitalWrite(led1, HIGH); } 96 if (waterLevel > 250) {digitalWrite(led2, HIGH); } 97 if (waterLevel > 350) {digitalWrite(led3, HIGH); } 98 if (waterLevel > 390) {digitalWrite(led4, HIGH); } 99 100 101 // Check if any reads failed and exit early (to try again). 102 if (isnan(humidityData) || isnan(celData) || isnan(fehrData)) 103 { 104 Serial.println("Failed to read from DHT sensor!"); 105 return; 106 } 107 108 if (isnan(waterLevel)) 109 { 110 Serial.println("Failed to read from water level sensor!"); 111 return; 112 } 113 114 // Compute heat index in Fahrenheit (the default) 115 int hifData = dht.computeHeatIndex(fehrData, humidityData); 116 // Compute heat index in Celsius (isFahreheit = false) 117 int hicData = dht.computeHeatIndex(celData, humidityData, false); 118 119 Serial.print("Humidity: "); 120 Serial.print(humidityData); 121 Serial.print(" %\ "); 122 Serial.print("Temperature: "); 123 Serial.print(celData); 124 Serial.print(" *C "); 125 Serial.print(fehrData); 126 Serial.print(" *F\ "); 127 Serial.print("Heat index: "); 128 Serial.print(hicData); 129 Serial.print(" *C "); 130 Serial.print(hifData); 131 Serial.print(" Water Level "); 132 Serial.print(waterLevel); 133 Serial.println(" \ 134"); 135 136Serial.println("\ 137Sending Data to Server..."); 138 // if you get a connection, report back via serial: 139WiFiClient client; //Instantiate WiFi object, can scope from here or Globally 140 141 //API service using WiFi Client through PushingBox then relayed to Google 142 if (client.connect(WEBSITE, 80)) 143 { 144 client.print("GET /pushingbox?devid=" + devid 145 + "&humidityData=" + (String) humidityData 146 + "&celData=" + (String) celData 147 + "&fehrData=" + (String) fehrData 148 + "&hicData=" + (String) hicData 149 + "&hifData=" + (String) hifData 150 + "&waterLevel=" + (String) waterLevel 151 ); 152 153 // HTTP 1.1 provides a persistent connection, allowing batched requests 154 // or pipelined to an output buffer 155 client.println(" HTTP/1.1"); 156 client.print("Host: "); 157 client.println(WEBSITE); 158 client.println("User-Agent: MKR1000/1.0"); 159 //for MKR1000, unlike esp8266, do not close connection 160 client.println(); 161 Serial.println("\ 162Data Sent"); 163 } 164} 165 166 167void printWifiStatus() { 168 // print the SSID of the network you're attached to: 169 Serial.print("SSID: "); 170 Serial.println(WiFi.SSID()); 171 172 // print your WiFi shield's IP address: 173 IPAddress ip = WiFi.localIP(); 174 Serial.print("IP Address: "); 175 Serial.println(ip); 176 177 // print the received signal strength: 178 long rssi = WiFi.RSSI(); 179 Serial.print("signal strength (RSSI):"); 180 Serial.print(rssi); 181 Serial.println(" dBm"); 182}
Downloadable files
1_NYb5Jpvjp7.png
1_NYb5Jpvjp7.png

1_NYb5Jpvjp7.png
1_NYb5Jpvjp7.png

Comments
Only logged in users can leave comments