November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!

Assignment 6. Collision (in the program) triggers the DC motor

Project Members: 
Seung Wook Kim


- Geometric collision (in processing) triggers the DC motor as a haptic feedback.

- Connects the arduino board to a C++ based Racing Game.

- When the vehicle collides with an object, the DC motor vibrates.



- DC Motor X 1

- 1.5V AA Battery X 2 

- Resistor X 2

- Transistor X 1


[Arduino Code]

int potPin = 2;   // select the input pin for the potentiometer
int motorPin = 11; // select the pin for the Motor
int val = 0;      // variable for the output value to the game (not used herein)
int m_val = 0;  // variable for the input value from the game
void setup() {
void loop() {
  m_val =;
  if(m_val < 0 )
    m_val = 0;
  analogWrite(motorPin, m_val); // analogWrite to the motor can be between 0-255

[C++ Code (Partial)]

DWORD CCommThread::WriteComm(BYTE *pBuff, DWORD nToWrite) {
 DWORD dwWritten, dwError, dwErrorFlags;
 COMSTAT comstat;

 if (!WriteFile(m_hComm, pBuff, nToWrite, &dwWritten, &m_osWrite)) {
  if (GetLastError() == ERROR_IO_PENDING) {
   while (!GetOverlappedResult(m_hComm, &m_osWrite, &dwWritten, TRUE)) {
    dwError = GetLastError();
    if (dwError != ERROR_IO_INCOMPLETE) {
     ClearCommError(m_hComm, &dwErrorFlags, &comstat);
  else {
   dwWritten = 0;
   ClearCommError(m_hComm, &dwErrorFlags, &comstat);
 return dwWritten;




Comments from TAs

Nice job -- this project would be a good foundation for building some games using the Arduino and Processing. I like the idea of using the motor for haptic feedback -- It would be interesting to think about what it could be used for.  Could there be "productive uses", such as a mouse that vibrates when it moves over a button?  Or might there be more playful uses, such as a motor that vibrates in relation to music?

Powered by Drupal - Design by Artinet