BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Hydroponics code error

#1

Hi! It’s my first time to use Blynk and I’m having a hard time figuring out the problem with the code. My project is an Automatic Hydroponics Irrigation. When the HC-SR04 sensed a distance>=10, then the farmer will be notified thru blynk push notification and the pump will be turned on. I’m not that good in programming so I can’t figure out what’s wrong. I would really appreciate your help. Thank you in advance!

Arduino IDE says this error:

Arduino: 1.8.7 (Windows 8.1), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
YESFINAL:132:3: error: expected unqualified-id before 'void'
   ^
YESFINAL:132:3: error: expected constructor, destructor, or type conversion before 'void'
In file included from C:\Users\name\Documents\Arduino\libraries\Blynk-0.6.1\src/Blynk/BlynkApi.h:18:0,
                 from C:\Users\name\Documents\Arduino\libraries\Blynk-0.6.1\src/Blynk.h:14,
                 from C:\Users\name\Documents\COLLEGEfiles\IoT Projects\HYDROPONICS\YESFINAL\YESFINAL.ino:18:
C:\Users\name\Documents\Arduino\libraries\Blynk-0.6.1\src/Blynk/BlynkHandlers.h:152:5: error: expected unqualified-id before 'void'
     void BlynkWidgetWrite ## pin (BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &param)
     ^
C:\Users\name\Documents\Arduino\libraries\Blynk-0.6.1\src/Blynk/BlynkHandlers.h:160:31: note: in expansion of macro 'BLYNK_WRITE_2'
 #define BLYNK_WRITE(pin)      BLYNK_WRITE_2(pin)
                               ^
C:\Users\name\Documents\COLLEGEfiles\IoT Projects\HYDROPONICS\YESFINAL\YESFINAL.ino:110:1: note: in expansion of macro 'BLYNK_WRITE'
 BLYNK_WRITE(V7)
 ^
C:\Users\name\Documents\Arduino\libraries\Blynk-0.6.1\src/Blynk/BlynkHandlers.h:152:5: error: expected constructor, destructor, or type conversion before 'void'
     void BlynkWidgetWrite ## pin (BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &param)
     ^
C:\Users\name\Documents\Arduino\libraries\Blynk-0.6.1\src/Blynk/BlynkHandlers.h:160:31: note: in expansion of macro 'BLYNK_WRITE_2'
 #define BLYNK_WRITE(pin)      BLYNK_WRITE_2(pin)
                               ^
C:\Users\name\Documents\COLLEGEfiles\IoT Projects\HYDROPONICS\YESFINAL\YESFINAL.ino:110:1: note: in expansion of macro 'BLYNK_WRITE'
 BLYNK_WRITE(V7)
^
exit status 1
expected unqualified-id before 'void'

HERE IS THE CODE

//Define Pin Numbers
const int trigPin = 3;
const int echoPin = 5;
const int PumpPin = 6;  //relay --OUTPUT
const int PumpButton = 7;  //V7 IN BLYNK --INPUT
const int waterTankH =25.4;  //Water Tank Height in cm
const int waterTankL =75;  //Water Tank Length in cm
const int waterTankW =50;  //Water Tank Width in cm
//Define Variables
long duration;
int distance;
int volume;
 

#include <ESP8266WiFi.h>
#include <Blynk.h>
#include <BlynkSimpleEsp8266.h>

//WiFi Connection//
char auth [] ="   ";
char ssid [] ="   ";
char pass [] ="   ";

//TIMER//
BlynkTimer timer;



void MeasureCm()
{
  //clears the trigPin
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);

  //sets the trigPin on HIGH state for 10 microseconds
  digitalWrite (trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);

  //Calculating the distance and volume
  distance=duration*0.034/2;
  {
    if(distance>=10)
    {
      volume=((waterTankH*waterTankL*waterTankW)-(distance*waterTankL*waterTankW))/1000; //volume in Litres
    }
    else
    {
      if(distance<10)
      {
        volume=93;   //Volume when Tank is set to overflow --- not the exact volume
      }
    }
  }

  //SEND DATA TO BLYNK
  Blynk.virtualWrite(V2,distance); //virtual pin 2 in Blynk -- Level V
  Blynk.virtualWrite(V4,volume);   //virtual pin 4 in Blynk -- SuperChart
}


//PUSH NOTIFICATION
void notifyOndistance()
{
  if(distance>=10)
  {
    Blynk.notify("Water is low. Turn Pump On.");
  }
  else
  {
    if(distance==9)
    {
      Blynk.notify("Water is high. Turn Pump Off.");
    }
  }
}


void setup() 
{
  Serial.begin(9600);
  Blynk.begin(auth,ssid,pass);

  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  pinMode(PumpPin,OUTPUT);
  pinMode(PumpButton,INPUT_PULLUP); //V7 in Blynk -Button for pump water
  digitalWrite(PumpPin,LOW);


  timer.setInterval(5000,MeasureCm);

}

void loop() 
{
  timer.run();  //initiates SimpleTimer
  Blynk.run();  //initiates Blynk
}



**//PUMP REMOTE CONTROL//**

BLYNK_WRITE(V7)
{
  int i=param.asInt();
  if(i=1)
  {
    pumpStatus=!pumpStatus;
    aplyCmd();
  }
}

void aplyCmd()
{
  if(pumpStatus==1)
  {
    Blynk.notify("Hydroponics: Warning==>>Pump On");
    digitalWrite(PumpPin, HIGH);
  }
  else
  {
    digitalWrite(PumpPin,LOW);
  }
}

**//AUTOMATICALL CONTROL THE PLANTATION BASED ON SENSOR READING//**
void autoControlPlantation()
{
  if(distance>=10)
  {
    turnPumpOn();
  }
}

//TURN PUMP ON FOR A CERTAIN AMOUNT OF TIME
void turnPumpOn()
{
  TimePumpOn=180;
  pumpStatus=1;
  aplyCmd;
  delay(TimePumpOn*1000);
  pumpStatus=0;
  aplyCmd();
}

0 Likes

#2

Your problems are caused by these two lines:

**//PUMP REMOTE CONTROL//**

and

**//AUTOMATICALL CONTROL THE PLANTATION BASED ON SENSOR READING//**

the ** characters need to be after the double forward slash // characters, like this:

// ** PUMP REMOTE CONTROL **

You are also using the variables TimePumpOn and pumpStatus in this function without first declaring them:

//TURN PUMP ON FOR A CERTAIN AMOUNT OF TIME
void turnPumpOn()
{
  TimePumpOn=180;
  pumpStatus=1;
  aplyCmd;
  delay(TimePumpOn*1000);
  pumpStatus=0;
  aplyCmd();
}

If you want them to be global variables then you need to declare them at the top of your code.

Pete.

0 Likes

#3

Thank you!

1 Like