Need Help With Ultrasonic Sensor Sending Email

Sorry, I'm brand new to this, but trying a lot of things and still having some trouble!

MY HARDWARE:
• Arduino Uno
• WiFi 101 ShieldIf
• Ultrasonic Sensor

I WANT TO DO THIS:
When the ultrasonic sensor detects the object at a distance of (x) centimeters, send an email to (y) email address.

ALREADY DONE:
I set up the Google App-Specific Password, Username, FromAddress, Message Body, etc. on Temboo
The sensor event is as follows: If Digital 8 is HIGH then run the Choreo

QUESTIONS:
• How can I set the exact distance that triggers the Choreo?
• What do I do with the "Header" file, where does that go?
• When I paste the code and attempt to verify, I get the following Error Message. How do I fix this?:

Users/stucarnes/Documents/Arduino/TEMBOO___Tank/TEMBOO___Tank.ino:5:66: fatal error: TembooAccount.h: No such file or directory
#include "TembooAccount.h" // Contains Temboo account information

  • ^*
    compilation terminated.
    Multiple libraries were found for "Temboo.h"
    Used: /Users/stucarnes/Documents/Arduino/libraries/Temboo
    Not used: /Applications/Arduino.app/Contents/Java/libraries/Temboo
    exit status 1
    Error compiling for board Arduino/Genuino Uno.

–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Below is the code that all of the above is referring to, that Temboo generated:

#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information

WiFiClient client;

// The number of times to trigger the action if the condition is met
// We limit this so you won't use all of your Temboo calls while testing
int maxCalls = 10;

// The number of times this Choreo has been run so far in this sketch
int calls = 0;

int inputPin = 8;

void setup() {
Serial.begin(9600);

// For debugging, wait until the serial console is connected
delay(4000);
while(!Serial);

int wifiStatus = WL_IDLE_STATUS;

// Determine if the WiFi Shield is present
Serial.print("\n\nShield:");
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("FAIL");

// If there's no WiFi shield, stop here
while(true);
}

Serial.println("OK");

// Try to connect to the local WiFi network
while(wifiStatus != WL_CONNECTED) {
Serial.print("WiFi:");
wifiStatus = WiFi.begin(WIFI_SSID);
if (wifiStatus == WL_CONNECTED) {
Serial.println("OK");
} else {
Serial.println("FAIL");
}
delay(5000);
}

// Initialize pins
pinMode(inputPin, INPUT);

Serial.println("Setup complete.\n");
}

void loop() {
int sensorValue = digitalRead(inputPin);
Serial.println("Sensor: " + String(sensorValue));

if (sensorValue == HIGH) {
if (calls < maxCalls) {
Serial.println("\nTriggered! Calling SendEmail Choreo...");
runSendEmail(sensorValue);
calls++;
} else {
Serial.println("\nTriggered! Skipping to save Temboo calls. Adjust maxCalls as required.");
}
}
delay(250);
}

void runSendEmail(int sensorValue) {
TembooChoreo SendEmailChoreo(client);

// Set Temboo account credentials
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);

// Set Choreo inputs
String FromAddressValue = "xxxxxxx@gmail.com";
SendEmailChoreo.addInput("FromAddress", FromAddressValue);
String UsernameValue = "xxxxxxx@gmail.com";
SendEmailChoreo.addInput("Username", UsernameValue);
String ToAddressValue = "xxxxxxx@gmail.com";
SendEmailChoreo.addInput("ToAddress", ToAddressValue);
String SubjectValue = "Hello";
SendEmailChoreo.addInput("Subject", SubjectValue);
String MessageBodyValue = "xxxxxxx";
SendEmailChoreo.addInput("MessageBody", MessageBodyValue);
String PasswordValue = "xxxxxxxxxxx";
SendEmailChoreo.addInput("Password", PasswordValue);

// Identify the Choreo to run
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");

// Run the Choreo
unsigned int returnCode = SendEmailChoreo.run();

// Read and print the error message
while (SendEmailChoreo.available()) {
char c = SendEmailChoreo.read();
Serial.print(c);
}
Serial.println();
SendEmailChoreo.close();
}
COPY
HEADER FILE

UPDATE: I solved the Error Message issue. (Duh) :confused: BUT would still really appreciate help defining the exact distance that will trigger the email being sent! Where can I do that in the sketch and how, please? :slight_smile: Thanks anyone!

OK, quick reply as no other.

The code snippet:

void loop() {
  int sensorValue = digitalRead(inputPin);
  Serial.println("Sensor: " + String(sensorValue));

  if (sensorValue == HIGH) {

is where you need to look.

It's a bit odd reading the value from an analogue device at a digital pin; its value can only be HIGH or LOW whereas you would expect it to be an analogue reading of between 0 and 1023. Always assuming this is your ultrasonic output pin?

This is the problem when developers plug together bits of code they don't really understand; fine when it works, but when it doesn't then what? No one here can help either unless they have used the same example code. Probably why you've had no other replies :frowning:

Now if your really want to understand and learn something then get an ultrasonic device like the HC-SR04 (if you have not already got this) and look at my video #17 where all this is demonstrated and you can get your device to work and you will know exactly where it is you have to change a value to get the distance. It's fun and educational. And it's quick and easy to do too.