Relay control via SMS & Wifi

Hello,

I’m new to this world, I discovered Arduino while searching for a solution for my garden.

I need to control a valve via a relay so that I can turn my sprinklers on/off via SMS or Wifi.

What is the simplest solution between these two and how do these two work?

I’ve seen that it could be relatively easy with SMS. I don’t know about the wifi one but for both of them, I would like to make it secure so that nobody else can turn it on/off.

Turning it ON/OFF is the first step. Next, I would like to be able to turn the system on and off every hour for 12h once I’ve sent the SMS or the command via wifi. I know that it would require a bit of code but I don’t know if it’s possible?

What is the material required for each one ?

Thank you :slight_smile:

Looking for the most reliable solution could be one idea.
SMS calls for a phone card and prescription. If Your Wifi reaches the point where the device will stay, that costs less.

A least a relay module capable of the unknown valve current.
A Wifi equipped controller spare extra boards.

I would say an easy solution would be esp32 board. it has wifi and bluetooth and you can set it up to turn a relay on and off over the internet with your homes wifi and because of that should be secure "depending on your homes wifi and internet security. If you google and research the esp32 for this you will find that what you are trying to do has been done many times and there is plenty of information to get you started. Instructables.com is a good place to look also. Even if your not familiar with this type of stuff the information is out there and you will find it quite easy to get it done there are tons of tutorials. Hope this helps!

Hi, thank you for your answer ! Sorry for the delay of my response, I had really busy days !

I feel like it would be better for me the SMS system as I would have to activate the valves when I'm away from home. I don't know if it's as simple through wifi ? What it would require to do that with the wifi ?

I have found this on instructable : https://www.instructables.com/SMS-Controller-by-Using-SIM800L-V2/ which require only this components :

  1. SIM800L V2.0 GSM/GPRS Module
  2. Arduino Uno
  3. 4 Channel 5 Volt Relay Module
  4. Jumper Wire

It's dated 6 years ago, is there any upgrade on the hardware or new component since ?

It seems quite simple. I also need to control the valves which are 9V et 12v. What will be your advise to control these two ? I'll have a look on the forum in the meantime.

Thanks :slight_smile:

Thanks, the two relays are 9v and 12v but I would probably only keep the 9v.

I see that there is several options to do this system :

Or with the :
MKR GSM 1400
or
SIM 900 Shield
or
the SIM800L from above.

What's exactly the difference between these systems ? Which one would you recommend ?

Thanks :slight_smile:

Okay,

Sim800L is the latest version. I've also seen that it works on the 2G network. As i'm located in Canada the 2G network is no longer supported. I see that the MKR GSM 1400 is working on 2G and 3G. The 3G network is meant to be stopped by end of 2025 in Canada. As I plan to use that for business purpose, would there be a reliable solution for this project ?

I was thinking SMS because of the simplicity of it (except maybe the coding) and I also needed to have the opportunity to activate/deactivate the valve even if there is not electricity, that's why I was leading toward this solution.

But as now on I'm open to any other other solution. Weather Wifi or SMS. I still have to do some research on the esp32. I also saw that there is an Arduino professional platform for professional application. I'll do some more research on this, but I'm doing it with the time I have at the moment. If you have any leads, link to a proper topic, website or could help me where to look, it would be awesome.

Thanks.

What does this mean?

The valve control project is for business, not a personal home project?

I mean when there is a power outage, the system while work on battery so that a can still communicate with it.

I want to try the system for eventually, if everything works, do something with it. But at the moment it's still a project in progress.

In other words, market it and sell it?

If everything works, I'll consider including it in a package, yes. Can you help me finding a solution, or orientate me on this project ? I've seen there is a professional Arduino branch with some industrial application and bords. would you think the "MKR NB 1500" will works for this ?

As a homeowner and gardener, I note you are not concerned with knowing if your project ACTUALLY turned the water on or turned the water off. Just sending commands is ignoring the troubling part of your project.

If I were doing this for personal use, I'd use an esp8266 connected to the WWW via an IOT service (such as Adafruit IO) or maybe just open a port on my router and use the router mfgrs ddns service.

If I were doing this to sell to others, I'd pay someone who develops this sort of thing for a living (who knows about liability, warranty, UL certifications, redundancy, failsafe, verifications, etc. in addition to the nuts, bolts, and code). You may find such a person on the Gigs and Collaborations section of the forum.

Hi I have a problem with my project.I can get SMS and I can see it on Serial Monitor.Message(R1,R2... R6 etc.) should trigger the relay but ıt doesnt.What is the point I missed?

'#include <Arduino.h>

// Using Serial2 hardware serial port on ESP32
HardwareSerial SIM800(2);

// Pin definitions for SIM800C (connected to ESP32 RX2 and TX2)
#define SIM800_RX_PIN 16 // ESP32 RX2 (GPIO16)
#define SIM800_TX_PIN 17 // ESP32 TX2 (GPIO17)

// Baud rate for SIM800C
#define BAUD_RATE 9600

// Relay pins
#define RELAY1_PIN 21
#define RELAY2_PIN 19
#define RELAY3_PIN 18
#define RELAY4_PIN 5
#define RELAY5_PIN 27
#define RELAY6_PIN 26

void setup() {
// Initialize primary serial port for debugging
Serial.begin(9600);

// Initialize SIM800C serial port
SIM800.begin(BAUD_RATE, SERIAL_8N1, SIM800_RX_PIN, SIM800_TX_PIN);

// Initialize relay pins
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
pinMode(RELAY3_PIN, OUTPUT);
pinMode(RELAY4_PIN, OUTPUT);
pinMode(RELAY5_PIN, OUTPUT);
pinMode(RELAY6_PIN, OUTPUT);

// Set all relays to HIGH initially (OFF state)
digitalWrite(RELAY1_PIN, HIGH);
digitalWrite(RELAY2_PIN, HIGH);
digitalWrite(RELAY3_PIN, HIGH);
digitalWrite(RELAY4_PIN, HIGH);
digitalWrite(RELAY5_PIN, HIGH);
digitalWrite(RELAY6_PIN, HIGH);

// Check connection to the SIM800C module
if (sendATCommand("AT")) {
Serial.println("SIM800C module connected.");
} else {
Serial.println("Failed to connect to SIM800C module.");
}

// Set SMS mode to text
if (sendATCommand("AT+CMGF=1")) {
Serial.println("SMS mode set to text.");
} else {
Serial.println("Failed to set SMS mode.");
}

// Enable new SMS notifications
if (sendATCommand("AT+CNMI=1,2,0,0,0")) {
Serial.println("New SMS notifications enabled.");
} else {
Serial.println("Failed to enable new SMS notifications.");
}
}

void loop() {
// Check for new SMS
readSMS();
}

// Function to send AT commands and wait for a response
bool sendATCommand(const char* command) {
SIM800.println(command); // Send AT command
Serial.print("Sent AT Command: ");
Serial.println(command);

// Timeout for response
unsigned long timeout = millis() + 5000; // 5-second timeout
while (millis() < timeout) {
if (SIM800.available()) {
String response = SIM800.readString(); // Read the response
Serial.print("SIM800 Response: ");
Serial.println(response);

  // Check for "OK" or ">" in response to confirm successful command
  if (response.indexOf("OK") != -1 || response.indexOf(">") != -1) {
    return true;
  }
}
delay(100); // Small delay to allow response

}
// Return false if no valid response
return false;
}

// Function to control relays based on SMS commands
void controlRelay(const String& command) {
if (command == "R1") {
digitalWrite(RELAY1_PIN, LOW); // Activate Relay 1
Serial.println("Relay 1 activated.");
} else if (command == "R2") {
digitalWrite(RELAY2_PIN, LOW); // Activate Relay 2
Serial.println("Relay 2 activated.");
} else if (command == "R3") {
digitalWrite(RELAY3_PIN, LOW); // Activate Relay 3
Serial.println("Relay 3 activated.");
} else if (command == "R4") {
digitalWrite(RELAY4_PIN, LOW); // Activate Relay 4
Serial.println("Relay 4 activated.");
} else if (command == "R5") {
digitalWrite(RELAY5_PIN, LOW); // Activate Relay 5
Serial.println("Relay 5 activated.");
} else if (command == "R6") {
digitalWrite(RELAY6_PIN, LOW); // Activate Relay 6
Serial.println("Relay 6 activated.");
} else {
Serial.println("Invalid command received.");
}
}

// Function to read incoming SMS
void readSMS() {
if (SIM800.available()) {
String response = SIM800.readString();
Serial.println("Incoming SMS: ");
Serial.println(response);

// Check for new SMS notification with +CMTI
if (response.indexOf("+CMTI") != -1) {
  // Extract SMS index number
  int indexStart = response.indexOf(",") + 1;
  String indexStr = response.substring(indexStart);
  int smsIndex = indexStr.toInt();

  // Read the new SMS
  SIM800.print("AT+CMGR=");
  SIM800.println(smsIndex);
  delay(1000); // Wait for SMS content

  // Read and display SMS content
  if (SIM800.available()) {
    String smsResponse = SIM800.readString();
    Serial.println("SMS Content: ");
    Serial.println(smsResponse);

    // Check for relay commands in the SMS content
    if (smsResponse.indexOf("R1") != -1) controlRelay("R1");
    else if (smsResponse.indexOf("R2") != -1) controlRelay("R2");
    else if (smsResponse.indexOf("R3") != -1) controlRelay("R3");
    else if (smsResponse.indexOf("R4") != -1) controlRelay("R4");
    else if (smsResponse.indexOf("R5") != -1) controlRelay("R5");
    else if (smsResponse.indexOf("R6") != -1) controlRelay("R6");
  }
}

}
}
`