Hi, I have this code to remotely boot my computer.
Wemos power comes from the 5v computer. and I have connected to the relay by the (-) to the start button of the computer.
I also have in the D5 input of the Wemos, 3v that come from the Led of the computer when it is on.
The DHT measures the temperature inside the computer and the bmp280 measures the temperature outside.
In the code I have another led to know when the relay is active.
This I have done copying from other codes, so I need a little help with the response speed of the Led.
This code works well, except when the computer is suspended, since the LED starts to flash, but Blynk does not reflect (I think it’s because of the refresh rate)
This is the code:
//#define BLYNK_PRINT Serial
#include <ArduinoOTA.h> //OTA
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <SimpleTimer.h> //Good timer library
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define DHTPIN D4 // Pin for DHT
#define Relay_1 D7 // Pin for Relay
#define computer D5 // + Led Input Computer
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bme; // I2C D1 D2
int temp;
int humidity;
char auth[] = "xxxxxxxxxxxxxxxxx"; //Auth Token for project
// Select your pin with physical button
const int cmpPin = D5;
const int btnPin = D7;
// Blynk Led Widget
WidgetLED led0(V0); //register led to virtual pin 0
WidgetLED led1(V1); //register led to virtual pin 1
SimpleTimer timer;
String myHostname = "Computer";
void setup(){
Serial.begin(115200);
dht.begin();
bme.begin();
WiFi.hostname(myHostname);
Blynk.begin(auth, "SSID", "PASSWORD");
Serial.println("Blynk test!");
Serial.println();
ArduinoOTA.setHostname("Computer"); // OPTIONAL
ArduinoOTA.begin();
// Setup physical button pin (active low)
pinMode(btnPin, INPUT_PULLUP);
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, LOW);
pinMode(Relay_1, OUTPUT);
pinMode(computer, INPUT);
delay(4000); //Check that all relays are inactive at Reset
while (Blynk.connect() == false) {
// Wait until connected
}
// Setup function to be called every 2 seconds
timer.setInterval(2000, sendData);
timer.setInterval(10L, buttonLedWidget);
timer.setInterval(10L, computerLedWidget);
}//--(end setup )---
// V0 LED Widget represents the physical computer state
boolean cmpState = false;
void computerLedWidget()
{
// Read button
boolean isPressed = (digitalRead(cmpPin) == LOW);
// If state has changed...
if (isPressed != cmpState) {
if (isPressed) {
led0.off();
} else {
led0.on();
}
cmpState = isPressed;
}
}
// V1 LED Widget represents the physical relay state
boolean btnState = false;
void buttonLedWidget()
{
// Read relay
boolean isPressed = (digitalRead(btnPin) == LOW);
// If state has changed...
if (isPressed != btnState) {
if (isPressed) {
led1.off();
} else {
led1.on();
}
btnState = isPressed;
}
}
void sendData()
{
float t = dht.readTemperature();
float h = dht.readHumidity();
float T = bme.readTemperature();
float p = bme.readPressure();
Blynk.virtualWrite(V2, t);
Blynk.virtualWrite(V3, h);
Blynk.virtualWrite(V4, T-1.6);
Blynk.virtualWrite(V5, p/100);
}
void loop(){
Blynk.run();
timer.run(); // Initiates SimpleTimer
ArduinoOTA.handle(); //OTA
}
.