Help with Arduino circuit

Hi xfpd,

This was an older version previously presented and changed resulting from advice on this forum.

  • I need it so my 1 1/2 eyes can see it. :older_man:
  • What is the voltage going to the Arduino Vin pin ?

  • What is the voltage written on the relay ?

  • What are you doing with Q2 ?

  • I do not recommend you keying the relay module DC- terminal.
  • This might be your relay Module.
  • If it is, set to HIGH then a HIGH from the Arduino would energize the relay.
    If the relay module is set to LOW, the relay might be non functional.

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.. :smiley: :+1: :coffee: :australia:

Hi,
I hope I have interpreted the schematic.
You need to combine your gnds, system gnd and power gnd.

I am not sure what pins you have the LEDS connected to?
Need your code.

Tom.. :smiley: :+1: :coffee: :australia:

  • Now that’s what I was taking about !
    :+1:

  • I think the OP has 7v connected to relay 5v ? :thinking:
    I think the OP has DC- being keyed by a NPN BJT ? :thinking:
    Did OP have kickback across the pump ? :thinking:

  • Hey since you have time, how about learning how to shovel snow ? :cloud_with_snow:

Why, I don't know, so I left it out.
Makes no sense.

And superfluous resistors between supply and gnd.

Tom... :smiley: :+1: :coffee: :australia:

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

  1. Why am I keying the relay board negative? I am researching what this means
  2. Voltage to Arduino is 7V
  3. Relay voltage is 5V with 30V DC output capacity
  4. Q2- was an attempt to only power the relay when it is required
  5. (Larry) - I do not recommend you keying the relay module DC- terminal. I assume this is the same as no 1 above. I do not understand what I need to change. How do I set this to hiigh - is this not done in the code?

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;
      }
    }
}
![smoke pcb image|465x500](upload://pxpfBwgXDKQ6kKi40HBl63Xi4ck.jpeg)
![SMoke Main pcb schematic|690x450](upload://w1jI9Ga1P4OOTfcbjFcG4g19o4H.jpeg)
![schematic external components|676x499](upload://C8X6D60ItrhL5w1FJX2ofv50SG.jpeg)

  • I don’t know either.

Try putting this in the post not the code tags.

Tom.. :smiley: :+1: :coffee: :australia:

@dovoaussie1

  • Suggest you forget about using HIGH/LOW in your code, instead use macros.
#define RELAYon     HIGH
#define RELAYoff    LOW
. . .
digitalWrite(RelayPinOut, RELAYon);
. . .
digitalWrite(RelayPinOut, RELAYoff);



  • Bed time

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

  1. I note that you have removed the transistor - I will certainly try that
  2. I see you have connected the relay to 5v+. I have 14v or 7v - Is 7V ok, or can I use the 5V out from the Arduino?
    3, I have tried to combine grounds, but that did not solve the problem.

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.

  1. Should I not be powering the load on the input side of the Converter? If not how do I get the 12V needed for the pump.
  2. How do I prevent the converter dropping voltage. It already has capacitors built in? This is the converter I am using ...(converter)

All help appreciated.