BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Esp 32 analog pin

Hi i’m new at Blynk and i have some problem for me. Sorry if this already asked before, I’m using esp32 with v1.0.0beta3 library and android 11 with arduino droid , i want to set my analog pins to blynk. But in the blynk app there’s no analog pins when i add button. It’s different from the youtube video i watched beacuse i think they used the old blynk app. Should i use some code or something for setting the analog pin ? I wanted to use the GP13 and GP12 pin

Here’s my code

//Xx --  
#define BLYNK_TEMPLATE_ID "TMPLxxx"
#define BLYNK_DEVICE_NAME "xxx"

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// kode yang dikirim aplikasi blynk ke email kalian.
// masukan kode yang sudah kalian copy di bawah.
char auth[] = "xxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "realxxx; ///NAMA WIFI ATAU HOTSPOT KALIAN
char pass[] = "tvjaqxxx"; ///KATA SANDI WIFI ATAU HOTSPOT KALIAN
void setup()
{
  // Debug console
  Serial.begin(9600);

 //Blynk.begin(auth, ssid, pass);
 Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
 WiFi.begin(ssid,pass);
 Blynk.config(auth);
}

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

I’d suggest using virtual pins instead
https://docs.blynk.io/en/getting-started/using-virtual-pins-to-control-physical-devices#how-do-virtual-pins-relate-to-the-gpio-pins-on-my-hardware

So i need to add a new code ? , Can you tell me where should i put the code in my current code and some example ? I’m sorry i’m really new in these

What are you trying to achieve exactly ?

I wanted to make a lamp that could be controlled by a phone, but i’m too confused by the tutorial’s app and the new app now. I’ve seen many of virtual pins code for esp32 but didn’t get it

Would you like to control the brightness, or just on/off ?

Just on and off

Add this to your sketch

void setup()
{
  pinMode(23, OUTPUT); // Initialise digital pin 2 as an output pin
}

BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
  if(param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    digitalWrite(23,HIGH);  // Set digital pin 2 HIGH
  {
  else
  {
    // execute this code if the switch widget is now OFF
    digitalWrite(23,LOW);  // Set digital pin 2 LOW    
  }
} 


This is my setting in the button , is it ok ? And at the pinmode “23” should i change it to my needed pin ? Because i wanted to use GPIO13.

Yes.

you can change it, no problem.

Sorry if asking more , i’m confused with the pinmode after seeing about more explanation of the GPIO. The pin i wanted to use is D13 written on the board but the explanation saya it’s not it

" If you’re working with an Arduino then it’s all quite simple. General Purpose Input/Output (GPIO) pin 2 is labeled “2” or “D2”. However, if you’re using a NodeMCU type of device then the manufacturers decided to make things a little more complicated. The numbers screen printed onto the board are not the GPIO numbers. You have to translate these NodeMCU “D” numbers onto actual GPIOs as follows…

Label GPIO

  • D1 5 *
    D2 4
  • D3 0*
  • D4 2*
  • D5 14*
    *D6 12 *
    D7 13
    D8 15

So which one should i put , sorry this become more complicated :pensive:

The list of pin you provide is for ESP8266.
Usually, ESP32’s pins are labeled in GPIO not Dxx

But it says Esp- WROOM - 32 at it

Nodemcu is an ESP8266

I’d start by updating your Blynk library to the latest version, which is currently 1.1.0

Yes, that’s an ESP32 board. The D13 written on the board means GPIO13

It’s the ESP8266 NodeMCU boards that have confusing pin numbering, but you aren’t using that board.

Pete.
Pete.

Ahh i see

Ohh , then should i just change the pinnumber same as the number that written on the board ? Like i wanted to use D13 means the pinmode ( 13, output); like that ?

Yes, but it’s:

pinMode(13, OUTPUT);

The commands in C++ are case-sensitive.

Pete.

I put the code and it says error: a function-definition is not allowed here before ‘{’ token…

//Xx--  
#define BLYNK_TEMPLATE_ID "TMPLxx"
#define BLYNK_DEVICE_NAME "xx"

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// kode yang dikirim aplikasi blynk ke email kalian.
// masukan kode yang sudah kalian copy di bawah.
char auth[] = "ysMxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "realxx"; ///NAMA WIFI ATAU HOTSPOT KALIAN
char pass[] = "tvjxxx"; ///KATA SANDI WIFI ATAU HOTSPOT KALIAN
void setup()
{
  // Debug console
  Serial.begin(9600);

 //Blynk.begin(auth, ssid, pass);
 Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
 WiFi.begin(ssid,pass);
 Blynk.config(auth);
    
    {
pinMode(13, OUTPUT); // Initialise digital pin 2 as an output pin 
        } 
BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes 
    { 
    if(param.asInt() == 1) 
    { 
            // execute this code if the switch widget is now ON
         digitalWrite(13,HIGH); // Set digital pin 2 HIGH 
        { 
          else
             { 
                // execute this code if the switch widget is now OFF
                 digitalWrite(13,LOW); // Set digital pin 2 LOW } } 
}

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

You have to delete {

1 Like