Categories
Development

Blink LED with Blynk on ESP32

Let’s write code on ESP32

For this project you will need an ESP32 board, a way to program it and an application Blynk on your phone.

Initial code was just a regular Arduino code to see that I didn’t make a mistake. It is rather trivial with this project, but it is good to be consistent and really test the basic code, so you will know the code is working.

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  delay(1000);  
}

After checking the documentation on the Blynk page we need to install the Blynk library first.

And we also need to create a button in the Blink project on the phone.

Open the Blynk app and click on “New Project”. The project name will be “Blink” since we are blinking the LED on the ESP32 board. From the CHOOSE DEVICE list select ESP32 Dev Board and for connection type Wi-Fi. Theme is not important.

When you finish clik CREATE button and the Auth token is sent to the mail address you used to register.

Let’s add the button to the project from the list and click on it to modify it.

We will use the gp2 digital pin, since this is the pin to which blue LED is connected.

Don’t forget to select SWITCH mode of the button.

That’s it.

Let’s program the ESP32 with new code now.

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

char auth[] = "auth_code_sent_via_email";
char ssid[] = "ssid_of_your_wifi";
char pass[] = "password_for_your_wifi";

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

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

Upload the code to the ESP32 and run the project in Blynk app by clicking on Play button in right upper corner. It changes to STOP button.

Next to the STOP button will be a small icon of the board and if there is no connection the red circle with exclamation point will be shown.

No connection to the board

Check if the board is connected, that you have programmed it, that ssid and password are correct, that auth code is also correct.

After successful connection to the board you can test the code by pressing the button and checking the LED on the board.

Leave a Reply

Your email address will not be published. Required fields are marked *