Esp8266-01 Arduino Uno. Status to Firebase - firebase

I am having problems connecting my Esp8266-01 to my Arduino Uno. I want to be able to connect it so that it can send the below code for a microswitch to Firebase (+LLC). I am not getting any response from AT commands in the serial monitor and have tried both NL & CR as well as changing from 9600 to 115200 baud rate. My esp only displays a red led and not the blue one.
int pressSwitch = 0;
void setup()
// put your setup code here, to run once:
{
Serial.begin(9600);
}
void loop()
// put your main code here, to run repeatedly:
{
pinMode(LEVER_SWITCH_PIN,INPUT);
pressSwitch = digitalRead(LEVER_SWITCH_PIN);
if(pressSwitch == HIGH)
{
Serial.println("CLOSED");
delay(1000);
}
if(pressSwitch == LOW)
{
Serial.println("OPEN");
delay(1000);
}
}```

Related

Arduino ESP32-Wroom-32D to XBee Via BlueTooth

I have a few questions as to why my input isn't behaving correctly. I have 2 functioning scripts I've used:
ESP32 to Xbee using UART2, I open a serial connection to Xbee3 and type "+++" or AT Commands "ATID" and I am able to view to xbee's response via serial monitoring, works fine
Samsung Phone Serial App to ESP32 using Bluetooth, I'm also able to connect to the phone and type commands from phone to terminal and terminal to phone, works fine.
code for item 1:
//Arduino IDE
//ESP32 to Xbee UART2
//Select your modem:
#define TINY_GSM_MODEM_XBEE
// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
HardwareSerial SerialAT(2);
#define TINY_GSM_DEBUG SerialMon
void setup() {
// put your setup code here, to run once:
// Set console baud rate
SerialMon.begin(115200);
SerialAT.begin(9600);
delay(1000);
SerialAT.print("+++"); while (SerialAT.available()) {SerialMon.write(SerialAT.read());}
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
// Access AT commands from Serial Monitor
SerialMon.println(F("***********************************************************"));
SerialMon.println(F(" You can now send AT commands"));
SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
SerialMon.println(F("***********************************************************"));
while(true) {
if (SerialAT.available()) {
delay(1000);
SerialAT.println("ATID");
SerialMon.write(SerialAT.read());
}
if (SerialMon.available()) {
SerialAT.write(SerialMon.read());
}
delay(0);
}
}
Code for item 2:
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
#define TINY_GSM_MODEM_XBEE
#define SerialMon Serial
HardwareSerial SerialAT(2);
#define TINY_GSM_DEBUG SerialMon
void setup() {
SerialMon.begin(115200);
SerialAT.begin(9600);
SerialBT.begin("ESP32testBLMfalse"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
// Access AT commands from Serial Monitor
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(1000);
}
My issue was when I tried to combine these. See, I wanted to know if it was possible to open a Bluetooth connection with the ESP32 and send the AT commands from the phone app to the XBEE connected to it on UART2. This is what I'm currently doing. The command looks like it sends fine, but my serial output on reads:
"
The device started, now you can pair it with bluetooth!
10:44:04.546-> OK????????????????????????????????????????????????????????????????????????????????????
"
not sure if it's due to the bit rate, let me know if anyone can assist.
Thank you
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
#define TINY_GSM_MODEM_XBEE
#define SerialMon Serial
HardwareSerial SerialAT(2);
#define TINY_GSM_DEBUG SerialMon
void setup() {
SerialMon.begin(115200);
SerialAT.begin(9600);
SerialBT.begin("ESP32testBLMfalse"); //Bluetooth device name
delay(1000);
SerialAT.print("+++"); while (SerialAT.available()) {SerialMon.write(SerialAT.read());}
delay(1000);
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
// Access AT commands from Serial Monitor
if (SerialBT.available()) {
delay(1000);
Serial.write(SerialAT.read()); //send phone input to xbee
}
if (SerialMon.available()) {
SerialAT.write(SerialBT.read()); //send xbee output to phone
SerialAT.write(SerialMon.read()); //send xbee output to serial monitor
}
delay(1000);
}
I was expecting
Samsung phone [input] --BlueTooth--> ESP32 --UART2-> Xbee
Xbee [output] --UART2--> ESP32 serial monitor --BLueTooth-->Samsung phone

Sending data from Arduino UNO to NodeMCU over UART and processing received data on NodeMCU

I'm trying to send data from Arduino UNO to NodeMCU via UART.
What I want to do is that when Arduino UNO sends "on" String to the NodeMCU, NodeMCU lights up its builtin LED, when "off" - it turns off.
I send data from Arduino UNO via standard Serial.println (). On the NodeMCU I use the SoftwareSerial library. I assigned rx and tx to pins D7 and D8 accordingly. Serial ports on Arduino(standard) and NodeMCU(SoftwareSerial) are set at 9600 baud rate.
Standard Serial port (USB) of NodeMCU is set to 115200.
I send the string that I receive from the Arduino to the standard serial port of the node (connected to usb)
The question is:
On the standard port of NodeMCU, which I view through the Arduino IDE, messages coming from the arduino are displayed, and displayed correctly (those that were sent), but the NodeMCU does not want to accept them in conditional statements and light up my LED. Why?
At the same time, when I remap the virtual UART to its original pins (connected to USB, GPIO3 and GPIO1, and send the same messages via usb through the COM port view in the Arduino IDE, the LED turns on and off as I programmed it.
Do you have any ideas why this is happening?
By the way, I do not lower voltage coming from Arduino RX and TX pins from 5V to 3.3V, but since messages are recived coorectly, I don't think that this is causing a problem.
Here's my code:
Arduino:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("on");
delay(1000);
Serial.println("off");
delay(1000);
}
NodeMCU:
#include <SoftwareSerial.h>
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
Serial.println(str);
if(str == "on"){
digitalWrite(D4, HIGH);
}
if(str=="off"){
digitalWrite(D4, LOW);
}
}
Screenshot of COM4:
Screenshot of COM4:
UPD: I tried using sending 1 or 0 as int value via Serial.write() and s.read() and it works, maybe the prolem is in String type somehow
You Use İt Maybe Work
#include <SoftwareSerial.h>
String text = "";
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
text = str
Serial.println(text);
if(text == "on"){
digitalWrite(D4, HIGH);
}
if(text =="off"){
digitalWrite(D4, LOW);
}
}

GSM SIM 900A Wont send a Message Using Arduino UNO

My Connections are
5VT to D9
5VR to D10
And external adaptor for power.. (5v 2A)
The blinks are good because it blinks every 3seconds,
The sim card is loaded.
But when I run the serial monitor, It only shows AT AT AT sometimes AT with reverse question marks..
Here is the Code I am using..
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+639176344625\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}
This is the Sim900A I am using together with Arduino Uno..
Check out this code for simple data sending using GSM.
#include <SoftwareSerial.h>
SoftwareSerial ph(9,10); // RX, TX of gsm
void setup() {
Serial.begin(9600);
ph.begin(9600);
sms(600);
}
void loop() {
// put your main code here, to run repeatedly:
}
void sms(float amount) {
ph.println("AT+CMGF=1");
delay(1000);
ph.println("AT+CMGS=\"123456789\"\r"); //Enter your number in place of 123456789
delay(1000);
ph.print("Amount: ");
ph.println(amount);
delay(100);
ph.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}

ESP8266 connected to my Arduino Uno

I have the ESP8266 connected to my Arduino Uno. With a blank sketch I can use Serial Monitor to connect it to my wifi network using these commands
AT+IPR=9600
AT+CWMODE=1
AT+CWJAP="SSID_HERE",""
It get's an ip and everything. But now I want my sketch to just do this using this code
#include <SoftwareSerial.h>
#define SSID "SSID_HERE"
void setup(){
Serial.begin(9600);
Serial.setTimeout(5000);
delay(1000);
}
boolean connectWiFi()
{
// connect
Serial.println("AT+CWMODE=1");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"");
delay(2000);
if(Serial.find("OK"))
{
Serial.println("AT+CIFSR");
Serial.flush();
delay(1000);
return true;
}
else
{
// Can not connect to the WiFi.
return false;
}
}
But it doesn't work.. The Serial.println shows up in the Serial Monitor, but the ESP8266 doesn't seem to respond. What am I missing?
AT -commands ends with carriage return, so you need to add '\r' to every command you print.
In your code lines looks like:
Serial.println("AT+CWMODE=1\r");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"\r");
Serial.println("AT+CIFSR\r");
Reference: https://en.wikibooks.org/wiki/Serial_Programming/Modems_and_AT_Commands/Special_Commands_and_Character_Sequences
The problem here is that you are trying to use pins 0 & 1 for the serial comms, well its part of the problem.. Because the arduino uses serial as well, it for me is only really good to use pins 0 & 1 for serial when i've grounded the reset pin on the arduino. This turns the arduino into a dummy device.
You can use something like software serial and two different pins instead, this way you will not interfere with the hardware serial of the arduino.
Also just to note, the below example will barely work.. For some it will for others it wont.. The problem here is that software serial does not really work / run at 115200..
You can change baud rate via AT+UART_DEF=19200,8,1,0,0 which will also disable flow control, then use software serial with a different speed mySerial.begin(19200)
Using Serial.println("TEXT") will send the line returns for you, so no need to add them unless you use Serial.print("TEXT\r\n")
DO NOT USE: AT+IPR= as this will brick it and require a reflash
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
pinMode(11, INPUT);
pinMode(10, OUTPUT);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("ARDUINO: Starting");
mySerial.begin(115200);
Serial.println("ARDUINO: Sending AT Command");
mySerial.println("AT");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

Arduino digitalWrite affected by Serial.begin

I used following code to write to digital pin with Serial.begin. Using Serial.begin affected my digital write. The correct timing will not happen.
#define led 0
void setup() {
// put your setup code here, to run once:
pinMode(led,OUTPUT);
Serial.begin (115200);
}
void loop() {
// put your main code here, to run repeatedly:
delay(500);
digitalWrite(led,LOW);
delay(500);
digitalWrite(led,HIGH);
}
I discovered that I cannot using digital pin 0 and 1 as input or output when using serial. Serial transmit(tx) and Receive (Rx) is on 1 and 0 respectively. It is shown in the Arduino Uno board. Solution was to use a different digital pin (2-13).

Resources