How can I detect an 5v signal?

I’m hacking a kettle. There is a wire at 5v that indicates if the kettle is on. How can I detect this?

This is the kettle. I have spliced in wires to interface with the controls in two ways.

The kettle has 4 momentary buttons. The on/off button lights up when the kettle is on.

As you can see I’m wired right into the buttons. The relay shield lets me close, then open these circuits to simulate button presses. This works OK. But, I need to know if the kettle is on, and how warm the water is. I need the relay because the board is 5v. It seems like overkill. But it works…

So I connected to the 5v level input/output I’ve done some tests and the red wire is at 5v when the kettle is on and 0v when it is off… How do I get this information into the core?

I have lots of free pins, but I just don’t know how to set it up. The orange wire seems to be the temp… It’s from 0-5v depending on the kettle. How can I get this info?

I tried making a divider, but the output in analog is just random.

Help?

 #include "HttpClient/HttpClient.h"
 HttpClient http;

 http_request_t request;
 http_response_t response;

 http_header_t headers[] = {
     { "Content-Type", "application/json" },
     { "X-Auth-Token" , TOKEN },
     { NULL, NULL } // NOTE: Always terminate headers with NULL
 };

 String search_on = String("\"value\": 1");//To check if a switch is pressed or not


 // These are variables for Ubidots.com
 #define on_SWITCH "UBIDOTS_VARIBLE_ID1"
 #define down_SWITCH "UBIDOTS_VARIBLE_ID2"
 #define up_SWITCH "UBIDOTS_VARIBLE_ID3"
 #define prog_SWITCH "UBIDOTS_VARIBLE_ID4"
 #define kettleTemp "UBIDOTS_VARIBLE_ID5"
 #define kettleIsOn "UBIDOTS_VARIBLE_ID6"
 #define TOKEN "UBIDOTS_TOKEN"


float temp = 0;
float tempScaled = 0;
char tempresultstr[64];

 // Variables to store virtual button presses
 int kettle_on;
 int kettle_down;
 int kettle_up;
 int kettle_prog;
 
 // Variable to detect if the kettle is currently on
 int kettle_is_on;
 char kettle_is_onresultstr[64];

// pin assignments for the relays
int RELAY1 = D0;
int RELAY2 = D1;
int RELAY3 = D2;
int RELAY4 = D3;


void setup()
{

   //Initilize the relay control pins as output
   pinMode(RELAY1, OUTPUT);
   pinMode(RELAY2, OUTPUT);
   pinMode(RELAY3, OUTPUT);
   pinMode(RELAY4, OUTPUT);

   // get ready to read the temp.
   pinMode(A7, INPUT);
   // get ready to read if the kettle is on or not
   pinMode(A6, INPUT);
   
   // Initialize all relays to an OFF state
   digitalWrite(RELAY1, LOW);
   digitalWrite(RELAY2, LOW);
   digitalWrite(RELAY3, LOW);
   digitalWrite(RELAY4, LOW);

   //register the Spark function
   Spark.function("relay", relayControl);      
   
request.hostname = "things.ubidots.com";
request.port = 80;

// Serial.begin(9600); For debug
 Serial.begin(9600);
  
    Spark.variable("kettle_is_on", &kettle_is_on, INT);
    Spark.variable("kettle_on", &kettle_on, INT);

}

void loop()
{
   // This loops for ever

 response.body = "";
 response.status = 0;
 request.path = "/api/v1.6/variables/"on_SWITCH"/values?page_size=1";
 http.get(request, response, headers);

 // check if the button is pressed on ubidots.com
 kettle_on = response.body.indexOf(search_on);

  //check if the 5v signal is there 
 kettle_is_on = digitalRead(A6);

 if (-1 < kettle_on) {
     //respond to virtural pressed button on ubidots    
     digitalWrite(RELAY1, HIGH);
     delay(300);
     digitalWrite(RELAY1, LOW);
 }

 

 if ( kettle_is_on ==1 ) {

    // Send to Ubidots
    request.path = "/api/v1.6/variables/"kettleIsOn"/values";
    sprintf(kettle_is_onresultstr, "{\"value\":%.4f}", 1);
    request.body = kettle_is_onresultstr;
    http.post(request, response, headers);
    Serial.println(response.status);
    Serial.println(response.body);

     
    temp = analogRead(A7);
    tempScaled = temp/20;
    // Send to Ubidots
    request.path = "/api/v1.6/variables/"kettleTemp"/values";
    sprintf(tempresultstr, "{\"value\":%.4f}", tempScaled);
    request.body = tempresultstr;
    http.post(request, response, headers);
    Serial.println(response.status);
    Serial.println(response.body);
 }


}

// command format r1,HIGH
int relayControl(String command)
{
  int relayState = 0;
  // parse the relay number
  int relayNumber = command.charAt(1) - '0';
  // do a sanity check
  if (relayNumber < 1 || relayNumber > 4) return -1;

  // find out the state of the relay
  if (command.substring(3,7) == "HIGH") relayState = 1;
  else if (command.substring(3,6) == "LOW") relayState = 0;
  else return -1;
 Serial.println("relay triggered");
  // write to the appropriate relay
  digitalWrite(relayNumber-1, relayState);
  return 1;
}

My main questions:

  • How can I detect a 5v signal as an (ideally) digital pininput?
  • Do I really need these big relays to simulate button presses? Could I use a transistor or mosfet?
  • Is there a better way to splice in? Look how ugly it is now.
1 Like

There are 5V tolerant inputs for digitalRead() and interrupt handling. So for the on/off info you actually could do it direct.

Depending on the proximity to any mains I would suggest to use an opto-coupler/opto-isolator to be on the save side.
As for your relays I would rather use transistors possibly also connected via optos.

What resistors have you used for your voltage devider?

Please tell me you’re implementing Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)

https://www.ietf.org/rfc/rfc2324.txt

1 Like

Two 470 ohm resistors … they should give an output of 2.5V… when I look at the analog output it’s numbers from 1000-4000… and not stable. If I look at digital it’s correct most of the time about when the kettle is on…but lots of errors.

An opto-coupler is a good idea! I made one with an led and a photo-resistor-- Maybe I should buy a real one? Are homade opto-couplers consistent?

Have you got a common ground between the two. And a small cap on the analog (or digital) input would be suggested also.

Are homade opto-couplers consistent? I would think they would be consistent if they are sealed from other light sources.Maybe not Nasa rated, but should work for less critical projects.

What is the large yellow block in your pictures? Can you draw out a wiring schematic for how you think the pot works on paper and send us a picture? If possible you might be able to simply replace the entire logic board and just make it Particle powered alone.

Depending on the available amps of that pin, you may be drawing to much current. The analog inputs of the core are about 40,000 ohms, and digital inputs a lot less. Maybe try two 10,000 ohm resisters ?

Reading voltage from a non trusted device, it may be a good idea to have a zener diode to help prevent over voltage also.

1 Like

Hi @futurebird

The big yellow thing @harrisonhjones identified is a high voltage capacitor which is probably used like a resistor to get the line voltage (220V?) down to something manageable.

This points out a another potential problem in that you are opening up what the manufacturer meant to be a sealed control. There may be high-voltages relative to earth or neutral on the wires you are bringing out to the Particle device and you should treat the entire circuit as having the potential to be at high voltage. Just be safe.

I’ve designed a circut that works the way that I want with batteries, I don’t know if it will work connected to the core.

NOTE: TLP621 is not the part number of my optocoupler. I’m using this one:
http://en.f-alpha.net/electronics/optoelectronics/optocoupler/get-started/different-optocoupler/

Pin Description
1 LED (Anode)
2 LED (Cathode)
3 Phototransistor (Emitter)
4 Phototransistor (Collector)

I have a wire with a 0-5v current. I want to detect if the current is there or not (HIGH/LOW.)

I’m using an optocoupler to avoid putting too much current into my micro, as it is only a 3.3V micro. I’m nervous about powering this on as one of my other micros stopped working although it’s not clear if it could have been the circuit?

The microcontroller is a spark/particle core 3.3v. It the yellow wire connects to the analog pin A6. The screw terminals connect to the wire with the 5v current that I’m trying to detect.

I based my circuit on this:

enter image description here

But I don’t know if it will do the same thing.