There are a couple of components to this code. There are voltage and temp readings and a motor control.
//#define BLYNK_DEBUG // Opt
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define BLYNK_NO_BUILTIN
//#define BLYNK_NO_FLOAT
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SPI.h>
#include <AFMotor.h>
#include <max6675.h>
#include "Adafruit_MAX31855.h"
#include <Keypad.h>
//Assign volt values to some number to start with
float volt1 = 2;
float volt2 = 3;
float volt3 = 4;
float volt4 = 5;
float volt5 = 8;
float volt6 = 9;
float volt7 = 10;
float volt8 = 11;
int maxValue = 3; // current sensor value that will trigger slowdown
int safeValue = 100; //safe motor speed
//Thermocouple Section
#define MAXDO1 23
#define MAXCS1 25
#define MAXCLK1 27
#define MAXDO2 48
#define MAXCS2 50
#define MAXCLK2 52
#define MAXDO3 41
#define MAXCS3 39
#define MAXCLK3 37
#define MAXDO4 47
#define MAXCS4 49
#define MAXCLK4 51
// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple2(MAXCLK2, MAXCS2, MAXDO2);
MAX6675 thermocouple4(MAXCLK4, MAXCS4, MAXDO4);
MAX6675 thermocouple3(MAXCLK3, MAXCS3, MAXDO3);
MAX6675 thermocouple1(MAXCLK1, MAXCS1, MAXDO1);
//LED
WidgetLED led1(V45);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
// Hardware Serial on Mega, Leonardo, Micro...
//Location of RX and TX pins on Arduino board
#define EspSerial Serial3
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
//Identify location of motor on shield
AF_DCMotor motor(2);
//Keypad Code..Use when there is no Internet
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {36, 34, 32, 30}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 26, 24};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int x = 0;
BlynkTimer timer;
//Below are functions they start with vois but are not the main void loop or void setup
void setup()
{
// Debug console
Serial.begin(115200);
EspSerial.begin(ESP8266_BAUD);
delay(2000);
Blynk.begin(auth, wifi, ssid, pass);
Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8080);
// Blynk.connectWiFi(ssid, pass);
//Blynk.begin(auth, wifi, ssid, pass, LOCAL_SERVER, 8080);
timer.setInterval(1000L, myTimerEvent);
timer.setInterval(3000L, getTemp);
timer.setInterval(3000L, getVolt);
// timer.setInterval(3000L, keyPad);
motor.run(RELEASE);
//motor.run(FORWARD);
}
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V60, millis() / 1000);//Assign the virtual pin(60) to the timer
}
void getVolt()
{
//assign the volt readings to an anologue pin
//volt1
volt1 = analogRead(A1);//Read the value of the potentiometer to val
volt1 = volt1/1024*5.0;// Convert the data to the corresponding voltage value in a math way
///volt2
volt2 = analogRead(A2);//Read the value of the potentiometer to val
volt2 = volt2/1024*5.0;// Convert the data to the corresponding voltage value in a math way
//volt3
volt3 = analogRead(A3);//Read the value of the potentiometer to val
volt3 = volt3/1024*5.0;// Convert the data to the corresponding voltage value in a math way
volt4 = analogRead(A4);//Read the value of the potentiometer to val
volt4 = volt4/1024*5.0;// Convert the data to the corresponding voltage value in a math way
//volt in arduino section
volt5 = analogRead(A5);//Read the value of the potentiometer to val
volt5 = volt5/1024*5.0;// Convert the data to the corresponding voltage value in a math way
///volt6
volt6 = analogRead(A8);//Read the value of the potentiometer to val
volt6 = volt6/1024*5.0;// Convert the data to the corresponding voltage value in a math way
//volt7
volt7 = analogRead(A9);//Read the value of the potentiometer to val
volt7 = volt7/1024*5.0;// Convert the data to the corresponding voltage value in a math way
volt8 = analogRead(A10);//Read the value of the potentiometer to val
volt8 = volt8/1024*5.0;// Convert the data to the corresponding voltage value in a math way
if (volt1 >= maxValue)
{
motor.run(FORWARD);
motor.setSpeed(safeValue);
led1.on();
Serial.println("LED on V1: red");
Blynk.virtualWrite(V20, safeValue);
}
if (volt1 <= maxValue)
{
led1.off();
Serial.println("LED on V1: off");
}
// if (volt1 <= maxValue)
// {
// motor.setSpeed(pinValue);
// }
//Assign each voltage reading to its own virtual pin
Blynk.virtualWrite(V1, volt1);
Blynk.virtualWrite(V2, volt2);
Blynk.virtualWrite(V3, volt3);
Blynk.virtualWrite(V4, volt4);
Blynk.virtualWrite(V5, volt5);
Blynk.virtualWrite(V6, volt6);
Blynk.virtualWrite(V7, volt7);
Blynk.virtualWrite(V8, volt8);
}
void getTemp()
{
// Assign a variable to the farenheit conversions of the digital pins
double t1 = thermocouple1.readFarenheit();
double t2 = thermocouple2.readFarenheit();
double t3 = thermocouple3.readFarenheit();
double t4 = thermocouple4.readFarenheit();
//Display these values in the Serial monitor(top right looking glass symbol)
Serial.print("Thermocouple Temp1 = *");
Serial.println(t1);
Serial.print("Thermocouple Temp2= *");
Serial.println(t2);
Serial.print("Thermocouple Temp3 = *");
Serial.println(t3);
Serial.print("Thermocouple Temp4= *");
Serial.println(t4);
//Assign each temp reading to its own virtual pin on Blynk app
Blynk.virtualWrite(V10, t1);
Blynk.virtualWrite(V11, t2);
Blynk.virtualWrite(V12, t3);
Blynk.virtualWrite(V13, t4);
}
BLYNK_WRITE(V20)
{
//Connect a virtual pin to the motor to control its speed
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
//Tell motor to run in one direction, forward
if (volt1 <= maxValue)
{
volt1 = analogRead(A1);//Read the value of the potentiometer to val
volt1 = volt1/1024*5.0;//
motor.run(FORWARD);
Serial.println(pinValue);
motor.setSpeed(pinValue);
}
//while (V1 > 2)
//{
// int pinValue = param.asInt();
// int pinValue2= pinValue/2;
// motor.run(FORWARD);
// Serial.println("pinValue2=");
// Serial.println(pinValue2);
// motor.setSpeed(pinValue2);
//}
//}
}
BLYNK_APP_DISCONNECTED() {
// Your code here
//void keyPad()
//{
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
motor.run(FORWARD);
if (customKey == '0')
{
motor.setSpeed(0);
}
if (customKey == '1')
{
motor.setSpeed(28);
}
if (customKey == '2')
{
motor.setSpeed(57);
}
if (customKey == '3')
{
motor.setSpeed(85);
}
if (customKey == '4')
{
motor.setSpeed(113);
}
if (customKey == '5')
{
motor.setSpeed(142);
}
if (customKey == '6')
{
motor.setSpeed(170);
}
if (customKey == '7')
{
motor.setSpeed(198);
}
if (customKey == '8')
{
motor.setSpeed(227);
}
if (customKey == '9')
{
motor.setSpeed(255);
}
}
}
void loop()
{
//Keep loop clean
//run blynk app and timer
Blynk.run();
timer.run(); // Initiates BlynkTimer
}