Blynk GrowBox

I have read a ton of info and it turns out I am not learning to code.

What I have is an Arduino mega with ethernet shield, dht 22 x 2 and a 8 relay board.

My goal was and still is to have my dht 22s provide data only.

The main goal is to have lights which are connected to relays on a timer.

Can anyone assist me in this as I am pulling my hair out.

Mainly some code to start pout would be fantastic!

Thanks

[code][code]#include <SPI.h>                    // Used by Blynk
#include <Ethernet.h>               // Used by Blynk
#include <BlynkSimpleEthernet.h>    // Used by Blynk
#include <Wire.h>                   // I2c
#include "DHT.h"                    // Use Arduino 20k pullup resistor 'activated in code'
#define BLYNK_PRINT Serial
char auth[] = "Auth Key";
WidgetLCD lcdA(V0);  //Set LCD widget to Advanced Mode - Widget to display project clock
WidgetTerminal terminal(V1);
//  DHT Reference Values - CHANGE THESE TO MANAGE YOUR ROOM'S CLIMATE - //
byte hiMaxTemp = 80;   // temp that triggers heat removal device(s) on
byte lowMaxTemp = 70;  // temp that triggers heat removal device(s) off
byte hiMinTemp = 55;   // temp that triggers heater on
byte lowMinTemp = 65;  // temp that triggers heater off
byte hiHum = 50;       // High humidity value that triggers dehumidifier on
byte lowHum = 40;      // Low humidity value that triggers dehumidifier off
float PHprobe = 15;          //pH meter connected to digital 15
BLYNK_WRITE(V2) {
  PHprobe = param.asFloat();  // 
}
#define lightA 22             //Relay 1/a  
#define lightB 23             //Relay 2/b  
#define pumpA 24              //Relay 3/c 
#define pumpB 25              //Relay 4/d  
#define ROpump 26             //Relay 5/e  
#define scrubberFan 27        //Relay 6/f  
#define heatVentA 28          //Relay 7/g  
#define heatVentB 29          //Relay 8/h 
#define TURN_ON 0 // TURN_ON and TURN_OFF are defined to account for Active LOW relays
#define TURN_OFF 1 // Used to switch relay states for on/off of 120VAC~ devices  
float b;

DHT dhtA(A0, DHT22);     // DHT instance named dhtA, (I/O pin, sensor type)
DHT dhtB(A2, DHT22);     // DHT instance named dhtB, (I/O pin, sensor type)
BlynkTimer timer;       // SimpleTimer instance named timer

void setup()
{
  Serial.begin(9600);
  //Serial2.begin() // For other baud rates
  //Serial3.begin() // For other baud rates
  Blynk.begin(auth);
  dhtA.begin();
  dhtB.begin();
  pinMode(A0, INPUT_PULLUP);    // DHT22 use internal 20k pullup resistors
  pinMode(A2, INPUT_PULLUP);
  Wire.begin();
  while (Blynk.connect() == false) {}
  timer.setInterval(2000L, pHread);      // 2 second intervals between timed routiness
  timer.setInterval(5001L, climateRoutine);   // 5 second intervals between climate routines
  delay(1000);
}

void climateRoutine()
{
  byte h1 = dhtA.readHumidity();          // f1 and h1 are fahrenheit and humidity readings
  byte f1 = dhtA.readTemperature(true);   // from DHT/A
  byte h2 = dhtB.readHumidity();          // f2 and h2 are fahrenheit and humidity readings
  byte f2 = dhtB.readTemperature(true);   // from DHT/B
  if (isnan(f1) || isnan(f2) || isnan(h1) || isnan(h2)) {
    terminal.println("Failed to read from a DHT sensor");
    terminal.flush();
    return;
  }
  Blynk.virtualWrite(V3, f1);      //  Set Virtual Pin 0 frequency to PUSH in Blynk app
  Blynk.virtualWrite(V4, h1);      //  Set Virtual Pin 1 frequency to PUSH in Blynk app
  Blynk.virtualWrite(V5, f2);      //  Set Virtual Pin 2 frequency to PUSH in Blynk app
  Blynk.virtualWrite(V6, h2);      //  Set Virtual Pin 3 frequency to PUSH in Blynk app
  //-------------------Bloom A Temp Test---------------------------------------//
  if (f1 >= hiMaxTemp)  //if "f1" is greater than or equal to hiMaxTemp,
  {
    digitalWrite(heatVentA, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the heat from Bloom A"); //  Text printed to terminal monitor
  }
  else if (f1 <= lowMaxTemp)  //  or else if "f1" is less than or equal to lowMaxTemp
  {
    digitalWrite(heatVentA, TURN_OFF); //  TURN_OFF relay E.
  }
  //-----------------------Bloom A Humidity Test-------------------------//
  if (h1 >= hiHum)  //if "h2" is greater than or equal to hiHum,
  {
    digitalWrite(scrubberFan, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the RH from Bloom A"); //  Text printed to terminal monitor
  }
  else if (h1 <= lowHum)  //  or else if "h1" is less than or equal to lowHum
  {
    digitalWrite(scrubberFan, TURN_OFF);
  }
  //-----------------------Bloom B Temp Test-----------------------------//
  if (f2 >= hiMaxTemp)  //if "f2" is greater than or equal to hiMaxTemp,
  {
    digitalWrite(heatVentB, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the heat from Bloom B"); //  Text printed to terminal monitor
  }
  else if (f2 <= lowMaxTemp)  //  or else if "f2" is less than or equal to lowMaxTemp
  {
    digitalWrite(heatVentB, TURN_OFF);
  }
  //-----------------------Bloom B Humidity Test-------------------------//
  if (h2 >= hiHum)  //if "h2" is greater than or equal to hiHum,
  {
    digitalWrite(scrubberFan, TURN_ON);  // TURN_ON heatVentA (fan).
    terminal.println("Exhausting the RH from Bloom B"); //  Text printed to terminal monitor
  }
  else if (h2 <= lowHum)  //  or else if "h2" is less than or equal to lowHum
  {
    digitalWrite(scrubberFan, TURN_OFF);
  }
  terminal.flush();
}

void pHread()
{
  int reading[10], total;
  int averageValue;  //Store the average value of the sensor feedback
  // Put the pH electrode into the standard solution whose pH value is 7.00
  // change calibrationOffset to the difference between your reading and 7.00
  float calibrationOffset = 0.0;

  for (int i = 0; i < 10; i++) //Get 10 sample value from the sensor for smooth the value
  {
    reading[i] = analogRead(PHprobe);  // returns int (0 to 1023)
    
  }
  
  for (int i = 0; i < 10; i++)
  {
    total = total + reading[i];
  }
  
  averageValue = total / sizeof(reading);
  
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = averageValue * (5.0 / 1024);
  float phValue = 3.5 * voltage + calibrationOffset;
  Serial.print("    pH:");
  Serial.print(phValue, 2);
  Serial.println(" ");
  terminal.print("    pH:");
  terminal.print(phValue, 2);
  terminal.println(" ");
  terminal.flush();
}

void loop()
{
  Blynk.run();
  timer.run();
}

[/code][/code]

That is one massive amount of code for someone who doesn't know how to code.

So what does it do, and what should it do?

Have you been able to get data from the DHT22s by simply reading them and dumping it to the Serial console? (I'm sure there's a piece of example code with the libraries).

Same for the other parts. Anything working on its own?

I agree.

I started out wanting PH monitored and failed.

Now What I am really trying to do is monitor temp humidity using 2 x dht22s.

Then I would like to be able to control 8 x relays and possibly put them on timers if needed.

I have spent months and ended up with that but I am really ready to sell this stuff.

I thought I could learn code but Im friggen lost.

I thought controlling 8 relasy with blynk would be easy.

I'd try something like this:

unsigned long Timer1 = 5000; //Timer for relais 1
pinMode(1, OUTPUT); //relais 1 on pin 1
int sensor1;

void setup() {
Serial.begin(9600);
}

void loop() {

if(millis() > Timer1)
{
if(digitalRead(1)) //if Pin 1 is HIGH
digitalWrite(1, 0);
else //If Pin 1 Low
digitalWrite(1,1)

sensor1 = analogRead(5) //read sensor from Analg pin 5

Timer1 = Timer1 + 5000; //Do this every 5 seconds
}
}

It activates/deactivates the first relais every 5 seconds and reads a sensor on Pin5 . Change 5000 to 300 000 for 5 minutes etc... For more relais you need to have

if(millis() > Timer2) .....

if(millis() > Timer3).... etc

Please use code tags when posting code.

So it looks like this.

That would just switch then on and off every . May or may not be useful.

For proper timing (so you can use wall clock time), add a real time clock.