Arduino Smartthing help


#1

I’m trying to send data from 4 sensros, 2 temperature and 2 pressure, using an ARDUINO w/smarthings shield. I know this hardware is no longer supported by Smartthings.,

I just need to display the 2 temperatures and 2 pressures on a smartphone. I need both an Arduino application program and a Deice Handler. I’m very familiar with Arduino coding, but not how to communicate to the Smartthings HUB.

I was able to connect the Smartthngs shield to my hub, and turn the LED on/off on the shield using the switch device handler.

Any help with this would be much appreciated.


#2

This should help (this is a clickable link),

Also, you can check the quick browse lists in the community – created wiki and look under either sensor projects or miscellaneous device type handlers for more Arduino discussion threads.

http://thingsthataresmart.wiki/index.php?title=How_to_Quick_Browse_the_Community-Created_SmartApps_Forum_Section


(Dan) #3

My ST_Anything library and associated DTH’s are exactly what you’re looking for. You’ll be up in and running in no time at all.

Not sure what pressure sensors you’re planning on using. If you let me know, I can explain the best method of adding them.


#4

Dan,
Sorry I didn’t get back to you sooner.

I’ve completed the Arduino coding for a POOL PUMP Controller. My son has upgraded to a pump with several presets. I’ve enclosed the .ino. As you can see from the code it’s pretty basic, 4 relays to control the pump (2) and valves (2).
We are monitoring 2 temps and 2 pressures, which we’d like ti display on Smartthings APP (iPhone).
So:1. What should I add to FPH_controller.ino to send temp amd pressure data to the device handler ?
2. What should the device handler look like on the smartthings side ?
Regards,BRIAN

ogiewon Dan Community Master
February 19 |

My ST_Anything library and associated DTH’s are exactly what you’re looking for. You’ll be up in and running in no time at all.Not sure what pressure sensors you’re planning on using. If you let me know, I can explain the best method of adding them. Visit Topic or reply to this email to respond. To unsubscribe from these emails, click here.


(Dan) #5

First, I don’t see your Arduino Sketch in your post.

Second, the ST_Anything model assumes you start with one of the ST_Anything example sketches to kickstart your project. From there, you modify the example to make it uniquely fit your application. You don’t mention the types of sensors you’ve attached to the Arduino. ST_Anything supports many devices, but not everything. So, for example, if you chose temperature sensors that are not supported by ST_Anything, you’ll have some additional work ahead.

Another possibility is for you to simply ADD SmartThings ThingShield support to your existing sketch. To do so, you would probably want to start with one of my “SmartThings” library’s example sketches. Once you understand how that works, you could modify your sketch.

On the ST Groovy DTH side of things, you can either reuse my DTH code, or roll your own. ST_Anything is designed to be used with my DTH’s, as it fully automates the creation of Child Devices, one for each device you attach to the Arduino. If you choose to not use ST_Anything, but instead just use the “SmartThings” communications library, you can still use my DTH’s, but you’ll need to make sure you follow my standard ‘name value’ convention for sending data to ST. That naming convention is used to automatically create and manage Child Devices.

Until I see your sketch, it is very hard for me to suggest a path forward.


#6

Dan,
Not sure what happened there. I checked my sent folder and it was there. I’ll include again, this time as .rtf.
I really appreciate any help you can give me. I’m not a programmer by profession, but do understand the basics, so go easy on me.
I have tried to get your ST_Anythnig to work, but no luck…I’m sure it’s pilot error. Will have another go.
Best Wishes…Brian

ogiewon Dan Community Master
March 12 |

First, I don’t see your Arduino Sketch in your post.Second, the ST_Anything model assumes you start with one of the ST_Anything example sketches to kickstart your project. From there, you modify the example to make it uniquely fit your application. You don’t mention the types of sensors you’ve attached to the Arduino. ST_Anything supports many devices, but not everything. So, for example, if you chose temperature sensors that are not supported by ST_Anything, you’ll have some additional work ahead.Another possibility is for you to simply ADD SmartThings ThingShield support to your existing sketch. To do so, you would probably want to start with one of my “SmartThings” library’s example sketches. Once you understand how that works, you could modify your sketch.On the ST Groovy DTH side of things, you can either reuse my DTH code, or roll your own. ST_Anything is designed to be used with my DTH’s, as it fully automates the creation of Child Devices, one for each device you attach to the Arduino. If you choose to not use ST_Anything, but instead just use the “SmartThings” communications library, you can still use my DTH’s, but you’ll need to make sure you follow my standard ‘name value’ convention for sending data to ST. That naming convention is used to automatically create and manage Child Devices.Until I see your sketch, it is very hard for me to suggest a path forward. Visit Topic or reply to this email to respond.
In Reply To

535Glenburry
March 12 |

Dan, Sorry I didn’t get back to you sooner. I’ve completed the Arduino coding for a POOL PUMP Controller. My son has upgraded to a pump with several presets. I’ve enclosed the .ino. As you can see from the code it’s pretty basic, 4 relays to control the pump (2) and valves (2). We are monitorin… Visit Topic or reply to this email to respond. To unsubscribe from these emails, click here.


(Dan) #7

Brian,

If you’re trying to email me the code, it will not work as you are actually posting to the SmartThings forum in a private message to me.

Copy and paste your Arduino code into the forum’s Private Message system, as a reply to this message.

PLEASE be sure to highlight/select all of your Arduino code after you paste it into the forum editor, and then click the Preformatted Text menu button that looks like < / > so that the code is readable.


#8

Dan,

Hope this works…

Regards,
BRIAN

/* Program Name: FPH_controller (Free Pool Heater)

  • Rev 0.0
  • Use: Controls pool related hardware
  • Date: 11-Mar-2018
  • Developers: Rob and Dad
  • Time-of Day SEQUENCER. Supports the following MODES
  •    MODE=VACUUM (1)
    
  •      TIME: 00:00:00 to 01:59:59
    
  •      PUMP at Speed-1 (RELAY_1)
    
  •      VACUUM Valve OPEN (RELAY_3)
    
  •    MODE=SKIM (2)
    
  •      TIME: 00:02:00 to 03:59:59
    
  •      PUMP at Speed-2 (RELAY_2)
    
  •      SKIMMER Valve OPEN (RELAY_4)
    
  •    MODE=FILTER (3)
    
  •      TIME: 00:04:00 to 11:59:59
    
  •      PUMP at Speed-1 (RELAY_1)
    
  •      VACUUM and SKIMMER Valves CLOSED
    
  •    MODE=IDLE (4)
    
  •      TIME: 12:00:00 to 23:59:59
    
  •      PUMP OFF
    
  •      VACUUM and SKIMMER Valves CLOSED
    
  • Hardware:
  •  Arduino Uno
    
  •  Smartthings Shield
    
  •  Relay Shield (4 x 3A slave relays)
    
  •  4 x 24V slave relays
    
  •  5V power supply
    
  •  24V transformer
    
  •  2 x DS18S20 thermometers (-50C to 125C)
    
  •  2 x Pressure/Vacuum transducers (+30 to -14.5 PSI)
    

*/

// Inluide LIBRARIES. Note DallasTemperature library, for DS18S20 thermometers, includes oneWire
#include <DallasTemperature.h>
#include <Wire.h>
#include <SD.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

// Use I/O pin 10 for temp sensor pull-up, 10Kohm
#define ONE_WIRE_BUS 10
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
RTC_DS1307 RTC;

// set to ‘true’ to get debug info in serial monitor
boolean debug = true;

boolean toggle = false;

// set MODE depending on time. PreviousMode stores MODE for previous pass through the main loop
int mode = 0;
int previousMode = 0;

// define digital pins on UNO controlling the 5V slave relays on RELAY SHIELD
int RELAY_1 = 7; // PUMP Speed-1
int RELAY_2 = 6; // PUMP Speed-2
int RELAY_3 = 5; // VALVE-1 (VACUUM)
int RELAY_4 = 4; // VALVE-2 (SKIMMER)

// pressure sensor parameters, offset and calibration
int i;
int sensorValue0, sensorValue1 = 0;
int min_sensorValue0, min_sensorValue1 = 999;
int max_sensorValue0, max_sensorValue1 = -999;
float total_sensorValue0, total_sensorValue1 = 0;
float average_sensorValue0, average_sensorValue1;
float pressure0, pressure1;
float ADC_offset0 = 377; // ADC reading for 0.0PSI
float ADC_calibration0 = 0.0543; // PSI per ADC step;
float ADC_offset1 = 377; // ADC reading for 0.0PSI
float ADC_calibration1 = 0.0543; // PSI per ADC step;

// temperature sensor parameters
float temperature0, temperature1;

// ---------- setup ----------
void setup(void) {
Serial.begin(9600);
sensors.begin();
Wire.begin();
RTC.begin();
lcd.init(); lcd.init(); // initialize LCD (not sure whyt we need to do twice)

// check to see if RTC is running
if (!RTC.isrunning()) {
Serial.println(“RTC is NOT running”);
}
// set RTC from LAPTOP
//RTC.adjust (DateTime(DATE, TIME));
if (debug == true) {
Serial.print("INITIALIZING RTC @ ");
PrintDateTime();
}

// initialize the digital pins controlling the SLAVE RELAYS as outputs
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
pinMode(RELAY_3, OUTPUT);
pinMode(RELAY_4, OUTPUT);

// turn all realys off
digitalWrite(RELAY_1, LOW); // turn RELAY-1 OFF
digitalWrite(RELAY_2, LOW); // turn RELAY-2 OFF
digitalWrite(RELAY_3, LOW); // turn RELAY-3 OFF
digitalWrite(RELAY_4, LOW); // turn RELAY-4 OFF

// update display template
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“FPH Controller”);
lcd.setCursor(0,1);
lcd.print(“Mode=”);
lcd.setCursor(9,1);
lcd.print(“Time=”);
lcd.setCursor(16,1);
lcd.print(":");
lcd.setCursor(0,2);
lcd.print(“P0/P1:”);
lcd.setCursor(0,3);
lcd.print(“T0/T1:”);

lcd.setCursor(7,2);
lcd.print(pressure0,1);
lcd.setCursor(14,2);
lcd.print(pressure1,1);
lcd.setCursor(7,3);
lcd.print(temperature0,1);
lcd.setCursor(14,3);
lcd.print(temperature1,1);
}

// ---------- main program loop ----------
void loop(void) {
// check time to see which MODE we are int
DateTime now = RTC.now();

// set mode to suit time
if (now.hour() < 2) mode = 1;
if (now.hour() < 4 && now.hour() >= 2) mode = 2;
if (now.hour() < 12 && now.hour() >= 4) mode = 3;
if (now.hour() > 12) mode = 4;

if (debug == true) {
PrintDateTime();
Serial.print("CURRENT MODE = “);
Serial.print(mode);
Serial.print(”, PREVIOUS MODE = ");
Serial.println(previousMode);
}

// collect data from pressure sensors
total_sensorValue0 = 0;
total_sensorValue1 = 0;
// read the input on analog pin A1 10 times:
for (i = 0; i < 10; i++) {
sensorValue0 = analogRead(A0);
sensorValue1 = analogRead(A1);
if (sensorValue0 > max_sensorValue0) max_sensorValue0 = sensorValue0;
if (sensorValue0 < min_sensorValue0) min_sensorValue0 = sensorValue0;
if (sensorValue1 > max_sensorValue1) max_sensorValue1 = sensorValue1;
if (sensorValue1 < min_sensorValue1) min_sensorValue1 = sensorValue1;
total_sensorValue0 = total_sensorValue0 + sensorValue0;
total_sensorValue1 = total_sensorValue1 + sensorValue1;
delay(100);
}
average_sensorValue0 = total_sensorValue0/10;
average_sensorValue1 = total_sensorValue1/10;
if (debug == true) {
Serial.println(total_sensorValue0);
Serial.println(average_sensorValue0);
}
// convert ADC value to PSI
pressure0 = (average_sensorValue0 - ADC_offset0)* ADC_calibration0;
pressure1 = (average_sensorValue1 - ADC_offset1)* ADC_calibration1;
Serial.print("Pressure0 = ");
Serial.print(pressure0,1);
Serial.println(“PSI”);

// issue a global temperature request to all devices on the bus
sensors.requestTemperatures();
temperature0 = sensors.getTempFByIndex(0);
temperature1 = sensors.getTempFByIndex(1);

if (mode = 1) { // VACUUM
digitalWrite(RELAY_1, HIGH); // turn RELAY-1 on
digitalWrite(RELAY_2, LOW); // turn RELAY-2 off
digitalWrite(RELAY_3, HIGH); // turn RELAY-3 on
digitalWrite(RELAY_4, LOW); // turn RELAY-4 off
}
if (mode = 2) { // SKIM
digitalWrite(RELAY_1, LOW); // turn RELAY-1 off
digitalWrite(RELAY_2, HIGH); // turn RELAY-2 on
digitalWrite(RELAY_3, LOW); // turn RELAY-3 off
digitalWrite(RELAY_4, HIGH); // turn RELAY-4 on
}
if (mode = 3) { // FILTER
digitalWrite(RELAY_1, HIGH); // turn RELAY-1 on
digitalWrite(RELAY_2, LOW); // turn RELAY-2 off
digitalWrite(RELAY_3, LOW); // turn RELAY-3 off
digitalWrite(RELAY_4, LOW); // turn RELAY-4 off
}
if (mode = 4) { // IDLE
digitalWrite(RELAY_1, LOW); // turn RELAY-1 off
digitalWrite(RELAY_2, LOW); // turn RELAY-2 off
digitalWrite(RELAY_3, LOW); // turn RELAY-3 off
digitalWrite(RELAY_4, LOW); // turn RELAY-4 off
}

// update active part of display
lcd.setCursor(18,0);
if (toggle == true) {
lcd.print(" “);
}
else lcd.print(”
");
toggle = !toggle;

lcd.setCursor(5,1);
lcd.print(mode);
if (now.hour() <10) {
lcd.setCursor(14,1);
lcd.print(“0”);
lcd.setCursor(15,1);
lcd.print(now.hour());
}
else {
lcd.setCursor(14,1);
lcd.print(now.hour());
}
if (now.minute() <10) {
lcd.setCursor(17,1);
lcd.print(“0”);
lcd.setCursor(18,1);
lcd.print(now.minute());
}
else {
lcd.setCursor(17,1);
lcd.print(now.minute());
}
lcd.setCursor(7,2);
lcd.print(pressure0,1);
lcd.setCursor(14,2);
lcd.print(pressure1,1);
lcd.setCursor(7,3);
lcd.print(temperature0,1);
lcd.setCursor(14,3);
lcd.print(temperature1,1);

previousMode = mode;
}

// ---------- functions ----------
void PrintDateTime () {
// read date/time from RTC
DateTime now = RTC.now();
// write to serial monitor
Serial.print(“Time = “);
if (now.hour() < 10) {
Serial.print(“0”);
}
Serial.print(now.hour());
Serial.print(”:”);
if (now.minute() < 10) {
Serial.print(“0”);
}
Serial.print(now.minute());
Serial.print(":");
if (now.second() < 10) {
Serial.print(“0”);
}
Serial.print(now.second(),DEC);
Serial.print("\t");

Serial.print(“Date = “);
if (now.month() < 10) {
Serial.print(“0”);
}
Serial.print(now.month());
Serial.print(”/”);
if (now.day() < 10) {
Serial.print(“0”);
}
Serial.print(now.day());
Serial.print("/");
Serial.print(now.year(), DEC);
Serial.println("");
}