
The code below will give you a kit like this one.


| #include<Adafruit_NeoPixel.h>//Adafruit Neo Pixel by Adafruit | |
| #include<WiFi.h> | |
| #include<HTTPClient.h> | |
| #include<OneWire.h>//library manager | |
| #include<DallasTemperature.h> | |
| #defineLED_PIN26//outa26 outb13 | |
| #defineNUMPIXELS48 | |
| #definesensorPin13//INA:33 INB:32 | |
| float moisture = 0; | |
| float sensorValue = 0; | |
| #defineONE_WIRE_BUS33//INA:33 INB:32 | |
| #defineSENSER_BIT9// Precision setting bit | |
| #definecdsPin32//INPUTA:33 INPUTB:32 | |
| float lux = 0; | |
| // SSID and password to connect to | |
| constchar* ssid = "xxxxxxxxx"; | |
| constchar* password = "xxxxxxxxxxxx"; | |
| //Your Domain name with URL path or IP address with path | |
| String serverName = "https://script.google.com/macros/s/AKfycbxINUMbng44NUpPhd0qqhrnGlyVRLVDwJKj8UMs2Ms7cZ5cy4UigcCFkI6jcONmmwQX/exec"; | |
| // the following variables are unsigned longs because the time, measured in | |
| // milliseconds, will quickly become a bigger number than can be stored in an int. | |
| unsignedlong lastTime = 0; | |
| // Timer set to 10 minutes (600000) | |
| //unsigned long timerDelay = 600000; | |
| // Set timer to 5 seconds (5000) | |
| unsignedlong timerDelay = 5000; | |
| Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800); | |
| OneWire oneWire(ONE_WIRE_BUS); | |
| DallasTemperature sensors(&oneWire); | |
| voidsetup() { | |
| pixels.begin(); | |
| Serial.begin(115200); | |
| pinMode(sensorPin, INPUT); | |
| sensors.setResolution(SENSER_BIT); | |
| pinMode(cdsPin, INPUT); | |
| connectWiFi(); | |
| } | |
| voidloop() { | |
| sensorValue = analogRead(sensorPin); | |
| moisture = sensorValue / 2224 * 100; //Initial value 2224. Value read by analog reading in water. | |
| Serial.print(moisture); | |
| Serial.println("%"); | |
| sensors.requestTemperatures(); // Temperature acquisition request | |
| Serial.println(sensors.getTempCByIndex(0)); //Temperature acquisition & serial transmission | |
| float cds_ad = analogRead(cdsPin); | |
| float cds_v = cds_ad * 3.3 / 4096; | |
| lux = 10000 * cds_v / (3.3 - cds_v) / 1000; | |
| Serial.print(lux); | |
| Serial.println(" Lux "); | |
| sendData(); | |
| uint16_t i, j, k; | |
| for(i=0; i<NUMPIXELS; i++){ | |
| pixels.setPixelColor(i,pixels.Color(60,60,60)); | |
| } | |
| pixels.show(); | |
| delay(10000); | |
| for(k=0; k<4; k++){ | |
| for(j=0; j <256; j++) { | |
| for(i=0; i < pixels.numPixels(); i++) { | |
| pixels.setPixelColor(i, rotateColor((((i) * 256 / pixels.numPixels()) + j) & 255)); | |
| } | |
| pixels.show(); | |
| delay(1); | |
| } | |
| } | |
| } | |
| //RGB color transition function | |
| uint32_trotateColor(byte WheelPos) { | |
| if(WheelPos < 85) { | |
| return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0); | |
| } elseif(WheelPos < 170) { | |
| WheelPos -= 85; | |
| return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3); | |
| } else { | |
| WheelPos -= 170; | |
| return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3); | |
| } | |
| } | |
| //Connect to WiFi | |
| voidconnectWiFi(){ | |
| WiFi.begin(ssid, password); | |
| Serial.println("Connecting"); | |
| while(WiFi.status() != WL_CONNECTED) { | |
| delay(500); | |
| Serial.print("."); | |
| } | |
| Serial.println(""); | |
| Serial.print("Connected to WiFi network with IP Address: "); | |
| Serial.println(WiFi.localIP()); | |
| Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading."); | |
| } | |
| //Transmission of measurement data | |
| voidsendData(){ | |
| //Send an HTTP POST request every 10 minutes | |
| if ((millis() - lastTime) > timerDelay) { | |
| //Check WiFi connection status | |
| if(WiFi.status()== WL_CONNECTED){ | |
| HTTPClient http; | |
| String serverPath = serverName + "?data1=" + moisture + "&data2=" + sensors.getTempCByIndex(0) + "&data3=" + lux; | |
| // Your Domain name with URL path or IP address with path | |
| http.begin(serverPath.c_str()); | |
| // Send HTTP GET request | |
| int httpResponseCode = http.GET(); | |
| if (httpResponseCode>0) { | |
| Serial.print("HTTP Response code: "); | |
| Serial.println(httpResponseCode); | |
| String payload = http.getString(); | |
| Serial.println(payload); | |
| } | |
| else { | |
| Serial.print("Error code: "); | |
| Serial.println(httpResponseCode); | |
| } | |
| // Free resources | |
| http.end(); | |
| } | |
| else { | |
| Serial.println("WiFi Disconnected"); | |
| } | |
| lastTime = millis(); | |
| } | |
| } |
