Go Down

Topic: self resetting switch? (Read 328 times) previous topic - next topic

RudiAhlers

Hi,

Is it possible to create a "self resetting switch" (if that makes sense?), possibly with some PNP or NPN transistors and a momentary push button?

I am building a battery monitor for 12V lead acid batteries in series, and parallel, and don't want to activate the relay power until everything is plugged in, and the Arduino booted up.

So I'm thinking of triggering a transistor with a push button, which will then stay activated till power is lost from the circuit, but don't know what to look for on google.

DVDdoug

An SCR (or TRIAC) will latch-on when triggered and won't turn-off until current is cut-off.   All you need is the SCR and a current-limiting resistor for the gate.

Quote
and don't want to activate the relay power until everything is plugged in, and the Arduino booted up.

So I'm thinking of triggering a transistor with a push button...
You could trigger the SCR from an Arduino output pin.   i.e.  Write the pin high as the last step in your setup.

RudiAhlers

An SCR (or TRIAC) will latch-on when triggered and won't turn-off until current is cut-off.   All you need is the SCR and a current-limiting resistor for the gate.
You could trigger the SCR from an Arduino output pin.   i.e.  Write the pin high as the last step in your setup.
Thanx for the suggestion on the name. I don't have SCR's but see there are some circuits using a PNP and NPN transistor.

And, yes, I would like to trigger the relays with the Arduino sketch, but only once this manual switch is engaged as well.

JohnRob

Does your relay have an extra (unused) set of contacts?

If so you can make the function you want with a single transistor (or Mosfet), using the extra contacts to continue the circuit once the arduino boots up.


Is there a reason you don't want to just use a single transistor controlled from the arduino to enable the relay?

Please do not PM me with thread based messages.  If your thoughts are worth responding,  the group should benefit from your insight.

RudiAhlers

Does your relay have an extra (unused) set of contacts?

If so you can make the function you want with a single transistor (or Mosfet), using the extra contacts to continue the circuit once the arduino boots up.


Is there a reason you don't want to just use a single transistor controlled from the arduino to enable the relay?


1. I am using an ESP8266 with limited pins
2. I burnt out 12 relays the other day, while reloading the sketch, and all the batteries to be monitored were still plugged in.

Oh, and I don't want to use any of the relays which are used to monitor the batteries, to control the circuit.

hammy

#5
Sep 21, 2018, 08:58 pm Last Edit: Sep 21, 2018, 09:01 pm by hammy
Whatever means you choose...You shouldn't be burning out relays - you need fuse protection and the relays arranging so that they can't short out however it starts in case of problems/fault with the Arduino.

When measuring voltage , you can add series resistors to limit fault current without creating significant measurement error - 100ohms?



RudiAhlers

Whatever means you choose...You shouldn't be burning out relays - you need fuse protection and the relays arranging so that they can't short out however it starts in case of problems/fault with the Arduino.

When measuring voltage , you can add series resistors to limit fault current without creating significant measurement error - 100ohms?



I have fuses in place, but the relays I chose to use are small and only allow a single battery's volt at a time. So when the ESP8266 starts up all the relays engaged together causing more volts to flow through the circuit than it should have. I don't want to use big noisy relays, and these smaller ones work fine if used in sequence as they should. But when the power cycled the ESP8266 it caused a problem.

So, by purposefully having to re-enable the power to the relays I have some control over it.

WattsThat

Classic x-y problem

Fixing the root cause is the best solution. Relays that turn on at power up or program loading is a driver circuit issue and/or faulty logic in your sketch. Since you've posted neither of these, there is little actual help that can be provided.
Vacuum tube guy in a solid state world

outsider

Can't you sequence the relays in setup() so they don't all come on at the same time? Are the relays energized on a LOW output or HIGH? Can you post a wiring diagram?

outsider

According to the datasheet, those relays require 5 volts and about 28 mA coil current, how are you driving them with a ESP8266?

RudiAhlers

Classic x-y problem

Fixing the root cause is the best solution. Relays that turn on at power up or program loading is a driver circuit issue and/or faulty logic in your sketch. Since you've posted neither of these, there is little actual help that can be provided.
I suspect the problem lies with the fact that I use an ESP8266 with limited pins. The 16 channel mux is driven by GPIO5, GPIO4, GPIO0, GPIO2 in sequence, and GPIO0 is TX as well, so during loading the new firmware it activates the MUX channels, which then activates the relays.
Since I'm still testing on a veroboard, I want to power off the relays manually while experimenting with the sketch workings.


I don't want to take out the ESP8266 every time as it's now nicely seated inside a secure box, with a hole for the USB cable.

RudiAhlers

Can't you sequence the relays in setup() so they don't all come on at the same time? Are the relays energized on a LOW output or HIGH? Can you post a wiring diagram?
Under normal running conditions, they don't all come on at the same time. It only happens / happened when I loaded a new sketch to the ESP8266.

I use a BC327 to energize the relays. Here's a simply breadboard example, which was then built on a veroboard with 16 relays.



It is based on a BC327 relay circuit I found online: https://www.electronics-tutorials.ws/articles/switch6.gif

RudiAhlers

According to the datasheet, those relays require 5 volts and about 28 mA coil current, how are you driving them with a ESP8266?
I use BC327 PNP transistors to drive them.

RudiAhlers

Classic x-y problem

Fixing the root cause is the best solution. Relays that turn on at power up or program loading is a driver circuit issue and/or faulty logic in your sketch. Since you've posted neither of these, there is little actual help that can be provided.
How would you fix this in this code:


Code: [Select]


/*
   V0.1 Works fine on Arduino Leonardo
  0 - ~1000volt voltmeter for 3.3volt Arduinos
  uses the stable internal 1.1volt reference
  6k8 resistor from A0 to ground, and 100k resistor from A0 to +batt
  100n capacitor from A0 to ground for stable readings
  (329000 + 998) / 998 = 330.6593186372745

*/

#include <stdio.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

const char* host = "192.168.10.30";
const char* apikey = "6e8465ac8dc473f4d3555e95e7eb87bf";


ESP8266WiFiMulti WiFiMulti;

#include <MCP3208.h>
#include <SPI.h>
MCP3208 adc(15);

//http://192.168.10.30/emoncms/input/post?json={temp:21,light:300}&apikey=<apikey>

float voltage = 0.000;            // calculated voltage
float R1 = 330000;
float R2 = 1000;
float divider = 331; // 299.7012987;
float  Vref = 4.155; // Using LM4040 reference voltage
unsigned int total; // can hold max 64 readings


int s0 = 5;
int s1 = 4;
int s2 = 0;
int s3 = 2;
int LED = D0;


void setup() {
  Serial.begin(115200);
  Serial.println("Voltage monitor");
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(LED, OUTPUT);
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

 
 
  delay(10);
  Serial.println("Voltage monitor: MCP3208VoltMeter V1.3 using MCP3408 and saving to Emoncms");
  Serial.println("Waiting for WiFi... ");

  WiFi.mode(WIFI_STA); // We start by connecting to a WiFi network
  WiFiMulti.addAP("xxxxxxx", "xxxxxxx");

  while (WiFiMulti.run() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  delay(500);

  adc.begin();


}

void loop() {
  // MUX Connection
  for (int i = 1; i < 17; i ++) {

    //MCP3208 Code
    // take a number of analog samples and add them up
    for (int x = 0; x < 64; x++) { // multiple analogue readings for averaging
      total = total + adc.analogRead(0); // add each value to a total
    }
    voltage = (total / 64.0) * divider * Vref / 4095 ; // convert readings to volt

    //    Serial.println(adc.analogRead(0));
    Serial.print("Battery ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(voltage);

    Serial.print(readMux(i));
    Serial.println("V"); 
    //    Serial.println();

    total = 0; // reset value
    delay(500); // half second between measurements

    // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");
      return;
    }

    char Volt[15];
    dtostrf(voltage, 4, 2, Volt);  //float to char  4 numero de caracteres  3 cifras sin espacio
    String Voltage = Volt;  // char to string

    char Number[15];
    dtostrf(i, 1, 0, Number);  //float to char  4 numero de caracteres  3 cifras sin espacio
    String No = Number;  // char to string

    char url [ 140]; //
    sprintf(url, "/emoncms/input/post.json?node=1&json={B%s:%s}&apikey=%s", Number, Volt, apikey) ;

    Serial.print("Requesting URL: ");
//    Serial.println(url);

    // This will send the request to the server
//    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
//                 "Host: " + host + "\r\n" +
//                 "Connection: close\r\n\r\n");
//    delay(500);

    // Read all the lines of the reply from server and print them to Serial
    while (client.available()) {
      String line = client.readStringUntil('\r');
      Serial.println(line);
      digitalWrite(LED, HIGH);
      Serial.println("Disabling Relays");
      digitalWrite(s0, LOW);
      digitalWrite(s1, LOW);
      digitalWrite(s2, LOW);
      digitalWrite(s3, LOW);
      delay(1000);
      digitalWrite(LED, LOW);
    }
  }

}




int readMux(int channel) {
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4] = {
    {0, 0, 0, 0}, //channel 0
    {1, 0, 0, 0}, //channel 1
    {0, 1, 0, 0}, //channel 2
    {1, 1, 0, 0}, //channel 3
    {0, 0, 1, 0}, //channel 4
    {1, 0, 1, 0}, //channel 5
    {0, 1, 1, 0}, //channel 6
    {1, 1, 1, 0}, //channel 7
    {0, 0, 0, 1}, //channel 8
    {1, 0, 0, 1}, //channel 9
    {0, 1, 0, 1}, //channel 10
    {1, 1, 0, 1}, //channel 11
    {0, 0, 1, 1}, //channel 12
    {1, 0, 1, 1}, //channel 13
    {0, 1, 1, 1}, //channel 14
    {1, 1, 1, 1} //channel 15
  };

  for (int i = 0; i < 4; i ++) {
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  int val = analogRead(voltage);

  return val;
}


WattsThat

Quote
How would you fix this in this code
I would start by looking at your schematic but you haven't posted it. No idea how you're multiplexing your relays.

Since D0 must be low during flash updating, does your hardware account for this condition?

Please post your schematic.

Vacuum tube guy in a solid state world

Go Up