Hi guys i’m new to arduino.
I’m working on a project, basically a dashboard of all the information i would need in my house, including a remote starter for my generator.
I live in haiti so we rely generaly on 3 power sources: The Grid, a Diesel generator, and an Inverter.
I was able to remotely turn on and off my generator with a simple relay shield. But I now i need feed back from my arduino to know which power source is on.
I’m using simple relays to make contact and act as buttons to turn on virtual LEDs on the blynk app, but i’m only able to make 1 LED work.
Please take a look at my code and let me know what I should fix.
Thanks,
Fredo
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "8d08897d16384f7a8dab7537e291720a";
// Select your pin with physical button
const int btnPin3 = 8; // pushbutton feedback GRID
const int btnPin4 = 9; // pushbutton feedback GENERATOR
const int btnPin5 = 10; // pushbutton feedback INVERTER
WidgetLED led3(V3);
WidgetLED led4(V4);
WidgetLED led5(V5);
SimpleTimer timer;
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth);
// Setup physical button pin (active low)
pinMode(btnPin3, INPUT_PULLUP);
pinMode(btnPin4, INPUT_PULLUP);
while (Blynk.connect() == false) {
// Wait until connected
}
timer.setInterval(500L, buttonLedWidget);
//---PUSH
// Setup notification button on pin 2
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
}
//---PUSH END ---
//---UPTIME+SYNC---
BLYNK_READ(V1) // Widget in the app READs Virtal Pin V1 with the certain frequency
{
// This command writes Arduino's uptime in seconds to Virtual Pin V1
Blynk.virtualWrite(1, millis() / 1000);
}
// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect)
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
// You can also update an individual Virtual pin like this:
//Blynk.syncVirtual(V0);
isFirstConnect = false;
}
//---UPTIME+SYNC END ---
//--- PUSH ---
void notifyOnButtonPress()
{
// Invert state, since button is "Active LOW"
int isButtonPressed = !digitalRead(2);
if (isButtonPressed) {
Blynk.notify("YO BAY LI!");
}
}
//--- PUSH END ---
// V3 LED Widget represents the physical button state
boolean btnState = false;
void buttonLedWidget()
{
// Read button
boolean isPressed = (digitalRead(btnPin3) == LOW);
// If state has changed...
if (isPressed != btnState) {
if (isPressed) {
led3.on();
} else {
led3.off();
}
btnState = isPressed;
}
boolean isPressed = (digitalRead(btnPin4) == LOW);
// If state has changed...
if (isPressed != btnState) {
if (isPressed) {
led4.on();
} else {
led4.off();
}
btnState = isPressed;
}
}
//--LED NOTIFICATION ON PRESS
void loop()
{
Blynk.run();
timer.run();
}