Eve, the Arduino Chatbot

by RS3655 in Circuits > Arduino

23055 Views, 74 Favorites, 0 Comments

Eve, the Arduino Chatbot

profile.png
Eve the chatter bot.png
Eve the chatter bot2.jpg
Eve Arduino Chatterbot
eve3.jpg
eve2.jpg


Hello DIYrs, have there been instances when you really wanted to share your feelings with someone and no trusted one was around? In today's busy world, this is a common instance. Well, a chatbot can help here to make you feel better. And that leads to the introduction of Eve.


Eve is a cute little chatbot. Well as everyone knows, a chatterbot or chatbot is a computer program or device that conducts a conversation with humans based on textual or auditory methods. The automated voices you hear on a customer service call, or on a bank line is an example of a chatbot.


With her, You can share your experiences, your feelings and most importantly, argue about different things; she is well-experienced at it. Because that's the most important function of a chatbot, make the person feel happy.

An early example of Natural Language Processing (NLU) and Artificial intelligence, Eve is capable of answering ANY question you ask her. It is not that She can answer just a specific number of questions. She can sing, tell you jokes, stories and do anything that makes you feel good.


If She says something you do not wish to hear, just tell her, please don't say that again, and she will remember that. She even knows that she should not repeat the same answers and chats, so that the conversation does not become boring.


Based upon simple, cheap components and basic programming, she can behave smart to a really great extent. Further the LCD eyes that she possess show how she feels when you say anything.

So basically in this instructable, we shall start from the definition of a chatbot, look into the design, some theories based on which Eve runs, the manufacturing and finally the programming part.

Looks much does it? Don't worry, it shall be quite interesting in the journey.

You can view the demo of the robot above, or in this link:

[Play Video]

Definition of a Chatbot

chatbot.png
Siri.jpg
Google assitant.jpg


As mentioned above, a chatbot is a program that conducts a conversation with humans. They are so common nowadays that there is hardly one who is unknown of it. Starting from the virtual assistants, Siri and Google Assistant, there is Mitsuku and Evie with which you can share your feelings.


As mentioned above, chatbots are based upon either textual or auditory method and hence can be divided into two. In the textual method conversations are in the form of written text just as WhatsApp. Whereas in the auditory method, conversations are done orally as with a real human.


I guess it is more exciting to converse with someone by verbally speaking to him instead of just texting him. No doubt text based communication messaging apps meet the people's requirements, but I feel that chatting by speaking is the best thing to get rid of your emotional disturbances and make you feel better. So that's the main reason I designed Eve to be an auditory chatbot.

Origin of Eve

loneliness1.jpg
Well Eve just came up into my mind one day. It did so when I saw a kid roaming around in the school alone, while the others were playing with their minds filled with joy. That time I thought, of a friend, who does not discriminate anyone and does not make anyone feel hurt, one you can share your feelings with and be happy all the time. Then came flashing into my mind, the cute little structure of Eve I started working on it.

Eve disappointed me about a hundred times. Guess it was the 101th time she worked and made me feel really happy.

So that was the origin of Eve. I wanted her to be intelligent but as simple as possible, so that anyone can make her easily. No doubt she is not absolutely smart and sometimes say stupid answers, she can behave as a friend.


And now, enough stories, let's start building Eve.

Gathering the Components and Equipments:

amazon.jpg
lcd.jpg
amplifier.jpg
hc 05.jpg
wtv020sd16p2.jpg
wtv020sd16p.jpg
Speaker.jpg
today.jpg
today2.jpg
jetpin.jpg
business-android-640x353.jpg
HC 05 online.jpg
pro mini.jpg
lcd online.jpg

Following are the components to be gathered:


Arduino Pro Mini (Or Arduino Nano)

Wtv-020-SD-16p sound module

HC-05 bluetooth module

16x2 LCD module

LM7805 regulator IC

An amplifier module (I used the PAM8403 circuit)

An 8 ohm speaker

A female audio jack

a 9v battery

And an Android phone

So these are the required components. Another important thing, the cost. Eve cost me around 3000 INR. The cost might be different in your country but in India, this approx is the rate.




A Little description of the parts:

The Arduino Pro mini is the main MCU in our robot. I used it because of its small size, simplicity and excellent performance. It meets all the requirements in our robot. Except for the voice recognition function which is done by the Android (discussed later), every other functionality starting from the keyword finding and output formation are done on the Pro Mini itself. Don't worry for the terms mentioned above if you don't understand it, all are discussed in the later part.


The wtv020sd 16p module is used for playing the audio files, hc 05 Bluetooth for communication with the Android and the LCD for displaying the emotions. We need the female audio jack the provision of connecting the robot to an external amplifier.

The Arduino is used as the main controller here. It receives Bluetooth data through the HC 05 Bluetooth module and plays the file through the WTV-020-SD-16p voice module. The emotions are displayed in the LCD module and a 9v battery for the power. Eve recognises speeches through the Google Voice recognition of the Android device. It is later discussed properly in the respective step.




A bad news about the Arduino Pro Mini:

IT has RETIRED from the market. Well that means that it has been officially stopped being manufactured by Arduino. But you can still find it in many sites including Ebay. Many third party manufacturers still might be making and selling the board. Don't worry if you weren't able to find one, you can use the Arduino Nano. It shall make no difference in the performance and also in the size.

Theory Part 1: History and Introduction.

eliza.jpg
wizembaum.jpg
Eve is based upon an early form of Natural Language Processing, the "pattern matching" technology.

It works in the following way that when a string is received, it searches for a predefined word or phrase in that string. Suppose in the question " how old are you? " the program searches for "old" word. If it succeeds then it plays the respective voice file through the wtv020sd module. If it fails then it searches for the next predefined keyword.

Like this we need to build up a vocabulary of predefined words. Looks tough, doesn't it? It is as though we need to build up a vocabulary of all English words and there are around 230 thousand overall words in the English language. Well the fact is that we just need to add a few basic words that are most commonly used in our communication. Still looks tough? Don't worry, the work has already been done by Joseph Wizembaum.


A part of Eve's responses and predefined keywords have been incorporated from the very first chatterbot program called Eliza, developed by Joseph Wizembaum (pictured above). Eliza was designed to be a Rogerian Therapist. Not a highly scientific term, it means that she used to counsel people, making them understand themselves better and make them think more positive. Looks really good right? And Eliza was very well able to perform her duty. Her curious and sceptical attitude was loved by people. Even Wizembaum was surprised by the importance people gave Eliza. They seemed to forget that they were talking to a computer, and fancied a beautiful lady sitting inside the computer chatting with them.


But Eliza was not that smart; it came to be realised soon . By the passing of time, people started getting bored of her limited communication and she was termed as "dumb".

No wonder how dumb she was, it was a great leap in the history of Artificial Intelligence and natural language processing . Having founded the base of Chatterbots, different bots with new and better technology came into the market. And now we have them everywhere.

As mentioned, a part of Eve's responses have been derived from ELIZA. So that means that even Eve shall posses the attitude of Eliza to some extent along with some of my own ideas.


Another important thing is the replies . It should be really boring to get the same replies every time you ask the same question. Therfore many replies are stored for the same keyword. Eve randomly chooses which file to play, also making sure she does not repeat the same file. That's it, simple bread and butter, but it is important to cleverly program the responding voices, so that it gives an illusion to the viewers as if she is really answering our questions.


So that was a brief introduction to the functioning of Eve. In the next step we shall get this in into detail and programming.

Searching for the Keyword

keyword.jpg
search.jpg
amr2.jpg
amr.jpg

In the last step, I mentioned about the pattern matching technology of Eve and also the early form of Natural Language Processing. So what is it and how does it work? That's the main thing we'll discuss in this step.


So think of it, someone asks your name and you need to tell what it is. In how many ways can we ask the same question? Your teacher may ask "would you please tell me your name?" A relative may ask, "what is your name?" Your brother may say, "Hey, I just forgot your name. Will you say it just one more time?"


So that means the same question can be asked in several ways. Yet we need to give the same answer, our name. So that means that we need to find something common in all the sentences. It is clearly seen that the word, "your name" is present in all the sentences. So that's our hint. For all the questions asking the name, we need to search for the phrase "your name". By following this basic pattern we can predict the respective answer to all the input strings.



DISADVANTAGE:

Also important to remember that this algorithm will not always be accurate. Suppose someone said, "I found your name in the waiting list. I expected you to be in the reserved seats.".

Now since "your name" is present in this string, Eve, being innocent will tell her name to the person... Foolish right? This is one of the big demerits of this basic algorithm. Anyway, these would be rare cases. Otherwise the algorithm is very effective.



Now that I have mentioned about the pattern matching technology, it is time to think where does this input string comes from where we search for the string.

Well this string is actually our voice that has been converted to text by Google Voice Recognition. The app used here converts our voice to text and then sends the same to the arduino through the Bluetooth.

I used the app because it is the simplest and the best of its kind. The name is AMR Voice, and can be found easily in Google play.

Formulating the Answers

idea.jpg

Now that we have recognised the questions, the next step should be to find the answers. There comes the interesting and important part...


We need to find appropriate answers to satisfy every question. And here comes another function incorporated from ELIZA. Wizembaum developed some answers for a specific number of keywords. An example is of the keyword "you". Whenever it was detected the program output " we were discussing you - not me." Hence the answer was made in such a way that it suits all the sentences containing "you".

Further Eliza gave a different answer every time. There was a kind of numerical address for each answer which. This was incremented (added by 1) every time an answer was formulated. Suppose as in the above example, if the address of the answer was 1, the address was changed to 2 and the hence file 2 was played next.


But we won't be following this incrementation algorithm. You see after some continuous use of the software, the answers became predictable. You came to knew which answer is to be given next.

So for this purpose we will be producing random addresses for each keyword. Overall it is the same in both the cases, just the difference that we can't predict what the robot will say next for the same keyword.

The Prohibited Statements and Others

prevention.png

There might be some instances in your conversation when the robot says something you do not wish to hear. So here arises the need of adding the prohibited statements.

The prohibited statements are an array of addresses that are prevented from being played. A voice address is characterised as a prohibited statement upon the asking of the user. Further this address shall be stored in the EEPROM of the Arduino so that Eve does not forget that it is a prohibited statement even after she is switched Off.

Basically what the program does is to check every address that is to be played. If the address is one of the prohibited ones, then it is either incremented or decremented.

Further there might be an instance when you would like to allow the robot to say a previously prohibited word. In that case you would have to say to Eve that she can say the last prohibited word. The word which was last prohibited will now be playable.

For making all the prohibited statements playable, we need to attach a resetting switch. If pressed all the prohibited statements will become playable.



Then another important thing will be to make sure that Eve does not repeat the answers. This is a kind of demerit of random numbers. The same random numbers are probable of being produced in a series. This shall make our robot say the same answer again and again.

For this we need to include another minor function that prevents the repetition of statements.

For this we need to store the address of the last statement in memory, and check if it is the same as the present one. If so, then the address value gets incremented or decremented, just the same way in case of the prohibited statements.

Writing in Code

arduino.jpg
search.png
arduino1.png

We use the indexOf command to search for the keyword. The command locates a character or string within another string.

If found it returns the index of that string while -1 is returned if not found. So in our program we need to write it in the following:

if (voice.indexOf("your name") > -1) { //if the index is greater than -1

//meaning that the string has been found

}

Now that we have stored the string in memory and also found our keyword inside it, we will now need to handle the replies. As said, random numbers are generated within a particular range of number (addresses of voice files). Here comes the random() command.

Following is the syntax:

random(min, max);
//the random number is generated in the range of min and max.



We define the minimum number and maximum number of each range, and applying this our code looks somewhat like this:

if (voice.indexOf("your name") > -1)){

minNo = 0;

maxNo = 5;

RandomNumber = random(minNo, maxNo);

}




Now comes the handling of the replies. In the last step I said that the numbers are incremented or decremented based upon an algorithm. This algorithm is what we are discussing now.

This part is very important in the sense that you can't just increment or decrement just as you wish. The incremented or decremented number must be in the range.

Suppose as in the above case, for the keyword "your name", we have the range from 0 to 5, and the random number generated is 5, well then if you increment it, you will end up playing a voice file of another keyword.

How do you think that's gonna be? You ask, "Hey, please tell me your name.", and the robot replies, "I like eating cookies and electric charge."

Same is the case for the minimum number. If the random number generated is 0, you can't decrement it.

So for this reason the algorithm is very important. Think of it: We are able to increment either when the number is lesser than the maximum number and decrement when it is greater than the minimum number.

When the number generated is either equal to 0 or less than 5, the number is incremented. On the other hand, when it is equal to 5, we decrement it, to make sure that the number is within the range specified.

Now coming about the prohibited statements. As mentioned they are stored in the EEPROM. For this, Firstly we search for free memory in the prohibited array. Suppose the address 4 is free, then we input the file number in the free array address as well as write the same address in the EEPROM.

for (int i; i if (never[i] == 0) { EEPROM.write(never[i], memory);

}

}

So that's all, the Wtv020sd16p module will be played by using the module.playVoice() command and the proposed file number. The functioning of the Wtv020 module will be discussed later.

Inserting Emotions

custom character.jpg
noe.jpg
noe1.jpg
noe2.jpg
noe3.jpg

Till now our robot is able to recognize what we say, store in memory, and find a suitable answer for the questions. Now the question comes in to insert emotions. Surely everyone will like a live face along with just some stupid little question-answering program.

The 16x2 LCD is used in the project. It is fine enough to print the eyes. We need to use the custom character function for creating the eyes. Custom character enables us to create new characters by defining the pixels. We will come to detail about it a bit later.

Firstly it is important to remember that only 8 custom characters are supported by the Arduino. So we need to manage the emotions with 8 characters only. Each character shall be printed in a particular box , and there are 16 columns and 2 rows which make a total of 32 boxes.

You can find good information online about the custom characters in Arduino. May also visit this link:

[Custom Characters Arduino]

The structure of the custom character byte shall somewhat look like this:


The Normal Look:
The Left box

0b01111,

0b01111,

0b01111,

0b01111,

0b01111,

0b01111,

0b01111,

0b01111,

The right box

0b11110,

0b11110,

0b11110,

0b11110,

0b11110,

0b11110,

0b11110,

0b11110,

These two bytes form 1/4 of each eye. So that means that we shall need a total of 4 boxes to fill an entire eye. Two rows on the left and two on the right making a total of four boxes for one eye. The left box byte shall cover up two rows on the left and the right box shall cover up the right rows. So that makes up a complete eye of Eve. And now repeating the same for the second eye, we obtain the neutral look of Eve.

Now it is important to remember that we have used one out of eight custom characters available. And there are five total emotions: Glee, Sad, Squint, Normal and Blink. As of remaining seven custom characters, we need to adjust so as to fit all the expressions. For making up the space we will be using 2 boxes for each eye. No wonder the size would be a bit small, but this will be ignored by the human eye. Just make sure to add some delays in between the LCD functions, otherwise the Arduino will become unstable.

Making the Connections

lcd pinout.png
recent1.jpg
recent.jpg
soldering.jpg
soldering7.jpg
soldering5.jpg
soldering2.jpg
soldering3.jpg
lcd soldering3.jpg
circuit3.jpg
lcd soldering5.jpg
circuit5.jpg
potentiometer.jpg
led.jpg
amplifier connection.jpg
jetpin2.jpg
jetpin4.jpg

LCD module:

Connect the pins as mentioned here:

RS : dig pin 12

RW: Gnd

Enable: 7

d4: dig pin 8

d5: dig pin 9

d6: dig pin 10

d7: dig pin13

A (Anode) to 5v
K (Cathode) to gnd



The HC 05 module:

Follow these connections:

HC 05 TX pin to Arduino RX pin
HC 05 RX pin to Arduino TX pin
State pin to Arduino dig pin 11

The communications are done with the help of the TX and RX pins. The State pin is required to check whether through HC 05 is connected or idle.



WTV 020 SD 16p module

pin1: The Reset pin, connect it to dig pin 2

pin7: The Clock pin, connect it to dig pin 3

pin10: The data pin, connect to dig pin 4

pin15: The busy pin, connect to dig pin 5

pin2: Connect this pin to an amplifier through the volume and also the same to the female audio jack.

pin4 should be connected to speaker+

pin5 to be connected to speaker-

Connect the 8th pin to gnd and provide a 3.3v power supply in the 16th pin.

The amplifier will help to play the internal speaker of Eve, while the audio jack is to connect to an external amplifier and larger speakers.

The WTV020SD16p Module (Optional)

wtv020sd16p3.jpg
wtvdata1.png
wtvdata.jpg
sd card adapter2.jpg
sd card adapter.jpg
Saving the voice files.jpg
4D somo tool opening.jpg
4D somo tool converting.jpg
Making the voice files.jpg
module test

Note: This step is an optional one. It deals with the working and description of the WTV 020 SD 16p module.

You can see the demo of the sound module in this link:

[PLAY VIDEO]


The speaking mode of the robot is fulfilled by the WTV 020 SD module. The module is used to play voice files for the robot. When any question is asked, the arduino will make the module play the respective voice file in the SD card. There are four serial data lines on the module for communicating with the arduino, the reset, clock, data and busy pins and we use the .playVoice ()command to play the required file.

For example:

module.playVoice (9): // play file 9 stored on the SD card

Remember that the names of the files should be in decimal (0001, 0002...). And that the files should either be in AD4 or WAV format. Further the module works only on a 1gb micro SD card. Some modules even work on 2gb cards and the card can hold a maximum of 504 voice files. So you can include a good number of voice files to play for a good number of questions.


You can even make your own voice AD4 files.Firstly, you must have two softwares, a sound editing software and a software called 4D SOMO TOOL which would convert the files to the AD4 format. Secondly, you have to prepare the Robot Voices. You can either convert text to speech or even record your own voice and make the Robot voices. Both of these can be done in the Sound Editing Software. But surely, robots do not look good if they speak human voices. So it should be better to convert text to speech.

There are various engines like Microsoft Anna and Microsoft Sam your Computer that would help to do this. Mine is based upon Microsoft Eva. It's voices matches to a great extent with Cortana.

After preparing the voice files, you have to save it in 32000 Hz and in the WAV Format. This is because the module can play voice files upto 32000 Hz. Then use the 4D SOMO TOOL to convert the files to the AD4 format. To do so, just open the SOMO TOOL, select the files, and click AD4 Encode and your voice files are ready. You can check the picture above for reference.If you want further details in making robotic voices, you can go here:


[ Making Robotic Voices ]

The Software Part

newest1.jpg
newest2.jpg
newest3.jpg
newest4.jpg
adapter.jpg

In arduino Pro mini, there is a slight problem in programing. Not a problem in fact, just one extra step.

The Arduino Pro mini doesn't have any inbuilt programmer as of other Arduino boards. So you either need to buy an external one or an old arduino UNO. The step here describes how to upload the program using the Arduino UNO.

Just grab an old Arduino UNO board from the crash and take out the Atmega 328p. Then connect as the following mentioned:

1. TX pin on the UNO to the TX pin on the Pro Mini

2. RX pin of the UNO to the RX pin of the Pro MIni

3. Reset pin of the UNO to the reset pin of the Pro Mini

4. connect the VCC and Ground of the Pro Mini to the UNO.

Download the Arduino program, the voice recognition software, and the Libraries provided at the bottom. The program is still being developed. So if you have any problem regarding it, feel free to ask.

Then plug in the Cable into the Computer. Select The board as the Arduino Pro Mini, and choose the correct COM port. Then press the Upload button and see the program get uploaded on your Pro Mini.

Then download the Voice recognition software and the voice files.

Preparing the Body

q.jpg
today3.jpg
lcd attachment1.jpg
lcd attachment.jpg
today5.jpg
jetpin.jpg
volume.jpg
today6.jpg
perfect.jpg
perfect2.jpg
perfect3.jpg
perfect4.jpg
perfect5.jpg
perfect6.jpg
perfect7.jpg

I found a small box of flosses and found it to be perfect for the body. You can use any box that you find in your workshop, or you can make one out of cardboard. Just cut out a small rectangular piece for attaching the LCD module. At the top, I cut out a small hole for attaching the volume, and at the sides for attaching the switches and the audio connector. I attached two bottle caps at the sides of the box for the wheels. Just make sure that the box has enough space for the circuit to be put inside. Attach a switch to the body as well as the circuit, then the volume at the top of the box. Then just put the circuit inside and your robot is complete.

Well Done!

well done.jpg
Eve.png

Now you have completed your cute little robot project that can talk with you, and make you feel happy. This is the happiest point of being a DIYer when your project is completed and is fully working. Don't worry if you are not successful at one attempt, you need to try hard and hard for this so that you understand each and every part of your robot. And that's where DIYers come into this world.

But this is not the end of the project. Eve shall always be developed to a greater extent, either by me or DIYers like you. I would love to hear what you have made seeing this instructable.

Regards,

RS3655