/* The Chamber Timer Controller Sketch V 1.0
This Arduino is needed since the Fright Idea flex controller is needed for the lighting effects, but is unable to cope with all of the functions we need in Chamber.
i.e. Automation of the timers and having a reset button in the chamber as well.
This sketch uses one momentary press button which is also wired into the Fright Ideas Flex Controller 206s. Hereafter referred to as the start button.
On pressing the start button the Fright Ideas Flex will move from idle to the Ambient scene and since that button is also wired to the Arduino it will also
start this timer sequence sketch.
The second button; hereafter named the reset button will turn off the timer power via relay 1.
Definitions of hardware:
Button 1 = Start button (Wired to input 1 of the Flex Controller and pin 2 of the Arduino)
Button 2 = Reset button (Wired to input 2 of the Flex controller and pin 3 of the Arduino)
Relay 1 = Timer Power Supply ***I need to investigate the usage of the reset button on the Timer board to see if that might work faster or better*** (This is connected to pin 4, 5 Volt and GND of the Arduino on one side and from the wall socket Positive wire through the NO connectors to the Timer itself to supply and interrupt power to the timer)
Relay 2 = Timer Mode Button (Pressed once it turns the Timer from the time function to the countdown timer function)
Relay 3 = Timer Up button (Wehn pressed this causes the hours unit to change to 1 i.e. 60 minutes)
Relay 4 = Timer Start/Pause button (This is the snooze button on the top of the timer and will also pause the timer) ***This needs to be developed further so that on success of the room which will depend on a door magnetic sensor which will be a reed switch, it will cause the countdown to pause so we have an accurate record of the time which the door was opened for the leaderboard and record keeping***
This sketch also incorperates an ESP-8266 ESP-01 to join the Wi-Fi and then connect back to a node-red server at 10.0.0.24 to enable remotly pressing the start and reset buttons
The ESP code has been removed until I figure out how to get the ESP8266 to play nice and connect with the Uno R3. Untill that time the code is commented out
Version 1.1 - Added a cooldown of 60 minutes for the startbutton with the exception that if the reset button has been reset then
it will auto reset the cooldown period to allow the start button to be pressed again.
Version 2.1 - Modified for an Arduino Nano and five volt relays
***For the button mapping make sure there is a voltage divider installed since the buttons area also wired to the Pico which is running at 12-volts.
12V ---------- R1 ---------- R2 ---------- GND
|
Arduino Pin
Use the following formula
Vout = Vin * (R2 / (R1 + R2))
In this instance I will be using a 10k for R1 and a 20k for R2 in conjunction.
These will be wired across the positive and negative terminals of the button.
R1 is connected to the positive and the R2 is connected to the ground. Off of this comes the input button to the Arduino.
Wiring Diagram
5 Volt - Red
GND - Blk
Start Button 1 - Yellow - Pin 2
Reset Button 2 - White - Pin 3
ModeRelay - Blue - Pin 4
UpRelay - Orange - Pin 5
StartPauseRelay - Green - Pin 6
ResetRelay - Brown - Pin 7
***These match up with the ethernet cables that are soldered to the timer and running to the relays
*/
// Arduino sketch for controlling relays with buttons using Arduino Nano
// Defining Button Pins
const int StartButton = 2;
const int ResetButton = 3;
// Defining Relay Pins
const int ModeRelay = 4;
const int UpRelay = 5;
const int StartPauseRelay = 6;
const int ResetRelay = 7;
// Cooldown period for the Start button in milliseconds
const unsigned long startButtonCooldown = 60 * 60 * 1000; // 60 minutes in milliseconds
unsigned long lastStartButtonPressTime = 0;
void setup() {
// Establish a Serial Connection at 9600 Baud
Serial.begin(9600);
// Set StartButtonPin and ResetButtonPin as INPUT
pinMode(StartButton, INPUT);
pinMode(ResetButton, INPUT);
// Set Relay Pins to OUTPUT and Low Voltage
pinMode(ModeRelay, OUTPUT);
pinMode(UpRelay, OUTPUT);
pinMode(StartPauseRelay, OUTPUT);
pinMode(ResetRelay, OUTPUT);
digitalWrite(ModeRelay, LOW);
digitalWrite(UpRelay, LOW);
digitalWrite(StartPauseRelay, LOW);
digitalWrite(ResetRelay, LOW);
delay(5000);
// Print that the connection for Serial Communication is established
Serial.println("Serial Connection Established");
}
void loop() {
unsigned long currentTime = millis();
static bool cooldownActive = false;
// Check if the cooldown period has passed
if (cooldownActive && (currentTime - lastStartButtonPressTime >= startButtonCooldown)) {
cooldownActive = false;
Serial.println("Cooldown ended");
}
// Check if the StartButton is pressed and cooldown period has passed
if (digitalRead(StartButton) == HIGH && !cooldownActive) {
Serial.println("Start Button Pressed");
// Trigger mode relay for 1 second
digitalWrite(ModeRelay, HIGH);
delay(1000);
digitalWrite(ModeRelay, LOW);
Serial.println("Mode Relay triggered");
// Trigger up relay for 1 second
digitalWrite(UpRelay, HIGH);
delay(1000);
digitalWrite(UpRelay, LOW);
Serial.println("Up Relay triggered");
// Trigger start and pause relay for 1 second
digitalWrite(StartPauseRelay, HIGH);
delay(1000);
digitalWrite(StartPauseRelay, LOW);
Serial.println("Start/Pause Relay triggered");
// Update the last start button press time
lastStartButtonPressTime = currentTime;
// Set cooldown active to true
cooldownActive = true;
Serial.println("Cooldown started");
}
// Check if the ResetButton is pressed
if (digitalRead(ResetButton) == HIGH) {
Serial.println("Reset Button Pressed");
// Trigger Reset Relay for 2 seconds
digitalWrite(ResetRelay, HIGH);
delay(2000);
digitalWrite(ResetRelay, LOW);
Serial.println("Reset Relay triggered");
// Reset the cooldown period for the Start button
lastStartButtonPressTime = currentTime;
cooldownActive = false;
Serial.println("Waiting for Start Button");
}
}