Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Two Wire Temperature Sensor Convert from older gateway NEED HELP

Two Wire Temperature Sensor Convert from older gateway NEED HELP

Scheduled Pinned Locked Moved My Project
3 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Newzwaver
    wrote on last edited by
    #1

    Hi Everyone,

    I am using this old sketch for a two wire temp probe and upgraded to the 2.1.1 gateway and can't figure out what to change to get it to work. Do anyone know of a basic guide? I can't find one.

    #include <MySensor.h>
    #include <SPI.h>

    #define THERMISTORPIN A0
    #define THERMISTORNOMINAL 10000
    #define TEMPERATURENOMINAL 25
    #define NUMSAMPLES 5
    #define BCOEFFICIENT 3950
    #define SERIESRESISTOR 10000

    const unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    MySensor gw;

    // Initialize temperature message
    MyMessage msg(0,V_TEMP);

    int samples[NUMSAMPLES];

    void setup(void) {

    pinMode(THERMISTORPIN, INPUT);
    analogReference(EXTERNAL);

    // Startup and initialize MySensors library. Set callback for incoming messages.
    gw.begin();

    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Temperature Sensor", "1.1");

    // Present all sensors to controller
    gw.present(0, S_TEMP);
    }

    void loop(void) {
    // Process incoming messages (like config from server)
    gw.process();

    float average;

    // take N samples in a row, with a slight delay
    for (uint8_t i=0; i< NUMSAMPLES; i++) {
    samples[i] = analogRead(THERMISTORPIN);
    delay(10);
    }
    // average all the samples out
    average = 0;
    for (uint8_t i=0; i< NUMSAMPLES; i++) {
    average += samples[i];
    }
    average /= NUMSAMPLES;

    Serial.print("Average analog reading ");
    Serial.println(average);

    // convert the value to resistance
    average = 1023 / average - 1;
    average = SERIESRESISTOR / average;
    Serial.print("Thermistor resistance ");
    Serial.println(average);

    float temperature;
    temperature = average / THERMISTORNOMINAL; // (R/Ro)
    temperature = log(temperature); // ln(R/Ro)
    temperature /= BCOEFFICIENT; // 1/B * ln(R/Ro)
    temperature += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
    temperature = 1.0 / temperature; // Invert
    temperature -= 258.95; // convert to C

    Serial.print("Temperature ");
    Serial.print(temperature);
    Serial.println(" *C");
    // Send in the new temperature
    gw.send(msg.setSensor(0).set(temperature,1));
    // delay(1000);
    gw.sleep(SLEEP_TIME);
    }

    1 Reply Last reply
    0
    • scalzS Offline
      scalzS Offline
      scalz
      Hardware Contributor
      wrote on last edited by scalz
      #2

      Hello,

      you need to convert your node to MySensors 2.x api. you can see how it looks in MySensors examples and there are also some guidelines here: https://forum.mysensors.org/topic/4276/converting-a-sketch-from-1-5-x-to-2-0-x

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Newzwaver
        wrote on last edited by
        #3

        Hi

        Thank you for the prompt reply, I will have a look.

        Thanks
        T

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        16

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular