M.Kevin Marcelino
Published

Dough Monitoring In Sourdough Bread Making

How to achieve optimum bulk fermentation in sourdough bread with monitoring its pH.

AdvancedShowcase (no instructions)24 hours987
Dough Monitoring In Sourdough Bread Making

Things used in this project

Story

Read more

Code

doughmonitoring

Arduino
#define BLYNK_TEMPLATE_ID "T3ererercG_"
#define BLYNK_DEVICE_NAME "Dough Monitor"
#define BLYNK_AUTH_TOKEN "token"
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 5

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature DS18B20(&oneWire);
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <SimpleTimer.h>
#include <ErriezRobotDyn4DigitDisplay.h>
#include <DHT.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#define TM1637_CLK_PIN      2
#define TM1637_DIO_PIN      3
#define DHTPIN 2        
#define DHTTYPE DHT22     // DHT 11

#define PHSensorPin  A0    //dissolved oxygen sensor analog output pin to arduino mainboard
#define VREF 4.83    //for arduino uno, the ADC reference is the AVCC, that is 5.0V(TYP)
#define OFFSET 0.00  //zero drift compensation

#define SCOUNT  30           // sum of sample point
int analogBuffer[SCOUNT];    //store the analog value in the array, readed from ADC
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0,copyIndex = 0;

float averageVoltage,phValue;
DHT dht(DHTPIN, DHTTYPE);
RobotDyn4DigitDisplay display(TM1637_CLK_PIN, TM1637_DIO_PIN);
char auth[] = "token";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "jancuk";
char pass[] = "tailedig";
/*
char ssid[] = "anjing";
char pass[] = "geronimo"*//*
int latchPin = 10;
int clockPin = 13;
int dataPin = 11;
fourMatrix m(11,10,13,4);*/

byte volt[] = {
  B00011,
  B00110,
  B01100,
  B11111,
  B00011,
  B00110,
  B01100,
  B11000
};


byte tempChar []= {
  0x04,
  0x0A,
  0x0A,
  0x0E,
  0x0E,
  0x1F,
  0x1F,
  0x0E
};
byte degree[] = {
  B00100,
  B01010,
  B00100,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte rh[] = {
  0x04,
  0x04,
  0x0E,
  0x0E,
  0x1B,
  0x11,
  0x1B,
  0x0E
};


#define EspSerial Serial3
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);



void setup()
{
    pinMode(PHSensorPin,OUTPUT);
    //lcd.clear();
    DS18B20.begin();
    lcd.createChar(0, tempChar);
    lcd.createChar(1, degree);
    lcd.createChar(2, rh);
    Serial.begin(9600);
    display.begin();
    lcd.begin();
    lcd.backlight();
    display.clear();
    dht.begin();
    delay(10);
    EspSerial.begin(ESP8266_BAUD);
    delay(10);
    Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
    
  
   
}


void phSpear()
{
  static unsigned long analogSampleTimepoint = millis();
  if(millis()-analogSampleTimepoint > 30U)     //every 30 milliseconds,read the analog value from the ADC
  {
     analogSampleTimepoint = millis();
     analogBuffer[analogBufferIndex] = analogRead(PHSensorPin);    //read the analog value and store into the buffer
     analogBufferIndex++;
     if(analogBufferIndex == SCOUNT)
         analogBufferIndex = 0;
  }
   static unsigned long printTimepoint = millis();
   if(millis()-printTimepoint > 1000U){
    printTimepoint = millis();
    for(copyIndex=0;copyIndex<SCOUNT;copyIndex++)
    {
      analogBufferTemp[copyIndex]= analogBuffer[copyIndex];
      }
      averageVoltage = getMedianNum(analogBufferTemp,SCOUNT) * (float)VREF / 1024.0; // read the value more stable by the median filtering algorithm
      phValue = 3.5 * averageVoltage + OFFSET;
      /*Serial.print("Voltage:");
      Serial.print(averageVoltage,2);
      Serial.print("   pH value:");
      Serial.println(phValue,2);*/
   }
}
int getMedianNum(int bArray[], int iFilterLen)
{
      int bTab[iFilterLen];
      for (byte i = 0; i<iFilterLen; i++)
      {
      bTab[i] = bArray[i];
      }
      int i, j, bTemp;
      for (j = 0; j < iFilterLen - 1; j++)
      {
      for (i = 0; i < iFilterLen - j - 1; i++)
          {
        if (bTab[i] > bTab[i + 1])
            {
        bTemp = bTab[i];
            bTab[i] = bTab[i + 1];
        bTab[i + 1] = bTemp;
         }
      }
      }
      if ((iFilterLen & 1) > 0)
    bTemp = bTab[(iFilterLen - 1) / 2];
      else
    bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2;
      return bTemp;
}
  

void sendSensor()
{
  pinMode(PHSensorPin,INPUT);
  lcd.backlight();
  lcd.createChar(0, tempChar);
  lcd.createChar(1, degree);
  lcd.createChar(2, rh);
  lcd.createChar(3, volt);
  float tempdough;
  float Fahrenheit=0;
  int h = dht.readHumidity();
  int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  int temp1 = t / 10;
  int temp2 = t % 10;
  int temp = t,dec;
  Blynk.virtualWrite(V5, temp); //suhu virtual 5
  Blynk.virtualWrite(V6, h); //kelembaban virtual 6
  Blynk.virtualWrite(V7, phValue); //kelembaban virtual 6
  lcd.setCursor(0,0);
  lcd.print("DOUGH MONITORING");
  lcd.setCursor(0,1);
  lcd.write(0);
  //lcd.setCursor(12,1);
  //lcd.write(2);
  lcd.setCursor(14,1);
  lcd.print("pH");
  lcd.setCursor(10,1);
  lcd.print(phValue);
  DS18B20.requestTemperatures(); 
  tempdough = DS18B20.getTempCByIndex(0); // Celcius
  //int tempdoughc= (float)tempdough/10,1;
  Fahrenheit = DS18B20.toFahrenheit(tempdough); // Fahrenheit;
  Blynk.virtualWrite(V8, tempdough); //virtual pin V3
  Blynk.virtualWrite(V9, Fahrenheit); //virtual pin V4
  lcd.setCursor(5,1);
  lcd.write(1);
  lcd.setCursor(1,1);
  lcd.print((float)tempdough,1);
  lcd.setCursor(6,1);
  lcd.print("C");
  phSpear();
  delay(1000);

}

void loop()
{


  Blynk.run();
  sendSensor();

  
}

Credits

M.Kevin Marcelino

M.Kevin Marcelino

1 project • 1 follower

Comments