Good afternoon,
I am new to coding and Blynk but have muddled my way to this point. I have managed to set up the web dashboard and mobile app.
I am using an Arduino Uno and ESP-01 and have managed to get the BLYNK logo but then get an error with 1532 ESP not responding. I don’t know if this is code or hardware now at this point. I have spent days trying to figure it. ESP is running SDK version:0.9.5 should I try update it ?
Arduino Uno R3 on IOS
We need to see your sketch, and exactly how you’ve wired-up your hardware.
You might find this helpful…
Pete.
Thanks Pete was just reading through that as seen on another post. Great work putting it together. Below is my sketch but bear in mind I’m new to all this. I had TX connected to TX and RX connected to RX so reading through the article this is wrong. I am working through it
#include <util/delay.h>
// Include Adafruit Graphics & OLED libraries
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Include Wire Library for I2C
#include <Wire.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define pumptime 2500 //Pump on time
#define delay_ms 3000 //Adjustable delay
//BLYNK-
#define BLYNK_TEMPLATE_ID "TMPL6Pv17xQ0"//
#define BLYNK_TEMPLATE_NAME "Greenhouse"//project name
#define BLYNK_AUTH_TOKEN "5j3T5Wy-3sapGdJpzz3F-T3AfyN-IKEN"
#define BLYNK_PRINT Serial
//Blynk Libraries
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// Your WiFi details.
// Set password to "" for open networks.
char ssid[] = "Fridgefi";
char pass[] = "arsenaL2005*";
// For arduino Uno
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
Adafruit_SSD1306 display(OLED_RESET);
// DHT parameters
#include <DHT.h>
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int FAN = 10; //enable Fan on pin 10
int BULB = 9; //enable Bulb on pin 9
int PUMP = 8; //enable pump on pump 8
int RedLED1 = 7; //Red LED for water level
int GreenLED1 = 4; //Green LED for water level
int SoilMoisture = A1; //Soil Moisture Sensor
int WaterLevel = A2;// WaterLevel Sensor
void setup() {
// Debug console
Serial.begin(115200);// for Blynk app
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass, "blynk.cloud", 80); //BLYNK app
Serial.begin(9600); //Open Serial Port for waterlevel and soil moisture
Wire.begin(); // Start Wire library for I2C
// initialize OLED with I2C addr 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
//Initial Values
int SoilMoisture =0;
int WaterLevel = 0;
//Enable pinMode
//OUTPUTS//
pinMode(FAN, OUTPUT); //enable pin 10 as output
pinMode(BULB, OUTPUT); //enable pin 9 as output
pinMode(PUMP, OUTPUT); //enable pin 8 as output
pinMode(RedLED1,OUTPUT);
pinMode(GreenLED1,OUTPUT);
//INPUTS//
pinMode(SoilMoisture, INPUT); //enable pin A1 as input
pinMode(WaterLevel, INPUT);//enable pin A2 as input
// Initialize Temp & Humidity Sensor
dht.begin();
}
void loop() {
display.display();
getTemp ();
Blynk.run();
SoilMoisture = analogRead (SoilMoisture);//read value of soil moisture
WaterLevel = analogRead (WaterLevel); //read value of waterlevel
/*Serial.print("WaterLevel: ");
Serial.println(WaterLevel);
Serial.print("SoilMoisture: ");
Serial.println(SoilMoisture);*/
if (SoilMoisture>520 && WaterLevel > 500){
digitalWrite (GreenLED1,HIGH);
digitalWrite (PUMP,HIGH);
delay (pumptime);
digitalWrite (PUMP,LOW);
}
else if (WaterLevel < 500){
digitalWrite (RedLED1,HIGH);
//Serial.print("WaterLevel Too Low");
//Serial.print("\n");
delay (delay_ms);
digitalWrite (PUMP,LOW);
}
}
void getTemp(){
// Read DHT11- Inside Greenhouse
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if reads fails
if (isnan(temperature) || isnan(humidity)) {// if not a number on temp or humidity return the error below
//Serial.println(F("Failed to read from DHT sensor"));
digitalWrite (RedLED1,HIGH);
return;
}
//Oled DIsplay
//Set the color - always use white despite actual display color
display.setTextColor(WHITE);
//Set the font size
display.setTextSize(1);
//Set the cursor coordinates
display.setCursor(0,0); //set cursor to home
display.print("SoilMoisture");
display.setCursor(0,10); //Move to next line
display.print("Humidity:"); //Write Humidity
display.print(humidity);//Take in value
display.print(" %");
display.setCursor(0,20); //Move to next line
display.print("Temperature: ");
display.print(temperature);
display.print(" C");
// Check the temperature is below 20C or exceeds 26C and reacts accordingly
if (temperature > 27.0) {
digitalWrite(FAN, HIGH);//Turn on the fan
delay(delay_ms);
digitalWrite(BULB, LOW);
delay(delay_ms);
//Serial.println("Temperature exceeded target, turning on fan.");
} else if(temperature < 25.0) {
digitalWrite(FAN, LOW);//Turn off the fan
delay(delay_ms);
digitalWrite(BULB, HIGH);//Turn on the bulb
delay(delay_ms);
}
// Wait a few seconds between measurements.
delay(5000);
}```
please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly. Triple backticks look like this: ```
Done
Seem to have got it connected by updating the FW on the ESP. Now to reduce this code so I can test.
Also based off the fact I am using an Arduino Uno I need to set the Baud rate to 9600 according to the article.
Your code breaks so many of the Blynk rules that I doubt it will work well.
You should read this…
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean
Pete.
OK thanks
I wrote the code before thinking to add Blynk. I will have to revisit it now but I am running out of time.
I will read that.
Thank you
Sorry to ask another Question. I changed the baud rate using AT+UART_DEF=9600,8,1,0,0
but tit then reverted back to 115200 it seems.
I used the above command and changed Baud in code to 9600 to match.
When I then connected to arduino it would not connect unless it was set to 115200. Is there a way to permanently set the baud to 9600?