CAT-BOT
![Screen Shot 2017-09-13 at 9.11.45 PM.png](/proxy/?url=https://content.instructables.com/FLK/AJIL/J7GGSC2G/FLKAJILJ7GGSC2G.png&filename=Screen Shot 2017-09-13 at 9.11.45 PM.png)
I used to dream of my kitty talking to me and now I am going to make my toy kitty react to my actions and even CHAT WITH ME!
Schematic
![Screen Shot 2017-09-13 at 10.39.19 PM.png](/proxy/?url=https://content.instructables.com/FNF/HFGZ/J7GGI6MG/FNFHFGZJ7GGI6MG.png&filename=Screen Shot 2017-09-13 at 10.39.19 PM.png)
Let's make a draft about the project.
Firstly I need a raspberry pi, which has a Linux OS, can compile Python and even has an access to the Internet.
Secondary I would like to use Arduino to get some data as well as realize some basic physical reactions.
Thirdly a webcam is required to capture user actions.
Finally is to make the connection to an AI chatbot.
Material List:
5MP Night Vision Camera for Raspberry Pi
DFRduino UNO R3 [ similar as Arduino UNO R3 ]
USB Cable A-B for Arduino Uno/Mega
and a monitor is required for raspberry pi
Assambling
![IMG_0675.JPG](/proxy/?url=https://content.instructables.com/F1E/MQ1T/J7GGIJ5M/F1EMQ1TJ7GGIJ5M.jpg&filename=IMG_0675.JPG)
![fullsizeoutput_10d.jpeg](/proxy/?url=https://content.instructables.com/FD5/VNU3/J7GGIJ5P/FD5VNU3J7GGIJ5P.jpg&filename=fullsizeoutput_10d.jpeg)
Just have everything in their right position.
Initial Raspberry Pi
![Screen Shot 2017-09-14 at 7.12.40 AM.png](/proxy/?url=https://content.instructables.com/FIO/83UN/J7GGIJSS/FIO83UNJ7GGIJSS.png&filename=Screen Shot 2017-09-14 at 7.12.40 AM.png)
Hint: just install the RASBAIN
Test the Pi-camera
here is a test code from pythonprogramming.net
import io
import picamera
import cv2
import numpy
#Create a memory stream so photos doesn't need to be saved in a file
stream = io.BytesIO()
#Get the picture (low resolution, so it should be quite fast)
#Here you can also specify other parameters (e.g.:rotate the image) with picamera.PiCamera() as camera: camera.resolution = (320, 240) camera.capture(stream, format='jpeg')
#Convert the picture into a numpy array
buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8)
#Now creates an OpenCV image
image = cv2.imdecode(buff, 1)
#Load a cascade file for detecting faces
face_cascade = cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml')
#Convert to grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#Look for faces in the image using the loaded cascade file
faces = face_cascade.detectMultiScale(gray, 1.1, 5)
print "Found "+str(len(faces))+" face(s)"
#Draw a rectangle around every found face for (x,y,w,h) in faces:
cv2.rectangle(image,(x,y),(x+w,y+h),(255,255,0),2)
#Save the result image
cv2.imwrite('result.jpg',image)
PySerial Encapsulates the Access for the Serial Port
connect the Raspberry Pi and the Arduino Uno with the cable.
After installing pySerial, reading data from Arduino is straightforward:
>>> import serial
>>> ser = serial.Serial('/dev/tty.usbserial', 9600)
>>> while True:
... print ser.readline()
'1 Hello world!\r\n'
'2 Hello world!\r\n'
'3 Hello world!\r\n'
Writing data to Arduino is easy too (the following applies to Python 2.x):
>>> import serial # if you have not already done so
>>> ser = serial.Serial('/dev/tty.usbserial', 9600)
>>> ser.write('5')
Test the Sensor and the Servo on the Arduino
![Screen Shot 2017-09-14 at 7.43.05 AM.png](/proxy/?url=https://content.instructables.com/FWR/T3M4/J7GGIKRV/FWRT3M4J7GGIKRV.png&filename=Screen Shot 2017-09-14 at 7.43.05 AM.png)
![Screen Shot 2017-09-14 at 7.43.39 AM.png](/proxy/?url=https://content.instructables.com/FPU/NPVK/J7GGIKRW/FPUNPVKJ7GGIKRW.png&filename=Screen Shot 2017-09-14 at 7.43.39 AM.png)
![Screen Shot 2017-09-14 at 7.44.00 AM.png](/proxy/?url=https://content.instructables.com/F71/SCFL/J7GGIKRX/F71SCFLJ7GGIKRX.png&filename=Screen Shot 2017-09-14 at 7.44.00 AM.png)
I have a temperature sensor which would give feedback when (you petting the kitty) the temperature reaches some pre-set height.
Add Chatbot Functions
I decided to have the bot make some feedback when I petting it.
eg. 'Meow! Keep going that way.'
'Purrrrrr. How is your day today my slave?'
'STILL NO GIRLFRIEND!?'
###############################################
So I wanna set each of those sentences a number and make a random function to print any of those sentences on my screen(I would use ssh to connect to the raspberry pi) after I petting it for ten minutes or even longer.
Update Your Code
Package Everything and Put Them Into a Toy Kitty
![IMG_0377.JPG](/proxy/?url=https://content.instructables.com/FLU/T5CS/J7GGIJ5O/FLUT5CSJ7GGIJ5O.jpg&filename=IMG_0377.JPG)