Stap 7: Upload deze Code naar uw planken
Nu voordat we uploaden van de Arduino schets moet u aanmelden voor een Temboo Account en uw referenties te krijgen. Temboo is een service waarmee met behulp van API's uiterst snel en eenvoudig. Dit script maakt oproepen naar Temboo om het e-mailbericht verzenden wanneer de Prullenbak vol is.
Aanmelden voor een Temboo Account en ga naar de sectie "Toepassingen" om uw
-De naam van de account van de Temboo
-De naam van de sleutel van de app
-Sleutel app
Upload deze code naar je Arduino board:
//Trash Can #include #include #include "TembooAccount.h" #include #include // software serial #1: TX = digital pin 10, RX = digital pin 11 SoftwareSerial portOne(10, 11); SoftwareSerial Geno(7,8); // Rx , Tx Servo trashServo; int trigPin = 2; int echoPin = 4; long duration, cm, inches; unsigned char Data[10]; unsigned char i; int counter = 0; int trigPin1 = 5; int echoPin1 = 6; long duration1, cm1, inches1; void setup() { portOne.begin(9600); Serial.begin (9600); Serial.println("bridge opening..."); Bridge.begin(); Serial.println("bridge OPEN!!"); Geno.begin(9600); SetVolume(25); trashServo.attach(9); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(trigPin1, OUTPUT); pinMode(echoPin1, INPUT); delay(5000); Serial.println("Initiate Smart Trash Can..."); } void playTrack(int track){ delay(1000); Data[0] = 0x7E; Data[1] = 0x04; Data[2] = 0xA0; Data[3] = 0x00; Data[4] = 0x00 + track; Data[5] = 0x7E; Command(Data,5); play_pause(); delay(3000); } void playTrackFULL(int track){ delay(1000); Data[0] = 0x7E; Data[1] = 0x04; Data[2] = 0xA0; Data[3] = 0x00; Data[4] = 0x00 + track; Data[5] = 0x7E; Command(Data,5); trashServo.write(160); play_pause(); delay(300); trashServo.write(180); delay(200); trashServo.write(160); delay(100); trashServo.write(180); delay(100); trashServo.write(160); delay(200); trashServo.write(180); delay(100); trashServo.write(160); delay(100); trashServo.write(180); delay(600); trashServo.write(160); delay(200); trashServo.write(180); delay(100); trashServo.write(160); delay(100); trashServo.write(180); delay(100); trashServo.write(160); delay(200); trashServo.write(180); delay(200); trashServo.write(160); delay(100); trashServo.write(180); delay(200); trashServo.write(160); delay(300); trashServo.write(180); delay(200); trashServo.write(160); delay(100); trashServo.write(180); delay(200); trashServo.write(160); delay(300); trashServo.write(180); delay(200); } void playTrackHEY(int track){ delay(1000); Data[0] = 0x7E; Data[1] = 0x04; Data[2] = 0xA0; Data[3] = 0x00; Data[4] = 0x00 + track; Data[5] = 0x7E; Command(Data,5); trashServo.write(150); play_pause(); delay(400); trashServo.write(180); delay(300); trashServo.write(160); delay(100); trashServo.write(180); delay(100); trashServo.write(160); delay(200); trashServo.write(180); delay(200); trashServo.write(160); delay(400); trashServo.write(180); delay(400); } void playTrackHI(int track){ delay(1000); Data[0] = 0x7E; Data[1] = 0x04; Data[2] = 0xA0; Data[3] = 0x00; Data[4] = 0x00 + track; Data[5] = 0x7E; Command(Data,5); trashServo.write(150); play_pause(); delay(400); trashServo.write(180); delay(300); trashServo.write(160); delay(100); trashServo.write(180); delay(100); trashServo.write(160); delay(200); trashServo.write(180); delay(200); trashServo.write(160); delay(100); trashServo.write(180); delay(300); trashServo.write(160); delay(400); trashServo.write(180); } void SetVolume( int vol){ Data[0] = 0x7E; // START Data[1] = 0x03; // Length Not 0x02 Data[2] = 0xA7; // Command Data[3] = vol; // new volume Data[4] = 0x7E; // END Command(Data,5); } void Command(unsigned char *Data, int length){ for(int i=0; i 1000) { trashServo.write(80); //Lid open delay(5000); } digitalWrite(trigPin1, LOW); //Inside Sensor delayMicroseconds(1); digitalWrite(trigPin1, HIGH); delayMicroseconds(2); digitalWrite(trigPin1, LOW); pinMode(echoPin1, INPUT); duration1 = pulseIn(echoPin1, HIGH); inches1 = (duration1 / 2) / 74; Serial.println(inches1); if (inches1 < 3 && counter == 0) { counter ++; playTrackFULL(2); Serial.println("Sending Email..."); TembooChoreo SendEmailChoreo; // Invoke the Temboo client SendEmailChoreo.begin(); // Set Temboo account credentials SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); SendEmailChoreo.setAppKey(TEMBOO_APP_KEY); // Set profile to use for execution SendEmailChoreo.setProfile("EmailTest"); // Identify the Choreo to run SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); // Run the Choreo; when results are available, print them to serial SendEmailChoreo.run(); while(SendEmailChoreo.available()) { char c = SendEmailChoreo.read(); Serial.print(c); } SendEmailChoreo.close(); Serial.println("Email Sent..."); } //Serial.println(incoming); if (incoming == 111){ //Open Lid from App trashServo.write(80); delay(2000); } //Serial.println(incoming); if (incoming == 49){ playTrackFULL(2); //I have reached capacity } //Serial.println(incoming); if (incoming == 50){ playTrackHEY(1); //hey get out of there } //Serial.println(incoming); if (incoming == 51){ playTrackHI(3); //Hi, I am open Trash Can } }//ends loop
In de Arduino IDE-Klik op een nieuw tabblad toevoegen en maken een headerbestand genoemd: TembooAccount.h deze code toevoegt aan uw headerbestand en vul het met de referenties van uw Temboo.
//header file /* IMPORTANT NOTE about TembooAccount.h TembooAccount.h contains your Temboo account information and must be included alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h, and copy this content into it. */ #define TEMBOO_ACCOUNT "********" // Your Temboo account name #define TEMBOO_APP_KEY_NAME "*******" // Your Temboo app key name #define TEMBOO_APP_KEY "******************************" // Your Temboo app key /* The same TembooAccount.h file settings can be used for all Temboo SDK sketches. Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */