Hello, I am very new to Arduino and I am still learning. I am working on a project that I want to use for water overflow on my ac unit. I found some projects online that I was able to use with their code but I can't figure out how to put them all together on just one code, this is what I need it to do. I have a 110V water pump connected to an Arduino nano with a relay and I use a magnetic sensor like the ones for alarms on doors and use it on a foam light board so, once the water container starts to fill the sensor, when it reaches the other sensor part, will activate the water pump. I installed it on the Arduino nano and works perfectly now I am using a water sensor on a separated Arduino Nano to activate a buzzer alarm when the water touches the sensor and finally I am using an SMS on another Arduino Nano to send a text message to my phone to alert me that the water container is overflowing. As you can see, I am using 3 Arduino's to do something that I am sure only one can do but every time I try to incorporate the programming I get errors and nothing works. I have been trying to figure out for the past month but obviously I am not knowledgeable enough to accomplish this, so if anyone can help me in figuring this out it will be very appreciated. Here are the codes I need to combine thank you.
This is the code I am using for activating the Water pump
int input = A1; //Magnetic Sensor In
int output = A5; //Relay Out
int maxSecondsOn = 300;
int minSecondsOn = 05;
int state = 0;
int secondsOn = 0;
void setup()
{
pinMode(input, INPUT_PULLUP);
pinMode(output, OUTPUT);
Serial.begin(9600);
digitalWrite(output, 1);
delay(500);
digitalWrite(output, 0);
Serial.println("Started");
Serial.print("Min Seconds On: ");
Serial.println(minSecondsOn);
Serial.print("Max Seconds On: ");
Serial.println(maxSecondsOn);
}
void loop()
{
int newState = !digitalRead(input); // The value is inverted (hence the ! sign) because I used the Arduino INPUT_PULLUP. Which means that it's normally HIGH unless the sensor is tripped.
// This is to avoid introducing an extra resistor into the circuit.
Serial.print("Output State: ");
Serial.print(state);
Serial.print(" Sensor state: ");
Serial.print(newState);
Serial.print(" Seconds On: ");
Serial.println(secondsOn);
if(state == 1)
{
secondsOn = secondsOn + 1;
if(secondsOn > maxSecondsOn)
{
newState = 0;
}
if(secondsOn < minSecondsOn)
newState = 1;
}
if(newState != state) //Status Changed
{
Serial.print("Changing Output to ");
Serial.println(newState);
state = newState;
secondsOn = 0;
digitalWrite(output, state);
}
delay(1000);
}
This is the code for the alarm
const int waterSens = A0;//define water sensor to pin A0
const int speaker = 8;//define speaker to pin 8
int SensorValue;//create sensor data variable
void setup() {
pinMode(speaker, OUTPUT);//set speaker as an output
pinMode(waterSens, INPUT); //set water sensor as an input
}
void loop() {
int sensorValue = analogRead(waterSens);//read the water sensor value
if (sensorValue >= 50) {
tone(speaker, 800, 800);
delay(200);
tone(speaker, 600, 800);
delay(200);
}//if the sensor senses water then play an alarm
}
and for the SMS I am using GSM sim900 module
// Dhaddammm Robotics //
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); // gsm module connected here
String textForSMS;
int data = 0;
int input = A1; //Magnetic Sensor In
void setup() {
randomSeed(analogRead(0));
Serial.begin(9600);
SIM900.begin(9600); // original 19200. while enter 9600 for sim900A
Serial.println(" logging time completed!");
pinMode(sensor, INPUT);
delay(5000); // wait for 5 seconds
}
void loop() {
data = analogRead(sensor);
Serial.println(data);
if ( data < 400) //
{
textForSMS = "\Warning Water Overflow";
sendSMS(textForSMS);
Serial.println(textForSMS);
Serial.println("message sent.");
delay(5000);
}
}
void sendSMS(String message)
{
SIM900.print("AT+CMGF=1\r");
delay(1000);
SIM900.println("AT + CMGS = "+919429260669""); // recipient's mobile number, in international format
delay(1000);
SIM900.println(message); // message to send
delay(1000);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(1000);
SIM900.println();
delay(100); // give module time to send SMS
// SIM900power(); // turn off module
}