Signal a state to a pc

In advance, I am very new to Arduino!
I almost finished this project where i have a floating thingy in a bucket that triggers a switch, which in effect triggers the arduino to give 3 good pulls on a solenoid that opens a valve so rainwater no longer runs in the bucket.

Now the fun part. The scenario above happens on my attic where I also have this PC running with Linux, hosting my files and such. It also runs postfix and here is my plan. When the arduino job is done, I want it to be read by my PC and send me an email.

So I would guess I would have CRON job run on my linux PC that does a job reading a arduino port (if that even exists, remember, I am a newbie) either listening for a simple "1" on A port or maybe even the flag used in the arduino script. But... how? And what If I do not want to use USB but a TTL port on the PC, so the wiring/ soldering is easier/ able to use longer wiring...and just two?

Please help a little where I should look. Or tell me if you guys know just how to setup such a scenario. Thanks in advance.

I suggest you spend some more time and do a preliminary design and pick the hardware devices that will perform the required functions. You will also have to resolve your communication to the PC.

Hi Gilshuls, oh it is this last bit i am looking for. Here is the stuff i have ready for implementation: "Bucket is full" system using an Arduino. - YouTube Rain water redirect automated. - YouTube

Hello alidigitaly

Welcome to the worldbest forum.

Take a piece of paper, a pencil and design, based on the IPO model, a program structure plan before start coding.
Identify functions and their depencies. Now start with coding and testing, function by function.
At the end merge all tested function together to get the final sketch.
The basics for coding the project are to be found in the IDE as examples.

Have a nice day and enjoy coding in C++.

1 Like

you could run esp-mail-client on a suitable microcontroller, e.g. ESP32, ESP8266, etc - which if you have WiFi coverage could send an email to an external SMTP server

1 Like

That is a great idea to consider.. I might even go for that! I am still interested in how I could read out the Arduino for future projects, using wires.

you could use serial communications - fairly easy to do in particular if you have a device with hardware serial ports, e.g. Arduino Mega, Arduino Due, ESP32
if communicating using wires with a number of devices consider RS485 or canbus

1 Like

10Mbps for 15 meters! That sounds great! I will need a different board (as above already mentioned) because I started out with the Uno. Thanks for the tip I will make use of with future projects!

using wires? try Ethernet

It said at the RS485 specs. I was dreaming of other projects using actual compatible hardware. Ethernet is even more appropriate I'm sure..

But how can I solve this communication issue with my current Uno and just a telephone wire to my pc.....
I'm almost at the point on giving up on that and just invest in a wifi solution.

the UNO does not have any hardwareserial ports
the AltSoftSerial docuementation states
AltSoftSerial is capable of running up to 31250 baud on 16 MHz AVR,
which is approximatly 3000bytes/secsond

if you require 10Mbps probably good idea to move to an ESP32

1 Like

This makes me so happy :slight_smile:

And the rainwater will be redirected like so: Rain water redirect automated. - YouTube

I let the relay jiggle the solenoid three times to give a good pull so the valve flips ¨for sure" because it stayed stuck in 1 out of ten manual tests. I could make it so that a sensor detects if the valve is open but I will be home anyway AND I get the notification email.

I want to thank you @horace!
The Esp was the best solution/ tip for my project.

And here is the code I used:

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP_Mail_Client.h>
#include <ezButton.h>

// WiFi network settings
const char* ssid = "YourWiFiSSID";
const char* password = "YourWIFIpassword";

// Declare the global used SMTPSession object for SMTP transport
SMTPSession smtp;

// Declare the SMTP_Message class variable to handle to message being transport
SMTP_Message message;

// Declare the global used Session_Config for user defined session credentials
Session_Config config;

// Define the pin numbers where the relay and LEDs are connected
int relayPin = 22;
int redLedPin = 2;
int greenLedPin = 4;

// create ezButton object that attach to ESP32 pin GIOP17
ezButton limitSwitch(17);

// Define a variable to keep track of whether the relay has already been triggered
bool relayTriggered = false;

// Define a variable to keep track of whether the email has been sent
bool emailSent = false;


void setup() {
  // Set the relay pin as an output
  pinMode(relayPin, OUTPUT);
  // Set the LED pins as outputs
  pinMode(redLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  
  // Turn off the red and green LEDs initially
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, HIGH);
  
  // Connect to WiFi
  Serial.begin(115200);

  // set limit switch debounce time to 50 milliseconds
  limitSwitch.setDebounceTime(50);

  //Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
  
  // Initialize the SMTP client
  // Set the session config
  config.server.host_name = "smtp.yoursmtp.com";
  config.server.port = yoursmtpPORTnr;
  config.login.email = "yourusername@yoursmtp.com";
  config.login.password = "yourEMAILpassword";
  // Set the message headers
  message.sender.name = "RainBucket";
  message.sender.email = "yourEMAIL@yoursmtp.com";
  message.subject = "The Bucket Is Full!";
  // Set the message content
  message.text.content = "The Bucket Is Full! Change to a new bucket and check the valve!";
  message.addRecipient("RecepientName", "recepient@email.com");
  // Connect to the server
  smtp.connect(&config);
}

void loop() {
  // MUST call the loop() function first
    limitSwitch.loop();

  // If the button is pressed and the relay has not yet been triggered, switch the relay on and off three times
  if ((limitSwitch.isPressed()) && !relayTriggered) {
    // Turn on the red LED
    digitalWrite(redLedPin, HIGH);
    
    // Switch on and off the relay three times
    for (int i = 0; i < 3; i++) {
      digitalWrite(relayPin, HIGH);
      delay(100);
      digitalWrite(relayPin, LOW);
      delay(100);
    }
    
    // Stop the relay
    digitalWrite(relayPin, LOW); 
    
    // Set the relay triggered flag to true
    relayTriggered = true;
  } 
  
  // If the relay has been triggered and the email has not been sent, send the email
  if (relayTriggered && !MailClient.sendMail(&smtp, &message)) {
    if (MailClient.sendMail(&smtp, &message)) {
      Serial.println("Email sent successfully");
      emailSent = true;
    } else {
      Serial.println("Error sending Email, " + smtp.errorReason());
    }
  }
}

I used chatGPT to help me get along with the code btw. It is very useful!
And also a little bit of this and that and my own knowhow and coding experience.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.