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: Relay Controller
- - Source Code NOT compiled for: Arduino Nano ESP32
- - Source Code created on: 2025-08-13 12:40:49
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* esp32 with i2c display,one relay out,one swich for */
- /* start, one swich for stop, one swich for time */
- /* setting up,one swich for time setting down,one */
- /* ds18b20 temperature sensor. */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - not working
- #### Feedback 2 ####
- - no oled in my scope
- ********* User code review feedback **********/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- // Define pins for switches
- const int startSwitchPin = 2; // Start button
- const int stopSwitchPin = 3; // Stop button
- const int timeUpSwitchPin = 4; // Time setting up
- const int timeDownSwitchPin = 5; // Time setting down
- // Define pin for relay
- const int relayPin = 6;
- // Define pin for DS18B20 temperature sensor
- const int oneWireBusPin = 7;
- // Create OneWire and DallasTemperature objects
- OneWire oneWire(oneWireBusPin);
- DallasTemperature sensors(&oneWire);
- // Variables for system state
- bool systemRunning = false;
- int temperature = 0;
- int setTimeMinutes = 0;
- void setup() {
- // Initialize serial communication
- Serial.begin(115200);
- // Initialize pins
- pinMode(startSwitchPin, INPUT_PULLUP);
- pinMode(stopSwitchPin, INPUT_PULLUP);
- pinMode(timeUpSwitchPin, INPUT_PULLUP);
- pinMode(timeDownSwitchPin, INPUT_PULLUP);
- pinMode(relayPin, OUTPUT);
- // Initialize relay
- digitalWrite(relayPin, LOW); // Relay off
- // Initialize temperature sensor
- sensors.begin();
- // Initial status message
- Serial.println("System initialized");
- }
- void loop() {
- handleSwitches();
- readTemperature();
- // Optional: Send status over serial for debugging
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.print(" C, Set Time: ");
- Serial.print(setTimeMinutes);
- Serial.print(" min, Status: ");
- Serial.println(systemRunning ? "RUNNING" : "STOPPED");
- delay(200); // Loop delay
- }
- void handleSwitches() {
- // Read switch states
- bool startState = digitalRead(startSwitchPin) == LOW;
- bool stopState = digitalRead(stopSwitchPin) == LOW;
- bool timeUpState = digitalRead(timeUpSwitchPin) == LOW;
- bool timeDownState = digitalRead(timeDownSwitchPin) == LOW;
- if (startState) {
- systemRunning = true;
- digitalWrite(relayPin, HIGH); // Turn relay on
- }
- if (stopState) {
- systemRunning = false;
- digitalWrite(relayPin, LOW); // Turn relay off
- }
- if (timeUpState) {
- setTimeMinutes++;
- }
- if (timeDownState) {
- if (setTimeMinutes > 0) {
- setTimeMinutes--;
- }
- }
- }
- void readTemperature() {
- sensors.requestTemperatures();
- temperature = sensors.getTempCByIndex(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment