Timers and relays and switches..

Status
Not open for further replies.

Wayne

Well-known member
Ok, Started a new project and I have to make a choice on what timers to use and sense a low input from a relay and pulse a relay on.
I need to make 10 circuits of this as a repeat for discharging batteries and recharge for 50 cycles.

The input to trigger the relay is from the discharge circuit already made, when the battery goes to about 6 volts, the relay closes a set of contacts. Originally it does nothing, but I will use this as a trigger.
To start the discharge of the battery, I have a push button. Push the button, an LED comes on and a low ohm resistor is in circuit to discharge the battery.
The sense for when to stop is a Zener and 2 relays. One is a 5 volt relay and the other is a 4.5 volt. The 5 volt drops out first and that is the one to signal to recharge. This will charge/discharge up to 50 times and stop as I said before.

The problem is I will time the charging at guessing how long it is to recharge the battery. Guessing is 3 hours currently (has lead way here).

I have tried elapsemillis with some success. I need to do debounce..

The test circuit code runs for 10 secs when I push the button I have (Acts as relay when done goes LOW)
I show the time and print so I know where I'm at in the program
I release the button as quick as I can and when I see the LED lite

I have now got myself in a loop and even this is so small, I now have myself confused.

Code I have started.. no debounce and it still has issues.

Code:
const int ledPin = 13;

int hour = 1000; // 3600000 milliseconds in an hour
int state = HIGH;
elapsedMillis battery1;
elapsedMillis battery2;
elapsedMillis battery3;
elapsedMillis relaypulse;

//long hour = 3600000; // 3600000 milliseconds in an hour

int battery1in = 1;
int battery2in = 2;
int battery3in = 3;
int battery1pass;
int battery1count;


// delay in milliseconds between blinks of the LED
// unsigned int interval = 60 x 60 x1;


// the setup() method runs once, when the sketch starts

void setup() {
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  Serial.begin(9600);
}

// the loop() methor runs over and over again,
// as long as the board has power

void loop()
{

  if (digitalRead(0) == LOW && battery1pass == 0 && battery1count < 10)  // start led high after low on input 0 (operate relay)
  {
    battery1 = 0;                                   // reset timer to 0
    battery1pass = 1;                               // set condition
    digitalWrite(ledPin, LOW);
  }
  if (digitalRead(0) == LOW && battery1 > 10000 && battery1count < 10)   // while low on input 0 and secs pass led goes low (turn off relay)
  {
    //relaypulse=0;
    digitalWrite(ledPin, LOW); Serial.print(relaypulse); Serial.println("   Time has Passed");
    if (relaypulse > 500 + battery1)
    {
      digitalWrite(ledPin, HIGH); Serial.println("Pulse Relay");
      relaypulse = 0; battery1 = 0;
    }
    battery1 = 0;
  }
  if (digitalRead(0) == HIGH && battery1pass == 1 && battery1count < 10) // immediately return conditions for input 0 to normal and increase count by 1
  {
    battery1count = battery1count + 1;delayMicroseconds(100);
    digitalWrite(ledPin, LOW); Serial.print("Battery 1 count = "); Serial.println(battery1count);
    battery1pass = 0;

  }
}

And if you have suggestions for 10 circuits or anything, tell me.. I will learn.

Wayne
 
The method to get the 10 circuits working without massive amounts of code is arrays, and specifically the example down the page using a for loop
https://www.arduino.cc/en/Reference/Array
This allows you to test 10 inputs, check the logic and proceed to driving the relevant relays. Though can see a potential for running out of pins so you may need some form of port expander.

Is there a reason why you are using relays rather than some form of analogeRead to check the battery level?
 
Thanks for the suggestion, I will do this tomorrow.
The test for voltage, I guess I can check and trigger when a level hits a value. The batteries will be off their own chargers.. I will log the voltage from a dead battery to fully charged.

I did change to timerobject. When things are simple, I get confused easier.

Wayne
 
An update.. I have completed a code, pretty long, and instead of the teensy, I'm using a 2560. The relays are the old TK1-4.5/5v type and I'm driving a 200ms pulse as a push button to activate.
So far since Friday, it has done 11 runs. With so much of a repeat of code (8 instead of the original 10 batteries), I dupe 1 line wrong. Found it, fixed it and running.
Pressure was on to get it done.

Now back to making 32 interface boards for production (the 1st project way back when) that is working great.
Again all, thanks for the input.

Oh, what are the 32 boards, well, interface of an analog photo resistor. Input analog, output controls 32" LED panel.
The other project was more involves, Serial input to convert to digital for LED panel, and, 57600 P-Cap touch to old 9600 serial with 80x80 resolution. Plus more..

Wayne
 
Status
Not open for further replies.
Back
Top