/********* 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: "Voltage Relay"
- Source Code NOT compiled for: ESP32 DevKit V1
- Source Code created on: 2024-07-19 05:30:37
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* when input of 2v is provided to giop 0, we recieve */
/* output from giop 4 to drive relay */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/rafaelnsantos/Relay
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t input_PIN_D0 = 0;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t relay_RelayModule_Signal_PIN_D4 = 4;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool relay_RelayModule_Signal_PIN_D4_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float relay_RelayModule_Signal_PIN_D4_phyData = 0.0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Relay light(relay_RelayModule_Signal_PIN_D4, true); // Initialize relay on pin 4, Normally Open
void setup(void)
{
// put your setup code here, to run once:
pinMode(input_PIN_D0, INPUT); // Initialize the input pin
light.begin(); // Initialize the relay pin
}
void loop(void)
{
// put your main code here, to run repeatedly:
updateOutputs(); // Refresh output data
}
void updateOutputs()
{
// Read the input voltage on pin D0
int inputVoltage = analogRead(input_PIN_D0);
// Check if the input voltage is approximately 2V
if (inputVoltage >= 409 && inputVoltage <= 614) // Assuming 3.3V ADC reference, 2V is approximately in this range
{
light.turnOn(); // Turn relay on
}
else
{
light.turnOff(); // Turn relay off
}
bool isLightOn = light.getState(); // Get relay state
// Use isLightOn variable as needed
}
/* END CODE */