Wednesday, September 30, 2009

Arduino Heliotropic Code

This is the code from our second project, the light source finder. Our code was mostly derived from the Arduino meets Processing project and was pretty much figured out by Michael Mathieu, a senior in MSE.

Just a note for anyone who's never looked at code before, anything inside of or after / is a comment to tell the human reader what it does.

* 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
* copyleft 2005 by Melvin Ochsmann for Malm� University
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);
// begin sending over serial port

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
// and a signal that serves as seperator between two values
// 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)

// 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;

// wait for a bit to not overload the port

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 for our group was ambient lighting, which we were able to counteract with a shade of sorts Allison and I made while in design, but in final display we could not, because of the amount of ambient light in the presentation area rendered our shade useless. We set our thresholds slightly too high for the situation that we were in, but it worked amicably for the purpose of presentation.

Thanks for reading.

No comments:

Post a Comment