/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: "Blynk Relay"
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-06-29 17:42:07
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* The system should control a relay module connected */
/* to digital pin D2 using the Relay library. The */
/* relay on off same as switch on off at blynk */
/****** SYSTEM REQUIREMENT 2 *****/
/* Create a system to manage a relay module on */
/* digital pin D2 with the Relay library. The relay */
/* should respond to a Blynk app switch, ensuring */
/* synchronized on/off states for efficient remote */
/* control. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/rafaelnsantos/Relay
#include // Blynk library for serial communication
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
BLYNK_WRITE(V1); // Blynk function to handle virtual pin V1 writes
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t relay_RelayModule_Signal_PIN_D2 = 2;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool relay_RelayModule_Signal_PIN_D2_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float relay_RelayModule_Signal_PIN_D2_phyData = 0.0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Relay light(relay_RelayModule_Signal_PIN_D2, true); // Initialize relay on pin 2, Normally Open
/****** BLYNK AUTH TOKEN *****/
char auth[] = "YourAuthToken"; // Replace with your Blynk Auth Token
void setup(void)
{
// put your setup code here, to run once:
Serial.begin(9600); // Initialize serial communication
Blynk.begin(Serial, auth); // Initialize Blynk with serial communication
light.begin(); // Initialize the pin
}
void loop(void)
{
// put your main code here, to run repeatedly:
Blynk.run(); // Run Blynk
updateOutputs(); // Refresh output data
}
void updateOutputs()
{
// Example of using the Relay library functions
relay_RelayModule_Signal_PIN_D2_rawData = light.getState(); // Get relay state
}
// Blynk function to handle virtual pin V1 writes
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // Get the value from the Blynk app
if (pinValue == 1) {
light.turnOn(); // Turn relay on
} else {
light.turnOff(); // Turn relay off
}
}