Linking UNO and ESP8266

I have no idea about the connection of hardware between Uno and MCU. Could you explain further for this?
This is mean for connection of pin 7 and 8 in Uno need to connect to MCU?
How are they going to connect in order to receive the data?

The UNO and the ESP are connected together via Serial… SoftwareSerial on the UNO and the hardware serial pins on the ESP8266.

If I recall, Pin 7 on the UNO is RX, so needs to connect to the TX pin on the ESP and the ESP RX pin to pin 8 TX on the UNO.

Something to note though, is that you should use a voltage level shifter module between them as the UNO sends out 5v on i’ts TX pin… but the ESP only wants to see 3.3v on it’s RX pin.

If i want to use the pin 0(RX) and 1(TX) of Uno connect to the ESP TX and RX pin, will it work?
yesterday i asked about the coding at other section. i intend to change the board mcu to uno as microcontroller while mcu used as the board to send signal to uno.
I worked out to the new coding by refer to this project.
this is the code of mcu to send data. could you please help to have a check on it?

#include <BlynkSimpleEsp8266.h>  // For Blynk
#include <ESP8266WiFi.h>  // For Blynk & OTA
#include <EasyTransfer.h>  // For EasyTransfer

EasyTransfer ET;

// Put your variable definitions here for the data you want to send
// THIS MUST BE EXACTLY THE SAME ON THE ARDUINO
struct SEND_DATA_STRUCTURE {
  int16_t Button;

};

SEND_DATA_STRUCTURE ETdata;

char auth[] = "ea704949cb72465e951fcde8d332ea3f";
char ssid[] = "Nayana";
char pass[] = "959608021210";
char server[] = "blynk-cloud.com";  // URL for Blynk Cloud Server
int port = 8080;

BlynkTimer timer;

void setup() {
  Serial.begin(9600);
  ET.begin(details(ETdata), &Serial);

  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);
  Blynk.connect();

  timer.setInterval(1000L, UpTime);

}  // END Setup Loop

void UpTime() {  
  Blynk.virtualWrite(V0, millis() / 1000);  // Display Widget - Uptime in seconds
}

BLYNK_WRITE(V1) {  // Button Widget - control power of robot
  ETdata.Button = param.asInt();  // button on and off
  ET.sendData();
}

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

}  // END Void loop

while this is the side of uno to receive data from mcu

#include <SoftEasyTransfer.h>  // For EasyTransfer
#include <Servo.h>
#define TURN_TIME 175

#include <SoftwareSerial.h>  // For Software Serial
SoftwareSerial ETSerial(0,1);  // Pins used for Soft Serial on UNO

SoftEasyTransfer ET;

// Put your variable definitions here for the data you want to receive
// THIS MUST BE EXACTLY THE SAME ON THE ESP
struct RECEIVE_DATA_STRUCTURE {
  int16_t Button;
};

int trigPin1 = 2;//right sensor
int echoPin1 = 3;
int trigPin2 = 4;//front sensor
int echoPin2 = 5;
int trigPin3 = 6;//left sensor
int echoPin3 = 7;
int distance, cmRight, cmCenter, cmLeft;
long duration; //prevent duration become negative
Servo servo1;//left wheel,9
Servo servo2; //right wheel,10
int i=0;//obstacle counting
int j=0;//modulo i

RECEIVE_DATA_STRUCTURE ETdata;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
  servo1.attach(9);
  servo1.writeMicroseconds(1500);
  servo2.attach(12);
  servo2.writeMicroseconds(1500);
  ETSerial.begin(9600);
  ET.begin(details(ETdata), &ETSerial);
  
}
void equalone(){
   servo1.write(180); //backward
   servo2.write(0);
   delay(500);
   servo1.write(180); //turn left
   servo2.write(180);
   delay(1650);
   servo1.write(0); //forward
   servo2.write(80);
   delay(800);
   servo1.write(180); //turn left
   servo2.write(180);
   delay(1350);
   servo1.write(0); //forward
   servo2.write(80);
   delay(500);
}

void equalzero(){
   servo1.write(180); //backward
   servo2.write(0);
   delay(500);
   servo1.write(-180); //turn right
   servo2.write(-180);
   delay(1250);
   servo1.write(0); //forward
   servo2.write(80);
   delay(800);
   servo1.write(-180); //turn right
   servo2.write(-180);
   delay(1500);
   servo1.write(0); //forward
   servo2.write(80);
   delay(500);
}

void obstacle(){
  servo1.write(180); //backward
  servo2.write(0);
  delay(800);
  servo1.write(180); //u-turn
  servo2.write(180);
  delay(2500);
}

void forward(){
  servo1.write(0);
  servo2.write(85);
  delay(500); //delete this
} //robot move forward function

void backward(){
  servo1.write(180);
  servo2.write(0);
  delay(1000);
} //robot move backward function

void loop() {
  ET.receiveData();

  while (ETdata.Button == 1) {  
  digitalWrite(trigPin1,HIGH); //right sensor
  delayMicroseconds(10000); //sense speed
  digitalWrite(trigPin1,LOW);

  duration = pulseIn(echoPin1, HIGH);
  cmRight = (duration/2)/29.1;
  
  digitalWrite(trigPin2,HIGH); //front sensor
  delayMicroseconds(10000); //delay the sense speed
  digitalWrite(trigPin2,LOW);

  duration = pulseIn(echoPin2, HIGH);
  cmCenter = (duration/2)/29.1;

  digitalWrite(trigPin3,HIGH); //left sensor
  delayMicroseconds(10000); //sense speed
  digitalWrite(trigPin3,LOW);
}
  duration = pulseIn(echoPin3, HIGH);
  cmLeft = (duration/2)/29.1;
  if(cmLeft >5 && cmRight <=5 && cmCenter <=5)
      {
        equalone(); // turn left
        Serial.println("wall on right, Turn Left");
      }
  
    else if(cmRight >5 && cmLeft <=5 && cmCenter <=5)
      {
        equalzero(); //turn right
        Serial.println("wall on left, Turn Right");
      }
  
    else if(cmRight <=5 && cmLeft <=5 && cmCenter<=5)
      {
        obstacle();
        i++;
        j = i%2;
        Serial.println("Make a U-Turn");
        Serial.print("i = ");
        Serial.println(i);
        Serial.print("j = ");
        Serial.println(j); 
      }
    else
    {
      Serial.println("Keep moving");
      forward();
  }
}

It has no compile error. But I am not certain about this.

I wouldn’t recommend it… not if you want to use any print statements or quickly upload any sketches without disconnecting from the ESP first. A serial connection can only be used on one thing at a time.

FYI, I moved this all into a dedicated topic for clarity.

Please use this topic for further discussion on this issue.

1 Like

Can i just output the 3.3V from uno to mcu instead of using the voltage level shifter?

No :rofl: it is a Serial signal with a range of somewhere between 0-5v that comes out of the digital TX pin on the UNO and is received by the RX pin on the ESP.

Going the other way… The lower 3.3v TX from the ESP doesn’t bother the UNO’s RX any… but there is also the possibility that because it is just barely above the differentiating voltage the determines HIGH and LOW, that it may not be clear enough. But I have found that with 9600 BAUD it seems just fine.

You can try it without a level shifter, but there are two camps on the concept… one says the ESP will probably be OK, and the other says it will most likely fry the RX pin, if not the whole ESP… and sooner than later.

ok understood.

so the pin 0 and pin 1 can be used for digital pin for sensor? because lacking of digital pin

Technically, yes… but then you can’t use them for any Serial use, such as the Serial monitor, and you have to unplug the sensor before uploading code… same issue as described before.

If you need more pins, you can use the Arduino’s Analog pins as Digital pins as well…

thank you very much. i will try it out later :slight_smile:

One more is, the MCU can be used as esp8266 like a wifi shield for arduino?
if yes, how is the connection like?
because the MCU doesn’t have the pin CH_PD.
As i found this example https://circuitdigest.com/microcontroller-projects/arduino-wifi-controlled-robot
which blynk can control the movement by using arduino with esp. but now i have only nodemcu in my hand

What are you referring to as the MCU?.. we use that term for the actual Microcontroller Unit… AKA Arduino, ESP8266, ESP32, etc.

An Arduino of the typical type (UNO, MEGA, Nano, Micro, etc…) do not have any networking option built in, so they are generally linked with ESP-01 MCUs that have AT firmware flashed on them… effectively turning them into WiFi to Serial adapters (AKA WiFi Shields) and allowing the Arduinos connectivity to IoT stuff like Blynk

But if you have the ESP(8266)-01’s big brother the NodeMCU (AKA Standalone ESP8266), then you can use it directly (no need for another Arduino)… as in program it with the same Arduino code, on the same IDE and connect it to networks for IoT use using it’s built in WiFi.

PS the ESP-01 can also be used as an ESP standalone when flashed with Arduino code, but it has very limited memory and GPIO pins.

Blynk as two different ESP8266 Libraries for each arrangement…

Arduino with ESP Shield - http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware

ESP as standalone - http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-standalone

I am actually referring to NodeMCU 1.0 ESP-12E. I am sorry for not stating it clearly.
So I would like to know whether the NodeMCU can be function as Wifi Shield like ESP8266-01? As the NodeMCU ESP-12E provide limited pin for me. So I decided to use Arduino Uno as the microcontroller while NodeMCU as the Wifi Shield to help me connect to Blynk and send data between each other.

Well, that is kind of like towing your truck around with a sports car… just because you need the storage room in the truck box :stuck_out_tongue_winking_eye:

Anyhow, I actually don’t know if it can take the AT firmware needed to be used as a shield (probably, but NOT a common move - you would have to figure that one out), nor precisely how you would link it (but most likely via the usual TX/RX.

You could try acquiring an ESP32 if you need more true IoT and pin versatility.

Otherwise I would still just recommend running your NodeMCU it as a Standalone with Blynk sketch… and then linking it to an an Arduino, running basic code and reading your sensors or whatnot and communicating back and forth with the ESP, via serial or i2c, using EasyTransfer… as mentioned above.

yeah i understood it is like overkill the NodeMCU:sweat_smile:. But what i have now are only NodeMCU and arduino uno. And for now, i have no budget to buy other mcu :pensive:
As i knew that the esp8266 has a pin CH_PD which i don’t see in NodeMCU so I am not sure whether it would be a problem to communicate with arduino.

I have 3 ultrasonic sensor, 2 servo motor and 2 dc motor. Is it possible to use NodeMCU?

No idea if this matters on the NodeMCU… not a recommended method to use it as a shield anyhow.

Should be OK with the ultrasonics and the servos (5 needed pins - See the green ones)… but two DC motors require a dual H-Bridge and that alone tiplicaly needs 4-6 data pins and you will not have enough left over without much more advanced pin management and possibly fancy coding.

Lolin%20NodeMCU

Anyhow, I have already given sufficient and preferencial suggestions for you needs… all you can do now is try them or Google for other alternatives.

Hi Boonniie!
I am also stuck at the very same problem and can’t find a solution to it as of now. In case you find it do let me know please.

Thanks

@sarthakvarshney If you need to please create your own topic with full details of your issue (not “very same problem:stuck_out_tongue_winking_eye: ) instead of tacking a “me too” into other’s topics. Thank you.