Engaging the User – Arduino

Tying the lights and sensors together is the Arduino. It is the nexus of the Step Up! system, enabling the functionality that makes these system components engaging. An Arduino board is a programmable microcontroller, which can read input from sensors and write data to other electronic components. It is a versatile piece of hardware. Programming is done in a fairly high-level language, similar to Processing, making it easy to learn and work with. Using a standard USB cable, we can upload code to the board, quickly changing how it operates, allowing for multiple iterations on our prototype.

Step Up! components

Step Up! components, with Arduino in middle

From a technical standpoint, we ran power for the sensors from the 5V pin, and for the BlinkMs from digital pin 10. Since both components require 5V of power, we had to use a standard digital pin to which we would write a high value. This would supply the current necessary to run the BlinkMs. Digital pins 2-8 were used to read values from the PIR sensors, since we just wanted to know if the sensor had been tripped (value of 1) or not (value of 0). Analog pins 4 and 5 where used to address the BlinkMs, sending commands for turning specific ones on and off.

After the break is the Arduino code we developed for the project. It includes code for receiving and sending messages to a Processing program. The message received indicates that a beat was detected in the song being played, and the message sent is made up of the data detected by the sensors.

#include “Wire.h”
#include “BlinkM_funcs.h”

#define blinkm_broadcast 0x00

int currentStep;
char recvChar;
String recvCmd;

int blinkMPower = 10;

//Arduino digital pin corresponding to the PIR sensors
int step1Pin = 2;
int step2Pin = 3;
int step3Pin = 4;
int step4Pin = 5;
int step5Pin = 6;
int step6Pin = 7;
int step7Pin = 8;

//Vars for the step position
int step1Val = 0;
int step2Val = 0;
int step3Val = 0;
int step4Val = 0;
int step5Val = 0;
int step6Val = 0;
int step7Val = 0;

void setup()
{
pinMode(step1Pin, INPUT);     // declare sensor as input
pinMode(step2Pin, INPUT);
pinMode(step3Pin, INPUT);
pinMode(step4Pin, INPUT);
pinMode(step5Pin, INPUT);
pinMode(step6Pin, INPUT);
pinMode(step7Pin, INPUT);
pinMode(blinkMPower, OUTPUT);

digitalWrite(blinkMPower, HIGH);

BlinkM_beginWithPower();
BlinkM_stopScript(blinkm_broadcast);
BlinkM_setRGB( 0x00, 0, 0, 0 );
currentStep = 0;
recvCmd = “”;

Serial.begin(9600);
}

void loop()
{
//Read values from the PIR sensors
step1Val = digitalRead(step1Pin);
step2Val = digitalRead(step2Pin);
step3Val = digitalRead(step3Pin);
step4Val = digitalRead(step4Pin);
step5Val = digitalRead(step5Pin);
step6Val = digitalRead(step6Pin);
step7Val = digitalRead(step7Pin);

if (Serial.available() > 0)
{
while (Serial.available() > 0)
{
recvChar = char(Serial.read());
recvCmd += recvChar;
}

if (recvCmd.endsWith(“0”))
{
if (currentStep > 2)
{
currentStep = 0;
}

BlinkM_setRGB( 0x00, 0, 0, 0 );

switch(currentStep)
{
case 0:
BlinkM_setRGB( 0x06, 255, 0, 0 );
BlinkM_setRGB( 0x09, 255, 0, 0 );
BlinkM_setRGB( 0x0c, 255, 0, 0 );
break;
case 1:
BlinkM_setRGB( 0x07, 0, 255, 0 );
BlinkM_setRGB( 0x0a, 0, 255, 0 );
BlinkM_setRGB( 0x0d, 0, 255, 0 );
break;
case 2:
BlinkM_setRGB( 0x08, 0, 0, 255 );
BlinkM_setRGB( 0x0b, 0, 0, 255 );
BlinkM_setRGB( 0x0e, 0, 0, 255 );
break;
default:
BlinkM_setRGB( 0x00, 0, 0, 0 );
break;
}

currentStep++;
recvCmd = “”;
}
}

Serial.print(step1Val);
Serial.print(“,”);
Serial.print(step2Val);
Serial.print(“,”);
Serial.print(step3Val);
Serial.print(“,”);
Serial.print(step4Val);
Serial.print(“,”);
Serial.print(step5Val);
Serial.print(“,”);
Serial.print(step6Val);
Serial.print(“,”);
Serial.print(step7Val);
Serial.print(‘\n’);

delay(200);
}

Advertisements
This entry was posted in health and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s