Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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 compiled for: Arduino Uno - Source Code created on: 2024-07-13 00:47:32 ********* 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
#include
//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 } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)