Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: "Bluetooth Relay"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-07-13 00:46:07
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Disconnecting and connecting the power supply, */
- /* when the character string "soldier: connected" is */
- /* received, the power supply should be turned on, */
- /* and if "soldier; off" is received, cut off the */
- /* power supply. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- #include <Relay.h> //https://github.com/rafaelnsantos/Relay
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t soldier_RelayModule_Signal_PIN_D2 = 2;
- /***** DEFINITION OF Software Serial *****/
- const uint8_t myHC05_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
- const uint8_t myHC05_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
- SoftwareSerial myHC05_HC05_mySerial(myHC05_HC05_mySerial_PIN_SERIAL_RX_A1, myHC05_HC05_mySerial_PIN_SERIAL_TX_A0);
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool soldier_RelayModule_Signal_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float soldier_RelayModule_Signal_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Relay light(soldier_RelayModule_Signal_PIN_D2, true); // Initialize relay on pin 2, Normally Open
- void setup(void)
- {
- // put your setup code here, to run once:
- light.begin(); // Initialize the relay pin
- myHC05_HC05_mySerial.begin(9600); // Initialize software serial communication
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // Check if data is available on the serial port
- if (myHC05_HC05_mySerial.available()) {
- String receivedString = myHC05_HC05_mySerial.readStringUntil('\n'); // Read the incoming string until newline character
- // Check for specific commands and update the relay state
- if (receivedString == "soldier: connected") {
- soldier_RelayModule_Signal_PIN_D2_rawData = true; // Turn on the relay
- } else if (receivedString == "soldier: off") {
- soldier_RelayModule_Signal_PIN_D2_rawData = false; // Turn off the relay
- }
- }
- }
- void updateOutputs()
- {
- if (soldier_RelayModule_Signal_PIN_D2_rawData) {
- light.turnOn(); // Turn relay on
- } else {
- light.turnOff(); // Turn relay off
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement