• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoShowcaseKowheeli: a robotic koala bear
Previous Next

Kowheeli: a robotic koala bear

Posted by: Alvin Jin , January 10, 2014

[vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Project Description” tab_id=”1389318119-1-85″][vc_column_text]Original: http://wiki.cs.mtholyoke.edu/mediawiki/rmc/index.php/Spring2012_Final_Report-Jingjing_%26_Liye

  • Kowheeli is a robotic koala bear that also functions as an alarm clock.
  • It can be controlled through a webpage.
  • At the time set online by the user, she will sing songs.
  • A picture of Kowheeli is shown below:

File:Kowheeli.png[/vc_column_text][/vc_tab][vc_tab title=”Materials Used” tab_id=”1389318119-2-66″][vc_column_text]

  • Arduino UNO kit $35.0
    • An Arduino UNO board
    • A mini Breadboard
    • Connecting wires
  • Two DC motors —-
  • A LinkSprite CuHead WiFi Shield for Arduino $55.0
  • An L239D dual H-Bridge $2.0
  • A DS1307 Serial Real-Time Clock $3.5
  • A 0.5W 8Ohm Speaker $2.0
  • A 32.768 kHz Crystal
  • Rof various resistors —-
  • Transistors $5.0
  • Some LEGO components (to make a free-rotating front wheel) —-
  • Two LEGO wheels ( main wheels ) —-
  • A plastic board (as a base) $5.0
  • Two 9v battery (with battery holders) $3.5
  • One 3v Lithium Coin Cell battery (with battery holder) $2.0
  • One LED( power indicator) —-
  • A Koala bear pillow —-
  • Total Estimated Cost = 108 //this is the cost of all the parts on the final robot, not including parts used/damaged during the process of building it

.[/vc_column_text][/vc_tab][vc_tab title=”Preparation” tab_id=”1389318510087-2-6″][vc_column_text]

Arduino

  • Download Arduino software from http://arduino.cc/en/Main/Software, install drivers
  • Look at tutorials from http://www.ladyada.net/learn/arduino/
  • Play with some example sketches (File -> Examples -> Choose the sketch you find interesting)

WiFi Shield

  • Get WiShield library from https://github.com/linksprite/ZG2100BasedWiFiShield
  • Put it under libraries directory and restart arduino IDE
  • To use WiServer, ensure that #define APP_WISERVER is uncommented in apps-conf.h
  • Open SimpleServer sketch (File -> Examples -> WiServer -> SimpleServer)
  • Pass the correct parameters to gateway_ip[], subnet_mask[], ssid[] and security type, for WPA/WPA2 encrypted networks, passphrase are needed. On PC, these values can be obtained through cmd -> ipconfig to get ip address, subnet mask and gateway ip
  • For local_ip[] (IP address of WiFi Shield), it must not be used by any other device. We tried with two ways:
    • Test with IPs adjacent to the IP address assigned to a laptop/phone using that network. Note: It does not always work.
    • Turn a phone or a laptop to a WiFi hotspot, it is clear which IPs are unused. To set up WiFi hotspot on win7, do the following:
      • run cmd as administrator (click start, enter “cmd”, then Ctrl+Shift+Enter)
      • type in : netsh wlan set hostednetwork mode=allow ssid=<NetworkName> key=<Password>(required security type is WPA2) in cmd
      • go to Control Panel->Network Connections. Find the network that is connected to the internet (e.g LyonNet-Encrypt).
      • right click the network, select “properties”, then click “sharing”.
      • check the box before “allow other network users to connect…”, and choose “Wireless Network Connection 2” in the drop box
      • type in : netsh wlan start hostednetwork in cmd (to end it, change start to stop)
  • Compile and upload SimpleServer. In case it does not compile successfully. In all applicable files:
    • Replace #include “wiring.h” with #include “Arduino.h”
    • Replace #include “WProgram.h” with #include “Arduino.h”
    • In WiServer.h, replace virtual void write(uint8_t); to virtual size_t write(uint8_t);
  • Once it is uploaded, wait for red LED on WiFi shield to light up
  • Check http://<ip address of WiFi shield> to see “Hello World!”

RTC

  • Download RTC library from: https://github.com/adafruit/RTClib

[/vc_column_text][/vc_tab][vc_tab title=”Structure of Kowheeli” tab_id=”1389318553259-3-6″][vc_column_text]

Base

  • A plastic board forms the base. It has a hole in the center to allow wires from the motors pass through
  • Two DC motors are attached at the back
  • A free-rotating wheel made from LEGO is attached at the front

Circuit

The bread board holds an H-bridge circuit which controls the direction of current supplied to the motors, a Real Time Clock (RTC) and a speaker.

Motors

  • H-Bridge circuit controls the direction of current supplied to the motors
    • Why do we need the H-Bridge?
    • Because DC motors will only reverse the direction of turning when the direction of current flow is reversed.
    • Principle of an H-Bridge:File:H-bridge_principle.png
    • A dual H-bridge Motor Driver integrated circuit is used to achieve this
    • A step by step guide of constructing a circuit to control one motor can be found here: http://itp.nyu.edu/physcomp/Labs/DCMotorControl, which also includes a schematic diagram of L293NE

Alarm

  • A Serial Real-Time Clock DS1307 is a computer clock in the form of an integrated circuit
  • It is used as a time keeper regardless of whether the arduino board is powered or not as the coin cell battery will power it.
  • It uses a crystal oscillator, which uses the mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal with a very precise frequency to keep track of time
  • The RTC circuit can be constructed as follows:

File:RTC.jpg

  • A speaker is included to produce pre-set tones when the alarm time matches current time.

Put Together

  • Completed circuit looks as follows:

File:Complete.png

  • A detailed connections diagram is drawn below using Fritzing, an open-source software that can be downloaded from: http://fritzing.org/download/

File:CircuitFritzing.jpg

  • Note: The red LED is used as an indicator to tell whether power is on
  • At last, wrap the pillow around the base, insert more cotton if needed

[/vc_column_text][/vc_tab][vc_tab title=”User Interface” tab_id=”1389319014037-4-4″][vc_column_text]

  • Users control Kowheeli through a webpage

File:Web.png

  • To control the movement of the pet, simply click one of the four links (Forward/Backward/Left/Right) once.
    • Note: the action will continue until user clicks Switch, and the user has to click Switch between actions.
  • To set alarm, key in the time and press set.
    • Note: the hour input box only accepts values from 0-24, while the minute box only accepts values from 00-59 (has to be double digits)

[/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1389319044490-5-9″][vc_column_text](current version of code can be found in our status report, week 12)

User Interface

  • Inside sendMyPage(char* URL) function, WiServer’s print and println functions are used to write out the page content
  • The webpage is coded in HTML
    • Tutorials for HTML can be found here: http://www.w3schools.com/html/
    • To create the links and input box as shown in above section’s picture
Wheel Control Links:
<a href=?RUN">Forward: </a> 
Alarm Setting:
WiServer.print("<form action=""><font face=arial><center><b>Set Alarm Time Here: </b></font></center>");
WiServer.print("<br><input type=text name=HOUR /><b>:</b><input type=text name=MINUTE />");
WiServer.print("<input type=submit value=SET /></form>");
  • How does the user interface work?
    • When the user clicks any link or presses set button, the URL of the webpage will change.
    • By reading that change in URL, we can determine which link/button the user has clicked, and according to that, different actions will be performed
    • After that, the webpage will return to index page, waiting for the next action by the user

Motor Control

  • In setup(), set all H-Bridge pins as outputs.
  • To control one motor, in loop():
One Direction:
digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
Reversed Direction: 
digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low
  • Similarly, by setting appropriate turning directions for the two motors, direction of movement can be controlled

Alarm Setting

How does alarm work?

  • Current time is constantly compared with time kept by RTC
  • When the two sets of values (HOUR:MINUTE) match, output of the speaker pin is set HIGH
  • Tones will be played for as long as that minute has not passed

Real Time Clock

  • include “RTClib.h” and declare RTC_DS1307 RTC;
  • In setup()
Serial.begin(57600);
Wire.begin();
RTC.begin();
If it is the first time, you need to set time for RTC using
RTC.adjust(DateTime(__DATE__, __TIME__));
You do not need to reset time for it as long as coin cell battery has not been detached
  • in loop(), DateTime now = RTC.now(); can get the current time
  • now.hour(), now.minute(), now.second() can also be useful

EEPROM

  • EEPROM stands for Electrically Erasable Programmable Read-Only Memory
  • Alarm set by the user is stored using EEPROM so that alarm time is kept even if the board is not powered
  • To use EEPROM, #include <EEPROM.h>
  • To get and to store value:
EEPROM.read(<position>);
EEPROM.write(<position>);
//position(int) is the address of data

Speaker

  • tone(pin, frequency, duration) is used to play different notes
  • it generates a square wave of the specified frequency (and 50% duty cycle) on a pin

Debugging Tips

  • Make sure every switch is turned on
  • Make use of Serial.println()and check through Serial monitor to see which lines are executed
  • Introduce test LEDs into circuit and add digitalWrite(<LED pinNumber>,HIGH) at appropriate places, by looking at which LEDs light up and which do not, you may get an idea of which part of your code is buggy
  • If your sketch behaves unexpectedly, you might have run out of your memory.(“If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely.”) Solution: store data that you will not modify while program is running in flash memory instead of SRAM; to do this, use the PROGMEM keyword.
  • Google your problem
  • Ask people in forums, e.g http://arduino.cc/forum/
  • Try all random possible solutions you can think of, even if they don’t make sense at that point
  • Make sure the connecting wire is attached to the Arduino board when u are uploading the sketch
  • Make sure all the parts are as light as possible and when assembling the parts try to place the CG above the wheels
  • When RTC behaves strangely , probably the battery is detached from the breadboard, need to reset the time( sometimes / most of the times there is time lag soluion not clear yet)

[/vc_column_text][/vc_tab][vc_tab title=”Future Work” tab_id=”1389319095549-6-8″][vc_column_text]

  • Add a wave shield to allow the pet sing nicer songs
  • Add different kinds of sensors, e.g ultra-sonic sensors to enable it to avoid obstacles and heat sensors to make it react to petting
  • Develop iPhone/Android apps to control Kowheeli through phones
  • Develop a special parent-child pet combination so that when the parents of an MHC student pat their parent pet at home, the child pet in the student’s dorm will react (sing/moving around etc).

[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: Showcase

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors