Showing posts with label In-Class Project 2. Show all posts
Showing posts with label In-Class Project 2. Show all posts

Friday, September 25, 2009

Arduino Solar Detector

So, now that the project is over, I have decided to post the code that directed our Arduino units, in the interest of keeping this class as open source as possible. Our code was mostly derived from the Arduino meets Processing project.

/*
* ap_LDRAiming
*
* Reads an analog input from the input pin and sends the value
* followed by a line break over the serial port.
*
* This file is part of the Arduino meets Processing Project:
* For more information visit http://www.arduino.cc.
*
* copyleft 2005 by Melvin Ochsmann for Malm� University
*
*/
#include
Servo myServo;

// variables for input pin and control LED
int PhotoA = 3;
int PhotoB = 4;
int PhotoC = 5;
int LEDpin = 13;
int pos = 0;

// variable to store the value
int valueA = 0;
int valueB = 0;
int valueC = 0;
// a threshold to decide when the LED turns on
int threshold = 750;
void setup(){

// declaration of pin modes
pinMode(PhotoA, INPUT);
pinMode(PhotoB, INPUT);
pinMode(PhotoC, INPUT);
pinMode(LEDpin, OUTPUT);
myServo.attach(9);
// begin sending over serial port
Serial.begin(9600);
}

void loop(){
// read the value on analog input
valueA = analogRead(PhotoA);
valueB = analogRead(PhotoB);
valueC = analogRead(PhotoC);

// if value greater than threshold turn on LED
if (valueA <>

// print out value over the serial port
Serial.print(valueA);
Serial.print(",");
Serial.print(valueB);
Serial.print(",");
Serial.print(valueC);
// and a signal that serves as seperator between two values
Serial.print(";");
// Checks if right is greater than left, if so move to right.

if (valueB > (valueC +20))
// +20 is the deadzone, so it wont jiggle back and forth.
{
if (179 > pos)
pos++;
myServo.write(pos);
}

// Checks if left is greater than right, if so move to left.
if (valueC > (valueB +20))
// +20 is the deadzone, so it wont jiggle back and forth.
{
if (pos > 1)
pos -= 1;
myServo.write(pos);
}

// wait for a bit to not overload the port
delay(10);
}

The code includes a serial input that we used to judge whether or not our solar detection was working properly in a numerical sense. By slowing the program down to a delay of 250, we were able to tweak the code in order to ensure that the readings were proper, and that we could utilize the changes in direction properly.

The biggest issue was ambient lighting, which we were able to counteract with a shade of sorts while in design, but in final display we could not, because of the amount of ambient light in the center room. We set our thresholds slightly too high for the situation that we were in.

Friday, September 18, 2009

SmartSurfaces, Day Two, 9/18/09

Day two was a massive improvement over day one, in every way.

We led out by introducing my lamp, which was pretty awesome I suppose, but I didn't expect to be in the spotlight for it... other people had much better lamps, especially the rangefinder - that was extremely impressive.

I am a huge fan of the work with physical computing, and I have been experimenting with the Arduino since we got it. I found a program called Processing, which can be set up to interact with inputs from the Arduino and uses the data for other things, such as compiling graphics. I intend to look deeper into this, hopefully designing an extremely neat program.

Day Two: Project

Our project for the day was to design and construct a light tracking device utilizing photoresistors to detect where a light source is. We were divided into groups, and almost immediately our group was off to the races. I had been working with code for Processing which interacted with the photoresistors, and was able to help jumpstart the coding. Marc and Damien jumped into developing the code for interacting with the servos, and the remaining members of the group either helped me work with the photoresistors or worked with the cardboard, whatever was needed.

The worst part about this project was the amount of time given - we only had an hour, and only discovered the code for the servos existed already 45 minutes in. Our group pulled together well, however. Everyone did their parts, and we were able to come up with a finalized design with finalized code, at the very least, even though we did not construct the actual unit completely. Other groups were in approximately the same boat as us.

After the presentations, we were told to meet later on to finish construction of our unit. We met Sunday night, and after a couple of extra hours and several wires that wouldn't stay where we wanted them, we were able to construct our unit and get it operational, if a little jittery. The unit will track light, though it is not the best at tracking small point light sources - it is just not feasible without a full array of sensors. Also, ambient light is the enemy of this project, so we built a shade for it in order to keep ambient light off of it.

I felt our group worked much better than last week's group. There was a definite cohesion, everyone knew what they had to do, and there were very few moments where someone was 'lost'. The work got done, and we were all very proud of the final result.

Day Two: Thoughts Going Forward

I have worked with Allison twice now, and I am hoping she winds up in my final group - she has done a great job each week to learn quickly when she doesn't understand and to do what needs to get done when she does. She brings great ideas to the table, and has been a valuable member of each group.

I feel like the Arduino is going to be great to work with, and look forward to whatever this class has in store for us next. I haven't quite gotten to play with Design Studio, that is my next project, for tomorrow.