Hello , i'm new at arduino tbh and i have project to do
so i'm trying to make watering plants iot and using blynk too
when i didn't include pinmode at my code it works pretty well and it can connect the blynk
but when i trying to include pinmode, the serial monitor looping at the void setup, the output at serial monitor is weird and the blynk repeatedly connect and then disconnected.
this is my code from setup
void setup() {
Serial.begin(9600); // See the connection status in Serial Monitor
Serial.println(F("DHTxx test!"));
Blynk.begin(auth, ssid, pass);
dht.begin();
pinMode(PumpAir, OUTPUT);
//Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop() {
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer*/ // Blynk
}
void sendSensor(){
int soil_analog = analogRead(SoilSensor);
float soilSensorValue = map(soil_analog,1024,290,0,100);
float moisture_percentage = ( 100 - ( (soil_analog/1024.00) * 100 ) );
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, soilSensorValue); //V5 is for Soil Moisture
Blynk.virtualWrite(V6, t); //V6 is for Temperature
DateTimeNow();
Serial.print("Moisture Percentage = ");
Serial.print(moisture_percentage);
Serial.print("% Moisture Index = ");
Serial.print(soil_analog);
Serial.print(" \nMoisture Index with Maping = ");
Serial.print(soilSensorValue);
Serial.print("\n\n");
if (soilSensorValue < 70)
{
Serial.print("Harus disiram\n");
digitalWrite(PumpAir, HIGH);
}
else if (soilSensorValue > 80)
{
Serial.print("Terlalu basah\n");
digitalWrite(PumpAir, LOW);
}
Serial.print(F("\nHumidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print("\n\n");
}
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] =*AUTH* //Enter the Auth code which was send by Blink
char ssid[] = *SSID*//Enter your WIFI Name
char pass[] = *PASS* //Enter your WIFI Password
const int SoilSensor = A0;
#define DHTPIN 4 // Digital pin 4
#define DHTTYPE DHT11
const int PumpAir = 9;
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void setup() {
Serial.begin(9600); // See the connection status in Serial Monitor
Serial.println(F("DHTxx test!"));
Blynk.begin(auth, ssid, pass);
dht.begin();
pinMode(PumpAir, OUTPUT);
//Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop() {
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer*/ // Blynk
}
void sendSensor(){
int soil_analog = analogRead(SoilSensor);
float soilSensorValue = map(soil_analog,1024,290,0,100);
float moisture_percentage = ( 100 - ( (soil_analog/1024.00) * 100 ) );
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, soilSensorValue); //V5 is for Soil Moisture
Blynk.virtualWrite(V6, t); //V6 is for Temperature
Serial.print("Moisture Percentage = ");
Serial.print(moisture_percentage);
Serial.print("% Moisture Index = ");
Serial.print(soil_analog);
Serial.print(" \nMoisture Index with Maping = ");
Serial.print(soilSensorValue);
Serial.print("\n\n");
if (soilSensorValue < 70)
{
Serial.print("Harus disiram\n");
digitalWrite(PumpAir, HIGH);
}
else if (soilSensorValue > 80)
{
Serial.print("Terlalu basah\n");
digitalWrite(PumpAir, LOW);
}
Serial.print(F("\nHumidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print("\n\n");
}