I’m currently working on a project for IOT and I’m using arduino uno and esp 8266.
This is my code
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = " f7960dd6b0184ec9a2880521a9bdd9fd";
char ssid[] = "Jonathan's iPhone";
char pass[] = "jojo1995";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8,9); // RX, TX
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
#define Motor_VIRTUAL V1
#define Light_VIRTUAL V3
const int motoron = 12;
const int motoroff = 13;
//const int motorspeed = 9;
const int led = 6;
int motor, LightSW ;
int motorstate=0;
void setup()
{
Serial.begin(115200);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pinMode(led,OUTPUT);
pinMode(motoron,OUTPUT);
pinMode(motoroff,OUTPUT);
//pinMode(motorspeed,OUTPUT);
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(Motor_VIRTUAL)
{
//int Speed = 90;
motor = param.asInt();
if (motor ==HIGH && motorstate ==0)
{
digitalWrite(motoron,HIGH);
digitalWrite(motoroff,LOW);
delay(1000);
digitalWrite(motoron,LOW);
//digitalWrite(motorspeed,LOW);
motorstate = 1;
}
else if (motor == LOW && motorstate == 1)
{
digitalWrite(motoroff,HIGH);
digitalWrite(motoron,LOW);
delay(1000);
digitalWrite(motoroff,LOW);
//digitalWrite(motorspeed,LOW);
motorstate = 0;
}
else {
digitalWrite(motoroff,LOW);
digitalWrite(motoron,LOW);
//digitalWrite(motorspeed,LOW);
}
}
BLYNK_WRITE(Light_VIRTUAL)
{
LightSW = param.asInt();
if (LightSW == HIGH)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
}
}
Regarding the connection I’m connecting the TX to pin 8 and the RX to a voltage divider and then ti pin 9 and i’m connecting pin 6 to a LED. Pin 12 and 13 to a relay module to control a 12v Motor and connecting the ESP8266 VCC and CH_PD pins to 3v input from power supply