I am a total beginner with Arduino, Blynk and even coding, so I hope that you could help me out here.
I am using an Arduino Uno, an ESP8266-01 Wi-Fi module, and a 315 MHz transmitter module. We have a set of lights at home that can be controlled by a 315 MHz remote with four buttons (which I call “lock”, “square”, “up” and “down” in the following code). I want to use the Blynk app to control them instead.
The problem is that I do not know how to do it. I can connect the Arduino with the Wi-Fi shield to my router, and control a simple LED with the app. And I can connect the Arduino with the 315 MHz transmitter to send out constant codes to the lights I want to control, but I can not figure out how to use them together.
This is the code I use to connect the Arduino to my router:
Does anyone know or can help me write a code to combine these two? So that for example, when I push a button for digital pin 9 in the app, the transmitter sends a 315 MHz code, and when I push a button for digital pin 10, it sends a different 315 MHz code?
What you need is called “Virtual Pins” in Blynk. If you look for that in the examples, I bet you will figure this thing out. It’s not that hard. A Virtual Pin can send a custom (or more then one) command to your hardware. I’ll give you a short example:
Thank you very much! But then I wonder, how do I connect the transmitter? Since I have to connect something to the DATA pin on the transmitter, which pin on the Arduino should I connect it to and how to I get it to use for example V02 to be pin D10 on the Arduino?
The numbers are the pin numbers to which they are attached, right? You need to integrate all needed parts. The virtual pin and the pin for the transmitter don’t have a relationship.
Blynk handles the vPin and the RCSwitch library handles the RCSwitch parts.
It seems the structure of your sketch is a bit outdated, it would be better if you use last Blynk library.
On the other hand…EspSerial.begin(115200)?? The Baudrate is really high…try to reduce it to 9600.
I know, but I was not able to connect to wi-fi with the later versions of the library. And as said, I am really a beginner at this, I do not even know what the baudrate does? I know that it has something to do with the monitor but not what difference it makes?
The baudrate specifies how fast data is sent over the serial line to the ESP (in this case)
Both items (ESP and Arduino) MUST operate at the same rate (obviously)
There’re lots of posts where you will be able to find more info to change the Baudrate of your ESP. If not, let me know and I will provide some tips.
What you are doing here is not going to work. You have to use another means of communicating with your ESP because the Arduino has only one serial port. You can either use that for debugging or for communicating with your ESP.
Now, there are a couple of options to work around that:
buy an Arduino Mega, this thing has more Serial ports
Attach the ESP to SoftSerial port on Arduino, not recommended
3 Do the debugging via SoftSerial, I’d choose this option
In both cases 2 and 3 you have to make use of the SoftSerial library. At the moment I got some other things to do, but I will provide you with a basic sketch of how to accomplish this later
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // tx / rx
#define BLYNK_PRINT mySerial // Comment this out to disable prints and save space
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
void setup()
{
// Set console baud rate
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, "ssid", "pass");
}
void loop()
{
Blynk.run()
}
I think this should be it, but I get an error compiling, missing ESP8266_Lib.h … when I comment the include out in the BlynkSimpleShieldEsp8266.h it compiles fine though.
nevermind that last bit, I just had an outdated library This code should do the trick and have you output serial debugging to pins 10/11 as being tx/rx.
As said, I am a total beginner. I do not really understand where to fit in the 315MHz codes in this. And also, how I should connect the transmitter now. Before, when I was not supposed to use Blynk and WiFi, I connected D5, D6, D10 and D11 to the data pin on the transmitter. (As seen in the second embedded code in my first post). Which pin/pins do I connect now to the data pin? How do I write the code for them? And how do I put in Vpins as well, so that I can get four buttons in Blynk, and each of them is supposed to send out a specific 315MHz code when pressed?
Uno R3, and yes I have! I got it to upload now, but when I look in the serial monitor it does not seem to connect to my wifi, it only says something about “blynk.cloud…”.