Read this before creating new topic:
Search forum for similar topics
Check https://docs.blynk.io
Add details :
• Hardware model + communication type. For example: ESP32
• Smartphone OS (iOS or Android) + OS version
• Blynk server region
• Blynk Library version
• Post your FORMATTED sketch code. Remove your AUTH TOKEN from code. Don’t post screenshots
• Post your serial monitor output when experiencing some issues
If you don’t format your code, your topic can be deleted by moderators.
Here is a correct example of code formatting:
//#define BLYNK_TEMPLATE_ID "xxxxxxx"
#define BLYNK_TEMPLATE_NAME "IoT Spice Dispenser "
#define BLYNK_AUTH_TOKEN "xxxxxxxxx"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Stepper.h>
#include <HX711.h>
// Blynk
char auth[] = "xxxxxx";
char ssid[] = "xxxxxxx";
char pass[] = "xxxxxxxxxx";
// OLED setup
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Stepper motor setup
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 14, 27, 26, 25);
// Load Cell (HX711)
#define DT 12
#define SCK 13
HX711 scale;
float weight = 0;
// Control variables
int selectedSpice = 0;
int quantity = 1;
bool isDispensing = false;
bool systemEnabled = true;
const char* spices[] = {"Turmeric", "Cumin", "Pepper"};
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
Serial.print("Connecting to Wi-Fi");
int attempts = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
attempts++;
if (attempts > 30) {
Serial.println("\nFailed to connect to Wi-Fi");
display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("WiFi failed!");
display.display();
return; // exit setup or retry logic
}
}
Serial.println("\nWi-Fi connected");
Serial.println(WiFi.localIP());
display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("WiFi Connected");
display.print("IP: ");
display.println(WiFi.localIP());
display.display();
Blynk.config(auth);
Blynk.connect();
myStepper.setSpeed(10); // RPM
// Load cell setup
scale.begin(DT, SCK);
scale.set_scale(420.0); // Set your calibration factor here
scale.tare(); // Reset the scale to 0
updateDisplay();
}
void loop() {
Blynk.run();
weight = scale.get_units(5);
updateDisplay();
}
BLYNK_WRITE(V0) {
selectedSpice = param.asInt();
updateDisplay();
}
BLYNK_WRITE(V1) {
quantity = param.asInt();
updateDisplay();
}
BLYNK_WRITE(V2) {
if (param.asInt() == 1) {
dispense();
}
}
BLYNK_WRITE(V4) {
systemEnabled = param.asInt();
Blynk.virtualWrite(V3, systemEnabled ? "System ON" : "System OFF");
updateDisplay();
}
void dispense() {
if (!systemEnabled) {
Blynk.virtualWrite(V3, "System OFF");
return;
}
isDispensing = true;
Blynk.virtualWrite(V3, "Dispensing...");
updateDisplay();
for (int i = 0; i < quantity; i++) {
myStepper.step(stepsPerRevolution);
delay(1000);
}
isDispensing = false;
Blynk.virtualWrite(V3, "Done");
updateDisplay();
}
void updateDisplay() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("Spice: ");
display.println(spices[selectedSpice]);
display.print("Qty: ");
display.println(quantity);
display.print("System: ");
display.println(systemEnabled ? "ON" : "OFF");
display.print("Status: ");
display.println(isDispensing ? "Dispensing" : "Idle");
display.print("Weight: ");
display.print(weight, 1);
display.println(" g");
display.display();
}
This is my final year project and i have a presentation in 2 days, can someone help me please?
my serial monitor prints this:
��J��(��)!���� �m Ձ��,���Hʈ��H�HHaJ)! C!1
�1�H�!!PL!#�!a�J!H@!�!J)jV!�����h3Pr�Υ1�9��z����C9��
That’s usually caused by having your serial monitor set to the wrong baud rate. As you’ve specified that you want your ESP32 to send serial data at 115200 you neeed to set your serial monitor to the same baud rate.
PeterNjogu:
Serial.begin(115200);
Your sketch has some issues though.
You shouldn’t be doing this in your void loop when using Blynk…
And it’s bad practice to use aliases that are keywords…
because it leads to nonsense like this…
PeterNjogu:
display.display();
Pete.