Last active
January 7, 2018 21:01
-
-
Save jplattel/1a7e76f1fedf7caa43753fcde04b6a24 to your computer and use it in GitHub Desktop.
A simple bubble counter for a Wemos D1 mini lite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Bubble Counter for fermentation processes | |
Made by: Joost Plattel | |
Email: [email protected] | |
This little arduino project is used for tracking fermentation processes | |
it works with a little photo interupter and posts the bubble count every | |
10 minutes to a endpoint specified. | |
*/ | |
#include <Arduino.h> | |
#include <ESP8266WiFi.h> | |
#include <ESP8266HTTPClient.h> | |
bool DEBUG = true; | |
int sensorPin = 0; // select the input pin for the photo interrupter | |
int sensorValue = 0; // variable to store the value coming from the sensor | |
int ledPin = 5; // D1 on the WEMOS | |
int bubbleCount = 0; // Count for bubbles (resets after sending) | |
int timer = 0; // | |
int timerTrigger = 12000; // 50ms * 10 * 60 * 10 = 12000 = every 10 minutes | |
const char* ssid = "wifissid"; | |
const char* password = "password"; | |
const char* endpoint = "http://yourendpoint.beer; | |
HTTPClient http; | |
void setup() { | |
pinMode(ledPin, OUTPUT); | |
Serial.begin(9600); // set up Serial library at 9600 bps | |
// Connect to WiFi network | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
// Connect to wifi | |
WiFi.begin(ssid, password); | |
// Blink the green LED when it is connecting | |
while (WiFi.status() != WL_CONNECTED) { | |
digitalWrite(ledPin, HIGH); | |
delay(500); | |
Serial.print("."); | |
digitalWrite(ledPin, LOW); | |
delay(500); | |
} | |
Serial.println("Connected!"); | |
} | |
void loop() { | |
// read the value from the sensor | |
sensorValue = analogRead(sensorPin); | |
// print the sensor value to the serial monito | |
// if (DEBUG) { Serial.println(sensorValue); } | |
if (sensorValue < 100) { | |
// Blink the green LED. | |
digitalWrite(ledPin, HIGH); | |
bubbleCount++; // Increment bubble count | |
if (DEBUG) { Serial.println("Bubble!"); } | |
} | |
// Increment the timer | |
delay(50); | |
timer++; | |
if (timer > timerTrigger) { | |
digitalWrite(ledPin, HIGH); | |
// Make a request to the endpoint with the bubble count | |
http.begin(endpoint); | |
http.addHeader("Content-Type", "application/json"); | |
int httpCode = http.POST("{'bubbles': " + String(bubbleCount) + "}"); | |
// Print status-code and close the connection | |
Serial.println(httpCode); // Print HTTP return code | |
http.end(); //Close connection | |
// Reset timer | |
timer = 0; | |
} | |
// Turn of the green LED | |
digitalWrite(ledPin, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment