Hi xfpd,
This was an older version previously presented and changed resulting from advice on this forum.
Hi xfpd,
This was an older version previously presented and changed resulting from advice on this forum.
What is the voltage going to the Arduino Vin pin ?
What is the voltage written on the relay ?
What are you doing with Q2 ?
The CAD program you are using can produce a jpg copy or your PCB pattern, you can post that jpg DIRECTLY into your post, rather than put it in a remote drive.
We need to see your PCB pattern to see your component layout.
We still need to see your code, in code tags....
Thanks.. Tom..
![]()
Why, I don't know, so I left it out.
Makes no sense.
And superfluous resistors between supply and gnd.
Tom...
![]()
Hi All,
Apologies I replied directly in my email expecting it to make it to the forum.
This is what I posted ...Use code tags to format code for the forum
Thanks for your time- it is immensely appreciated.
I attach the images, and also the code below
An attempt to answer some questions
SO now it is clear I have no idea what I am doing. But here is the interesting thing. If I plug the arduino into the usb to the computer (and leave the power supply and everything else as is), the relay seems to work and does not reset.
// 2024.10.0825
//Pin12 not working
// Assign Pins
//Note on toggle
// Pin 1 on toggle connects to pin 3 of DB25
// Pin 2 on toggle connects to pin 1 of DB25 (GND)
// Pin 3 on toggle connects to pin 2 of DB25
// Pin 4 on toggle connects to pin 21 of DB25
// Pin 5 on toggle connects to pin 3 of GND
// Pin 6 on toggle unused
int SmokeManualOnLEDRed = 8; // Manually Selected On RED LED
int SmokeArmedLEDGreen = 13; // Turn on Green LED
int SmokeActiveLEDBlue = 7; //To turn blue LED on when smoke is on
int SmokeArmSwitch = 2; // Toggle switch to Arm mode
int SmokeOnSwitch = 3; // Toggle switch to On mode
int StickButton = 5; // Tosten momentary switch on stick
int RelayPinOut = 10; // Switch Relay
int RelayPower = 4; // power relay if armed or On
int TonePin = 11; //To akert when smoke is on
int AudioOut2 = 6; //Spare Audio Out to allow for different code if the buzzer output dies not work. Code not inserted at this stage
int SkyviewInput = 9; //Input to skyview for sensor Grey =off (<1.5V), Green = Armed (1.5-3V), Blue =Smoke On (>3V)
// System Parameters
const unsigned long DoubleClickInterval = 500; // Max time between clicks
unsigned long LastPressTime = 0; // Time of the last button press
bool ButtonPressed = false; // Track if the button is currently pressed
int ClickCount = 0; // Count of button clicks
const int BeepDuration = 200; //Length of Beeps
const int SkyviewOff =0;
const int SkyviewArmed = 120;
const int SkyviewOn = 200;
// Variable Definitions
bool SmokeOnSelect = HIGH; // On Switch - low = selected
bool SmokeArmedSelect = false; // false = off Variable to track if smoke relay should activate or not based on ARM
bool StickStatus = HIGH; // Stick Pushbutton - low = pushed
String LastState = "OFF"; //Track Last State
bool SmokeOn = false; // Variable to track if smoke is on
bool OnBeep = false; //Used to track if ON beep has occured when SMOKE_ON switches states
bool OffBeep = true; //Used to track if OFF beep has occured when SMOKE_ON switches states
void setup() {
pinMode(SmokeManualOnLEDRed, OUTPUT); //Pin 8
pinMode(SmokeArmedLEDGreen, OUTPUT); //Pin 13
pinMode(SmokeActiveLEDBlue,OUTPUT); //Pin 7
pinMode(SmokeArmSwitch, INPUT_PULLUP);
pinMode(SmokeOnSwitch, INPUT_PULLUP);
pinMode(StickButton, INPUT_PULLUP);
pinMode(RelayPinOut, OUTPUT); //Pin 10
pinMode(TonePin,OUTPUT);
pinMode(SkyviewInput,OUTPUT);
pinMode(RelayPower,OUTPUT);
// Initialise Status
digitalWrite(SmokeManualOnLEDRed, LOW);
digitalWrite(SmokeArmedLEDGreen, LOW);
digitalWrite(SmokeActiveLEDBlue,LOW);
digitalWrite(RelayPinOut, LOW);
digitalWrite(SkyviewInput,LOW);
digitalWrite(RelayPower,HIGH);
Serial.begin(9600);
SmokeOn = false;
LastState = "OFF";
//Play Startup Tone to Warn system is armed
tone(TonePin,200,BeepDuration);
delay(BeepDuration);
tone(TonePin,400,BeepDuration);
delay(BeepDuration);
tone(TonePin,600,BeepDuration*1.5);
delay(BeepDuration*1.5);
}
void loop() {
// Read the switch states
Serial.print("2. Laststate:"); Serial.println(LastState);
SmokeArmedSelect = digitalRead(SmokeArmSwitch);
SmokeOnSelect = !digitalRead(SmokeOnSwitch); // Note Not operator
StickStatus = digitalRead(StickButton);
//STart
Serial.print("1. Laststate:"); Serial.println(LastState);
Serial.print("1. SmokeArmedSelect:"); Serial.println(SmokeArmedSelect);
Serial.print("1. SmokeOnSelect:"); Serial.println(SmokeOnSelect);
Serial.print("1. StickStatus:"); Serial.println(StickStatus);
Serial.print("1. RelaypPinOut:"); Serial.println(digitalRead(RelayPinOut));
// delay(1000);
//End
// Handle button press for double-click detection
if (StickStatus == LOW) {
if (!ButtonPressed) {
ButtonPressed = true; // Button is pressed
unsigned long CurrentTime = millis();
// Check if this is a new click or a double click
if (CurrentTime - LastPressTime <= DoubleClickInterval) {
ClickCount = 2; // Increment click count for double-click
} else {
ClickCount = 1; // Reset to 1 for a new click
}
LastPressTime = CurrentTime; // Update last press time
}
} else {
// Button is released
if (ButtonPressed) {
ButtonPressed = false; // Reset button pressed state
// Handle click actions based on click count
if (ClickCount == 1) {
Serial.println("Button Pressed Once");
SmokeOn = false; // Toggle smoke off
digitalWrite(RelayPinOut, LOW); // Turn relay off
digitalWrite(SmokeActiveLEDBlue, LOW);
} else if (ClickCount == 2) {
Serial.println("Button Pressed Twice");
SmokeOn = true; // Toggle smoke on
digitalWrite(RelayPinOut, HIGH); // Turn relay on
digitalWrite(SmokeActiveLEDBlue, HIGH);
}
// Reset click count after processing
ClickCount = 0;
}
}
// State management based on switch positions
if (!SmokeArmedSelect && !SmokeOnSelect) { // Bottom Switch position - This represents OFF
digitalWrite(SmokeManualOnLEDRed, LOW);
digitalWrite(SmokeArmedLEDGreen, LOW);
digitalWrite(RelayPower,LOW);
digitalWrite(RelayPinOut, LOW);
digitalWrite(SmokeActiveLEDBlue, LOW);
SmokeOn = false;
LastState = "OFF";
//Serial.print("1. Laststate:"); Serial.println(LastState);
} else if (SmokeArmedSelect && !SmokeOnSelect) { // Smoke armed - Green LED
digitalWrite(RelayPower,HIGH);
if (LastState != "ARMED") {
digitalWrite(RelayPinOut, LOW);
digitalWrite(SmokeActiveLEDBlue, LOW); // Turn Pump LED(Blue LED) OFF
SmokeOn = false;
}
//Serial.print("2. SmokeOn Status:"); Serial.println(SmokeOn);
digitalWrite(SmokeManualOnLEDRed, LOW);
digitalWrite(SmokeArmedLEDGreen, HIGH);
LastState = "ARMED";
} else { // Smoke ON - Red LED
SmokeOn = true;
//digitalWrite(RelayPower,HIGH); //If using the other side of the switch to turn the pump on directly, then disable relay
//digitalWrite(RelayPinOut, HIGH); //If using the other side of the switch to turn the pump on directly, then disable relay
digitalWrite(SmokeArmedLEDGreen, LOW);
digitalWrite(SmokeManualOnLEDRed, HIGH);
digitalWrite(SmokeActiveLEDBlue, HIGH); // Turn Blue LED on
LastState = "ON";
}
delay(100); // Short delay to stabilize loop
//Skyview Output
if(LastState=="OFF") {
analogWrite(SkyviewInput,SkyviewOff);
}
else if (LastState=="ARMED") {
analogWrite(SkyviewInput,SkyviewArmed);
}
else {
analogWrite(SkyviewInput,SkyviewOn);
}
//play tones
if (SmokeOn) {
while (OnBeep==false) {
tone(TonePin,20,BeepDuration/2);
delay(200);
tone(TonePin,80,BeepDuration/2);
delay(BeepDuration+200);
OffBeep = false;
OnBeep=true;
}
}
else {
while (OffBeep==false) {
tone(TonePin,800,BeepDuration/2);
delay(200);
tone(TonePin,200,BeepDuration/2);
delay(BeepDuration+200);
OnBeep=false;
OffBeep=true;
}
}
}



Try putting this in the post not the code tags.
Tom..
![]()
#define RELAYon HIGH
#define RELAYoff LOW
. . .
digitalWrite(RelayPinOut, RELAYon);
. . .
digitalWrite(RelayPinOut, RELAYoff);
I highly recommend to not use a String variable as state variable. Use int.
Give your states numbers...
const int ARMED =1;
Then:
if(something) state =ARMED;
Later:
if (state==ARMED) {
Do whatever needs done
}
Even better: use ENUM
And use switch case...
Seems you have a power supply problem.
Post a schematic of your setup.
And a photo...
I now see there is a schematic...
For some reason I am not allowed to delete my last post...
Hi All,
Thanks for your time (I am in Australia so my responses may be delayed).
TomGeorge, thanks a heap. That schematic looks more understandable
LarryD and Build_1971, thanks for the recommendation on the code- I will make those changes.
I am still confused as to why the system works when the Arduino is plugged into the computer, but not on standalone power. My DC converter is set to have a 7V output. I have tried with 9V as well.
Any other suggestions will be hugely appreciated.
Not sure if I read the schematic in #27 correctly....
Is the pump power supply running up and down your signal cable???
That seems like a bad idea...
What kind of pump is it?
What cable/connectors do you use?
Also 14.4V at the left seems to come through diode in non conducting direction...(D2)
Hi,
I dont believe the pump is running from a signal. It is powered by 14.4V from relay and Ground
The pump is this one ..pump
I know this is 12V (and I have my power supply set at 12V, I will put a resistor to bring down the 14.4 to 12v)
I am using Molex connectors for the pump and terminal blocks on the pcb.
The diode is position to provide power to the pump.
This is all confusing as the system works when plugged into the usb, so must be some kind of power problem?
Relay goes to pin 21, other end of csble D1, pin 22, other end of cable, pump...
So up and down through the cable...
And how does 14.4V get to your converter?
Hi,
I think you have picked up a problem. Let me explain. The idea was that there would be 2 ways to power the pump. 1. The first being the NO from the relay via the D2 to pin 22 of the DSUB. 2 - The second way was when the toggle switch was manually on, it would power the pump via pin 21 via D2 to pin 22 to power the pump.
There is definitely a problem with the second route, but I have not even connected this yet, so although that is a problem, its not my main problem right now.
I have gone back to the breadboard, debugged, and narrowed the problem down to a simplistic one.
See diagram attached - Assume I only have power connected to the DC Converter supplying 7V to the Arduino. When I connect a load to the 14v side of the converter, the output 7V to the Arduino drops to below 3V and the Arduino resets, and the relay then resets.
All help appreciated.