Project tutorial

Arduino based Amazon Echo using 1Sheeld © CERN-OHL

DIY Amazon Echo using Arduino that can control house lights, tell you the time, play music and even get the weather status right now.

  • 20,419 views
  • 55 comments
  • 58 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

A few months ago I visited a friend of mine and I was amazed with the Amazon Echo he owned.

It can play music, control the house lights, tell me news and weather status, and even the date and time, all of that with just voice commands.

At that moment, the maker inside me shouted "why don't I make it myself!".

And since that day I started to search for components that could help me to make an arduino based Amazon Echo, until I found the amazing 1Sheeld.

1Sheeld is a platform for Arduino that allows you to tap into your smartphone's sensors and capabilities and let you use them in your Arduino projects.

Basically, it is a hardware shield that sits on top of your Arduino board and communicates over Bluetooth to this Android app, to transfer data between it and your smartphone.

You can check the getting started tutorial on 1Sheeld website which will take you step by step till you can operate the 1Sheeld very smoothly and it's an awesome reference for great Arduino projects.

I have used in this project five shields from the 40+ shields in the 1Sheeld.

The first one is the Voice Recognition Shield which I used to control the whole system with voice commands, it's very simple shield that I can activate it with only 1 line of code: VoiceRecognition.start();

Then I used the Music Player Shield which allows me to tap into the smartphone music player and choose the tracks i want to play very smoothly, actually it's very simple that i only used this line to play the music player shield: MusicPlayer.play();

The third shield i used is one of the most important shields in the project, it's the Text to Speech Shield which add to the project a humanoid interaction that someone is responding for what you are saying, it was so easy to make the system responsive: TextToSpeech.say("time in cairo is");

After activating the Text to Speech shield i have activated the Clock Shield which return the clock in real time and then the system can respond with the time once i asked for it, amazing! isn't it :), and i can easily get the current time in my phone using this function: Clock.queryDateAndTime();

The last shield i used is the Internet Shield which in my opinion is the most powerful shield in the 1Sheeld, i used that shield to get the current status of the weather in my home town using an API from "openweathermap" website where I can call the API with that line: HttpRequest request1("/*the API address */");

Step 1: Gather the components

1- Arduino 101 $30.99

2- 1Sheeld+ board $54.94

3- iPhone $155.5

4- PVC pipe $2

5- LED strip $5

6- 12V Power supply $7

7- Relay board $3

8- Jumpers and wires $3

9- 3 NPN transistors $1

Step 2: Make holes in the pipe to allow the sound to go out

Step 3: Paint the PVC pipe with black spray

Step 4: Make the wiring

1- Connect the LED strips to the transistors and the power supply

2- Connect the lamp to the relay board and AC terminals

3- Connect the relay board and the LED strips to the Arduino 101 board as mentioned in the code below

4- Mount all that with the iPhone inside the PVC pipe

Step 5: Setup 1Sheeld library

you can manage any libraries from arduino's IDE .. just click Sketch >> Include library >> Manage libraries >> type OneSheeld >> then click install and you are good to go. ​ Or you can download the library from here :- http://1sheeld.com/downloads/ Then open your Arduino IDE then chose sketch from the menu bar >> Include library >>add .zip file >> then chose the zip file yo just downloaded :)

Step 6: Install 1Sheeld app

Download the 1Sheeld mobile app from the website or you can visit Apple play store or Google play store to get the app.

Step 7: Access the shields

Follow 1Sheeld getting started tutorial and at the end of it chose the following shields

Voice Recognition

Text to Speech

Clock

Internet

Music Player

Then press the multiple shield button.

Schematics

Amazon Echo Schematic
Alexa schetch g8vtvfyf2r

Code

Amazon echo codeArduino
/*
 
OPTIONAL:
To reduce the library compiled size and limit its memory usage, you
can specify which shields you want to include in your sketch by
defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define. 

*/

#define CUSTOM_SETTINGS
#define INCLUDE_INTERNET_SHIELD
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
#define INCLUDE_TEXT_TO_SPEECH_SHIELD
#define INCLUDE_MUSIC_PLAYER_SHIELD
#define INCLUDE_CLOCK_SHIELD


/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* create an initial value for the millis counter. */
unsigned long previousMillis = 0;
/* create an intial state for calling alexa. */
bool state = 0;

/* Call an api that will return the weather status in cairo,egypt. */
HttpRequest request1("http://api.openweathermap.org/data/2.5/weather?q=Cairo,EG&appid=43d95b4cf5d0573e2dfe5186c160017a");

/* define the 3 transistors on pins 3,5 and 6. */
#define strip1 3
#define strip2 6
#define strip3 5
/* define the lamp on pin 13. */
int lamp = 13;

/* define the variable that will hold the hours and miniuts . */
int hour, minute;

/* Create 2 charachter arrys to catch the string you want from the sentence. */
char b[4];
char c[4];

/* define variables to hold the hour and miniuts in string. */
String strh, strm ;
/* define variable  to hold the day status am or pm. */
String noon;

/* Voice commands set by the user. */

const char mainCommand[] = "alexa";

const char weatherCommand[] = "how is the weather today";

const char playCommand[] = "play music";

const char clockCommand[] = "what time is it";

const char stopCommand[] = "stop";

const char lightonCommand[] = "turn on the lights";

const char lightoffCommand[] = "turn off the lights";



void setup() {
  /* Start Communication. */
  OneSheeld.begin();
/* set the led strips and the lamp to output. */
  pinMode(strip1,OUTPUT);
    pinMode(strip2,OUTPUT);
      pinMode(strip3,OUTPUT);
            pinMode(lamp,OUTPUT);

      

 /* Subscribe to success callback for the request. */
 request1.setOnSuccess(&onSuccess1);
 /* Subscribe to json value replies. */
  request1.getResponse().setOnJsonResponse(&onJsonReply1);
/* on a voice recogniced call the function "myfunction". */
  VoiceRecognition.setOnNewCommand(&myFunction);
}

void loop ()
{
  /* make a delay for 5 seconds using millis counter to keep the voice detection alive. */
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 5000) {

    previousMillis = currentMillis;

    /* get the current time in your phone. */
     Clock.queryDateAndTime();
     /* start voice recognition. */
    VoiceRecognition.start();
  }
/* save the smartphone hour and minutes in variables. */
  hour = Clock.getHours();
  minute = Clock.getMinutes();
  
/* detect the time status if it am or pm. */
  if (hour > 12)
  { hour -= 12;
    noon = "P M";
  }
  else {
    noon = "A M";
  }


/* save the hour and minutes as string. */
  strh = String(hour);
  strm = String(minute);

/* save the string in a charchter array. */
  strh.toCharArray(b, 4);
  strm.toCharArray(c, 4);
}

/* This function will be invoked each time a new command is given. */
void myFunction (char *commandSpoken)
{
/* check if any one call alexa or not. */
  if (!strcmp(mainCommand, VoiceRecognition.getLastCommand()))
  {
    alexon();  
    MusicPlayer.setVolume(5);
    /* if yes make the state =1 . */
    state = 1;
  }
  /* check if you asked to play music after calling alexa. */
  if (!strcmp(playCommand, VoiceRecognition.getLastCommand()) && state == 1)
  {

    alexoff();
    MusicPlayer.play();
    delay(10000);
    MusicPlayer.stop();
    state = 0;
    }
/* check if you asked to get the weather status after calling alexa. */
   else if(!strcmp(weatherCommand,VoiceRecognition.getLastCommand())&& state == 1)
    {

     alexoff();
    Internet.performGet(request1);
    /* Wait for 5 seconds. */
    OneSheeld.delay(5000);
     state = 0;
    }
/* check if you asked for the time after calling alexa. */
  if(!strcmp(clockCommand,VoiceRecognition.getLastCommand()) && state == 1)
     {

      alexoff();
       /* 1Sheeld responds using text-to-speech. */
       TextToSpeech.say("time in cairo is");
       delay(1300);
       TextToSpeech.say(b);
        delay(600);
        TextToSpeech.say(c);
         delay(800);
         TextToSpeech.say(noon);
         delay(500);
          state = 0;
     }
/* check if you asked to turn the lamp on after calling alexa. */
  if (!strcmp(lightonCommand, VoiceRecognition.getLastCommand()) && state == 1)
  {
    alexoff();
    digitalWrite(lamp,HIGH);
    TextToSpeech.say("the lights turned on");
    delay(6000);
    state = 0;
  }
/* check if you asked to turn the lamp off after calling alexa. */
  else if (!strcmp(lightoffCommand, VoiceRecognition.getLastCommand()) && state == 1)
  {
    alexoff();
    digitalWrite(lamp,LOW);
    TextToSpeech.say("the lights turned off");
    delay(3000);
    state = 0;
  }
}

void onSuccess1(HttpResponse & response1)
{
  /* Using the response to query the Json chain till the required value. */
  /* i.e. Get the value of 'main' in the first object of the array 'weather' in the response. */
  /* Providing that the response is in JSON format. */
       response1["weather"][0]["main"].query();
delay(200);    
}

void onJsonReply1(JsonKeyChain & hell,char * output)
{
  if(hell == request1.getResponse()["weather"][0]["main"])
  {
   TextToSpeech.say("the weather today in cairo is");
  delay(2000);
  /* 1Sheeld responds using text-to-speech shield. */
  TextToSpeech.say(output);
    } 
}

void alexon(){
  /* Turn on the strips in order like the same oder of amazon echo. */
  digitalWrite(strip1,HIGH);
     delay(200);
      digitalWrite(strip2,HIGH);
       delay(200);
        digitalWrite(strip3,HIGH);
  }

 

  void alexoff(){

    /* Turn off the strips. */
    digitalWrite(strip1,LOW);
      digitalWrite(strip2,LOW);
        digitalWrite(strip3,LOW);
    }

Comments

Similar projects you might like

Pac-Man LED Pixel Panel Costume

Project tutorial by Ben Muller

  • 4,981 views
  • 4 comments
  • 86 respects

LoRa Gateway for DeviceHive

Project tutorial by DeviceHive IoT team

  • 1,320 views
  • 2 comments
  • 17 respects

IoT Bird Feeder with Sigfox and Tweeter

Project showcase by Gaël Porté

  • 388 views
  • 0 comments
  • 7 respects

Raspberry Pi and Arduino Laptop

Project tutorial by Dante Roumega

  • 17,831 views
  • 6 comments
  • 45 respects

SmartWay

Project tutorial by Universum

  • 275 views
  • 0 comments
  • 5 respects

Arduino-Based Automatic Guitar Tuner

Project tutorial by Ben Overzat

  • 3,618 views
  • 0 comments
  • 12 respects
Add projectSign up / Login