Skip to content

Instantly share code, notes, and snippets.

@bmidgley
Created February 18, 2018 18:33
Show Gist options
  • Save bmidgley/6d957e0544bdbd775110c7d28c54c68f to your computer and use it in GitHub Desktop.
Save bmidgley/6d957e0544bdbd775110c7d28c54c68f to your computer and use it in GitHub Desktop.
esp8266 moisture detector v1
/* wetness sensor v1
* active buzzer is connected to D1
* sensor is connected to A0
* temp sensor is connected to D3
* lolin nodemcu uses D4 for its LED
*/
#include <ESP8266WiFi.h>
#define THRESHHOLD 20
#define BUZZER D1
#define LED D4
const char* ssid = "network";
const char* password = "password";
void setup() {
Serial.begin(9600);
pinMode(BUZZER, OUTPUT);
pinMode(LED, OUTPUT);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
int wetness = analogRead(A0);
Serial.printf("analog %d\n", wetness);
digitalWrite(BUZZER, wetness < THRESHHOLD ? LOW : HIGH);
digitalWrite(LED, wetness > THRESHHOLD ? LOW : HIGH);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment