Notifications
Clear all

Control Relays With phone, Via SMS from anywhere-home automation

15 Posts
4 Users
1 Likes
748 Views
(@kaleb)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

Hi. I live in Manitoba, Canada. I would like to be able to control some relays with my phone, from anywhere where I have cell service. No internet involved, simply text messages via 4g network. I found a video on YouTube that seemed to fit the bill. it turns out it won't work because it does not support the 4g network here in Canada.

Here is a link to the YouTube video.

the only difference I want to see, is the same idea, simply working on the bell 4g network in Canada.


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

@kaleb What makes you think it won't work? Canadians on Bell travel to the US all the time, and Americans travel to Canada and get connected to the Bell network as well. I don't get it.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@hilldweller)
Member
Joined: 1 year ago
Posts: 111
 

For what it is worth, I bought a SIM800 here in the UK, on cost grounds, only to find it did not work. Exchange if for a SIM900 and it's perfect. A quick look at this old code reminds me of a real problem, the SIM900 is slow to reset and the UNO would send commands before it was ready. An output form the UNO to control the SIM900 reset cured this.

 

The first one was a house temperature monitor for when we were away in the winter, I could get the temperatures all over Europe.

I also have one on the burglar alarm which sends a message if the alarm is triggered, then I can get my daughter to have a quick look.

 

The important bits, nothing elegant but it's been running 5 years ....

void intosmsbuffer() // grab serial
{
if ( !Serial.available() ) return; // no chars

inbyte = Serial.read();
if ( inbyte < 0x30 ) return; // filter out CR,LF etc

smsbuffer[0] = smsbuffer[1]; // keep adding to end of array
smsbuffer[1] = smsbuffer[2];
smsbuffer[2] = smsbuffer[3];
smsbuffer[3] = smsbuffer[4];
smsbuffer[4] = inbyte;

if ( smsbuffer[3] == 'O' && smsbuffer[4] == 'K' ) // look for OK for SIM900 test
{
// smsbuffer[3] = 0; smsbuffer[4] = 0; // stop repeats
OKhere = true; // got an OK
}
}

byte parseBuffer()
{
command = 0;

if ( smsbuffer[0] == 'B' && smsbuffer[1] == 'l' && smsbuffer[2] == 'h' )
{
if ( smsbuffer[3] == 's' && smsbuffer[4] == 't' ) command = 1; // send status
if ( smsbuffer[3] == 'd' && smsbuffer[4] == 'i' ) command = 2; // send status
}

if ( command > 0 )
{
smsbuffer[0] = 0; // clear, now command established
smsbuffer[1] = 0;
smsbuffer[2] = 0;
smsbuffer[3] = 0;
smsbuffer[4] = 0;
}

return command;
}

void initText() // show UNO has reset
{
Serial.println("AT + CMGS = \"" + destinationNumberBrian + "\"");
delay(1000);
Serial.print("Alarm communicator initialised.");
Serial.write((char)26); // ctrl+z
delay(5000);

Serial.println("AT+CMGD=1,4"); // delete all SMS, returns OK
}

void reportIntruder()
{
Serial.println("AT + CMGS = \"" + destinationNumberBrian + "\"");
delay(1000);
Serial.print("Alarm Intruder");
Serial.write((char)26); // ctrl+z
delay(5000);

Serial.println("AT+CMGD=1,4"); // delete all SMS, returns OK

reported = true; // one off 'till reset by status request
}

void sendStatus()
{
Serial.println("AT + CMGS = \"" + destinationNumberBrian + "\"");
delay(1000);
Serial.print("Stat:");

if ( digitalRead( intruderPin ) == LOW ) Serial.print("Intruder ");
else Serial.print("Sys Clear ");

if ( reported ) Serial.print("Reported ");
else Serial.print("Not Reported ");

if ( digitalRead( setPin ) == LOW ) Serial.print("A.Set ");
else Serial.print("A.UnSet ");

Serial.write((char)26); // ctrl+z
delay(5000);

}
Serial.println("AT+CMGD=1,4"); // delete all SMS, returns OK
reported = false; // clear report lockout

delay(5000); // time to read STR
lcd.setCursor(13,1);
// 0123456789012345
lcd.print(" ");
}

void StartSIM900() // if Arduino resets we do no know what state SIM is in
{ // hitting start pin turns on AND off
unsigned long tms; // AT will return an OK if SIM is on

OKhere = false;

for (;; ) // wait OK recieved for 2 secs
{
intosmsbuffer(); // hunt for OK
if ( OKhere )
{
lcd.print("ok"); return;
}

if ( millis() > tms ) break; // give up after 2 secs
}

lcd.print("AT Failed");

// did not get OK so pulse starter

digitalWrite( startPin, HIGH ); // here with no OK, so pulse start
delay( 2000 );
digitalWrite( startPin, LOW );
lcd.setCursor(0,1);
lcd.print("Start pulsed");
delay( 10000 ); // SIM900 should now be active, long pause to connect
}

void setup()
{
WiFi.disconnect();

if (esp_now_init() == 0)
{
Serial.println("init");
}
else
{
Serial.println("init failed");
ESP.restart();
return;
}

Serial.begin(19200); // for SIM900

StartSIM900();

}

uint8_t message[16];
String temperature;
uint8_t t_len, x;

void loop()
{
lcd.clear(); lcd.print("Monitor.");
ticks = millis() + 10000; // ten seconds

for(;;)
{

tCnt++; if ( tCnt > 3 ) tCnt = 0;
}

intosmsbuffer(); // look for SMS, chart by char
parseBuffer();
if ( command == 1 )
{
sendStatus(); command = 0;
}

iPin = digitalRead( intruderPin );

if ( iPin == LOW ) intrCnt++; // intruder counter
else intrCnt = 0;

if ( intrCnt > 100 ) intrCnt = 100;

if ( intrCnt > 90 ) // anti glitch
{
if ( !reported ) reportIntruder();
}

if ( iPin != lastIpin ) // intruder has changed, display it
{
lcd.setCursor(6,1);

if ( iPin == LOW )
{
lcd.print("INTR");
} // 0123456789012345
else
{
lcd.print("Clr ");
}

lastIpin = iPin;
}

sPin = digitalRead( setPin );
if ( sPin != lastSpin ) // set has changed
{
lcd.setCursor(0,1);

if ( sPin == LOW )
{
lcd.print("SET ");
} // 01234567890123456
else
{
lcd.print("UNset");
}

lastSpin = sPin;
}
}
}

 

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

Posted by: @kaleb

Hi. I live in Manitoba, Canada. I would like to be able to control some relays with my phone, from anywhere where I have cell service. No internet involved, simply text messages via 4g network. I found a video on YouTube that seemed to fit the bill. it turns out it won't work because it does not support the 4g network here in Canada.

Here is a link to the YouTube video.

the only difference I want to see, is the same idea, simply working on the bell 4g network in Canada.

Just buy a Bell SIM.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@kaleb)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

@zander you see i did try it but this fellow is from a country where 2g networks are still up and running. i need something that will work on the 4g network such as the sim7600. but the sims7600 is to expensive. or not? Waveshare 4G/3G/2G/GSM/GPRS/GNSS HAT for Raspberry Pi Based on SIM7600G-H Supports LTE CAT4 up to 150Mbps for Downlink Data Transfer : Amazon.ca: Electronics


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1689
 

Hi @kaleb,

  I have no experience in this area ... so this is only an observation, NOT a recommendation!

  Quick search for '4G module Arduino' at AliExpress produced a number of 'hits' at modest prices ... e.g.

https://www.aliexpress.com/item/1005004176439432.html

(NB there are many links to variants etc. on that page ... not just the 'main' item. I have no idea what the differences are, etc.)

Of course, this is a much greater leap into the dark than a 'proven' package something by (say) Adafruit, and you are probably on your own for figuring out how to make it work and fixing problems. It might be totally unsuitable or total junk.

Also, remember, cell phone technology includes radio transmissions and interaction with public networks, so you are responsible for complying with relevant laws, etc. in your country.

It is only a suggestion for you to look into.

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

@kaleb I thought you said it was 4G but 4G didn't work in Canada. Not true.

Just ask yourself a question, do people from Canada and the USA freely travel across the border and their phone continues to work? YES, OF COURSE.

Just go to the local store, or online and order a SIM. 

You are making this more complicated than it is.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1689
 

Hi Ron @zander,

  @kaleb's introductory question can have more than one interpretation ...

   I think @kaleb was saying he started with a Sim800 style module ... and that doesn't work on 4G in Canada ... or on 4G anywhere else for that matter  ... because it is a 2G module ....

Hence the search for a 4G module that doesn't break the bank.

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

@davee @kaleb Well at least that would make some sense. Now to address the other elephant, he is talking Raspberry Pi and the video is Arduino UNO. Pick one.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

@kaleb Ok, I think I understand you now. If the benefit exceeds the cost it doesn't matter what it costs. One thing that would be smart though is to get a 5G device, that way when 6G starts rolling out and 4G is on it's last legs you aren't faced with a costly upgrade.

Even if you spend $400 for a 5G, assuming a 5 year life means it costs $80 a year or $6.67 per month, roughly $0.22 per day. As I understand it you can't even get a coffee for that now (I don't order food out very often)

If you can afford the Pi, you can afford the phone card. Save some money and use an arduino or esp32, then the total cost is less than the Pi 4.

I can't recommend a module since my search for 5G returns WiFi as well as phone(maybe) devices.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

@kaleb Here is a Pi PICO board that has support for both 2G and 4G. The company is Waveshare, they make great stuff, this board is part of a family of boards that mount on top of each other. Very inexpensive also. If you geta PICOW you can have WiFi access also.

https://amz.run/6MrK

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@kaleb)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

@zander i went ahead and got myself a waveshare 4g hat from ebay.  sim7600X 4G HAT. it was preowned. its working fine connected to bell 4g lte.(saw your post about the picow a bit too late but thanks anyway. now i will know in the future. LOL) basically this device but i got the older version of it. SIM7600G-H 4G HAT For Raspberry Pi, LTE Cat-4 4G / 3G / 2G Support, GNSS Positioning, Global Band (waveshare.com)

so to be clear, my goal is to have this thing talking with an arduino uno. when the arduino uno recieves a specific sms message i want it to turn on a relay. or a led for simpflication. i am not good at coding when i bulid something i will take someone else's code and modify it till it does what i need it to do. so now im loooking for some code and a schematic to build from.

this video is pretty close to what i thought i needed. he has the exact same 4ghat but its not working out im thinking the pins on the maker uno are slightly different than arduino uno? no? it does says arduino uno is compatible in the description but idk


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

@kaleb It's hard to see, but what I can see is identical to UNO. An easy way to find out is to email Cytron if you can't find the datasheet for the board. I can't help beyond that since you have not posted any details or pictures etc.

BTW, if I understand what you are trying to do, it can be easily done with off the shelf smart plugs. If you have cell service then you have internet service via cellular data. I often adjust my furnace, turn on or off lights when I am away and have no WiFi, my phone is simply set to cellular data and the apps used to control the furnace or lights are configured to use cellular data.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@kaleb)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

@zander

ard sms

  i got it figured out found some code online. so far, I'm pretty happy with the reliability it's got. I got my prototype attached. yeah i know about the smart plugs. in this case the SMS  is cheaper. theres no internet at the remote location. cellular internet is very expansive here.

 

#include<softwareSerail.h> //software serial library for serial communication between Arduino & sim900 GSM

SoftwareSerial mySerial(8, 9);//connect Tx pin of GSM to pin 8 of Arduino && Rx pin of GSM to pin no 9

int REY = 6; // relay output

String message;

String lampState = "HIGH";// Create a variable to store Lamp state

void setup() {

mySerial.begin(9600); // Setting the baud rate of GSM Module

delay(20000);

mySerial.println("AT+CMGF=1"); // set text mode

delay(1000);

mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS

pinMode(REY, OUTPUT);

digitalWrite(REY, LOW);

delay(100);

}

void loop() {

if (mySerial.available() > 0) {

message = mySerial.readString(); }

if (message.indexOf("ON") > -1) {

digitalWrite(REY, HIGH);

lampState = "on"; }

if (message.indexOf("OFF") > -1) {

digitalWrite(REY, LOW);

lampState = "off"; }

if (message.indexOf("STATE") > -1) {

mySerial.println("AT+CMGS=\"+9XXXXXXXXX\"\r"); // replace XXX.. with your number with country code delay(1000);

mySerial.println("Relay is "+ lampState);// Message content

delay(1000);

mySerial.println((char)26);// ASCII code of CTRL+Z

delay(100); }

}


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6981
 

@kaleb Glad to hear you got it working. I am curious how much data that setup would use in a month, I live in Canada too and know about our high cellular data plans, but are they not priced as a few dollars per megabyte? It looks like you only send a few bytes, puzzled am I unless you just wanted a challenge.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote