Arduino connected to esp-01 and send data to sql

Hi, i'm new using esp-01, i already worked in esp8266, but this time i'm struggling with this problem, so i have a arduino mega connected to esp-01, how i suppose to send data to sql(phpmyadmin) from arduino board?

"(use port 1 and 0) not tx1,2,3...."

i can't program esp-01 board like esp8266, anyone have a code or something i can look into?

if you have a MEGA you should use Serial1, Serial2 or Serial3 to connect to the ESP01 and keep Serial free for debugging and code upload.

The ESP01 pins are 3.3V only. If you connect the MEGA-Tx to ESP-Rx, you'll be sending 5V and risk damaging your ESP.

i can't program esp-01 board like esp8266, anyone have a code or something i can look into?

what do you mean by that? do you want to use AT commands?

i have resistor of course,

in esp8266 i can plug it by usb and program it, with esp-01 e don't have usb port, so i think i need to do all in arduino mega

the question was about how you want to program the ESP.

if you want to use the IDE to directly program the ESP using C++, then the easiest way is to use an USB to Serial Adapter. there are tons of tutorials for this, here is one example (first google hit)

if you want to use AT commands, then look for the AT command guide and send those commands over the serial line

here is what i want to do:

i have arduino mega connected to a RFID reader when detects the rfid card it will move the servo motor, (this part is working)

the problem is, i want to send data to a database when this event occurs, but to do that. i need connecting the arduino to esp-01, but i don't know how to code esp-01 using arduino mega board.

i' been google for a while.

read this tutorial to send AT commands

AT Commands don't work...

An ESP-01 is an ESP8266, but no it doesn't have a USB port, you can program it directly though using either a programmer or by using the USB port of an Arduino.
Check this tutorial

You will need more than 1 resistor. You need a voltage divider.

It does not mean much… is it wired the right way, what have you tried, is the firmware the AT command firmware etc…

This project goes through programming the ESP-01
Here a two sample sketches. For debugging the ESP-01 after you have programmed it connect the TTL-USB RX line to GPIO2
HardwareSerial1CSVToESP8266.ino (2.0 KB)
ESP8266_01_CSV.ino (2.2 KB)

Here is a connection circuit. The 3v3 regulator on the Mega2560 is only rated for 150mA, but can supply 300mA into a short circuit. The ESP-01 can draw 170mA on TX so the 100uF Low ESR is there to supply the peak current
Edit -- The 100uF does not seem to do much according to the scope. I am seeing 0.6V dips about 0.5mS wide, but the ESP still 'works' but clearly a real supply would be better.
See this project for an example of a 'real' supply for the ESP or use a Adafruit ESP8266 breakout board

yes i have resistor dividir*

that is nice but i don't have FT232RL FTDI USB or , CP2102 USB, that's why i asked if there is any other away

There is of course. You can use the Arduino as a programmer. With a Mega that has a few hwSerial one could even upload using Serial-passthrough, but the easiest is just to

  • load a blank sketch (or blink) onto the Arduino.
  • connect the ESP's RX to the Arduino RX (which is the USB's chip TX) (via divider of course)
  • connect the ESP's TX to the Arduino TX
  • Pull the ESP's GPIO 0 'LOW' and reset the unit to put it in flash mode.
  • Now once you have installed the ESP-core in the IDE you can upload a sketch of your choosing.

As a test you could upload a simple 'blink' , keep in mind that the builtin led on an ESP-01 is on GPIO 1 (TX-pin as well) and is active 'LOW'

This is a decent tutorial, only the bit about the Arduino not being able to provide enough 3.3v current is not really correct. An Uno and a Mega and probably also a DUE can easily provide the 300mA peak current that the ESP needs at times.

going try that, thanks, do you think i can find some code to send one variable to mysql?

Of course, remember, google is your friend.

best friend money (and personal data) can buy !

at commands now work at least

1 Like

i try connect esp-01 with my wamp, but gives this error
...trying... 0 retrying...
...trying... 0 retrying...
...trying... 0 retrying...
Connection failed.
Recording data.
ERROR: Class requires connected server.

my code:

#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(172,19,0,89);  // IP of the MySQL *server* here
char user[] = "root";              // MySQL user login username
char password[] = "";        // MySQL user login password

// Sample query
char INSERT_SQL[] = "INSERT INTO cardbd.teste (inteiro) VALUES (17)";

EthernetClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
  while (!Serial); // wait for serial port to connect
  if (conn.connect(server_addr, 3306, user, password)) {
    Serial.println("Connection failed.");

void loop() {

  Serial.println("Recording data.");

  // Initiate the query class instance
  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  // Execute the query
  // Note: since there are no results, we do not need to read any data
  // Deleting the cursor also frees up memory used
  delete cur_mem;

DBname: cardbd
table: teste
structure of the table: inteiro (type int)

Should be within </> code-tags

1 Like

ty, dind't find the code button