I am brewing beer and I want to keep track of the bubbles that from yeast. I have a mic strapped to airlock(where bubble are). I want to see that how many bubbles were the in past minute. Also want to keep histogram.
My question is how should I do that. I want to count bubbles/minute and update it once in 30 seconds or a minute or so. So I wont DDoS the server.
I am a begginner in coding so sorry for that. My code is not working. Actually it is working but when mic digital pin is high for at least 1 second or more. I want it to gather every bubble sound as +1 for counter.
int micState = 0;
int lastMicState = 0;
char auth[] = "****";
SimpleTimer timer;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "****";
char pass[] = "*****";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(2000L, sendUptime);
timer.setInterval(1000L, bubble);
sensors.begin();
pinMode(led, OUTPUT);
pinMode(mic, INPUT);
digitalWrite(led, LOW);
}
void sendUptime()
{
bla bla bla
}
void bubble()
{
micState = digitalRead(mic);
if (micState != lastMicState)
{
if (micState == HIGH)
{
bubbleCounter++;
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
lastMicState = micState;
}
Blynk.virtualWrite(V1, bubbleCounter);
}
void loop()
{
Blynk.run();
timer.run();
}
I tried without blynk, in the loop. It worked. How do I do with blynk. And I know it is not bubble/minute yet. It will be. Thanks.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
unsigned long bubbles;
char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
BlynkTimer timer;
void setup()
{
Blynk.begin(auth, ssid, pass);
ArduinoOTA.begin();
timer.setInterval(60000L, bubbleTimer);
attachInterrupt(4, bubbleCounter, RISING); // d2 pin. here comes the mic signal + a ~10k pulldown (try lower / higher value if not working)
}
void loop()
{
ArduinoOTA.handle(); // handles over the air code uploading
Blynk.run();
timer.run();
}
void bubbleTimer() // one minute timer function
{
Blynk.virtualWrite(0, bubbles); // sends to virtual pin 0 the counted bubbles, every minute
bubbles = 0; // then resets counter value
}
void bubbleCounter() // interrupt isr
{
bubbles++; // increments value for every mic "high" signal
}
ok. please report back how it goes. the value of the pullup probably will be very important, because it should be strong enough to keep the pin low to prevent floating when no signal is coming, but in the same time has to be weak enough, to allow for the mic signal (which is probably very weak), to pull it high.
if you could have an oscilloscope, would be very helpful, to see exactly what is going on…
what is the value of the pulldown resistor you added?
if you remove the mic from d2, the numbers remain 0?
the mic on the picture has analog and digital output. for interrupt you should use the digital output, but you have to set the threshold level with the trimpot first
I set the threshold and I’ve connected it with digital out.
And I have an idea. Is there a way that I can measure the time between two bubbles and change it the bubble/minute than send it to blynk without ddos’ing.
For example For example if there is 400ms between two bubbles it would be.60000/400= 150 bubbles/minute.
if it goes crazy, than i would be courious exactely how you added that pull down resistor…
it should be between d2 pin and gnd.
yes, it is possible to measure time between bubbles, but it will have very low precision for bubbles per minute… first i would recommend to leave the code exactely as i wrote, because that should be correct.
@erolcanulutas, sorry, i think i made a mistake in the code. you should replace the 4 in attacheinterrupt to 2, and hook up the pulldown resistor and mic to d4 pin, instead of d2. sorry.
I didnt disconnect mic side, I disconnected esp side. let me try other way while resistor still doing its job.
I tried and it’s always zero.
“if that works, take a jumper wire, hook up to 3.3v, and touch the d2 pin. you should see the numbers incrementing in the app.”
Yeah, I saw the incrementing numbers but one touch increments 3, 3 touch 11. like that. Than connected the mic. similar, sometimes 0 sometimes sometimes correct number sometimes 2 while it should be 6 or so.
Also there was no mistake with pins, gpio04 is d2, gpio02 is d4 and d4 is tx so it would be better if use d2 which is gpio04