Showing posts with label servo motors. Show all posts
Showing posts with label servo motors. Show all posts

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 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 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.

Smart Surfaces and Heliotropic Systems

A quick update on week 2-3. We've moved along with arduino learning how to program it using photocells and servo motors to follow a light source, which is quite cool actually, I'm still at the "gee-whiz! It moves!" stage of physical computing. I really think they should teach physical computing in Physics 240 (electromagnetic physics and includes circuits) and Engin 101 (programing). Learning how to manipulate code to actually have a physical result is much more engaging than the same old compile, run, debug, compile, run, "hello world!'.

Anyway, all of this is leading into heliotropic systems (following the sun, like sunflowers).

Our light source tracker!

The bread board and all the wires inside the base.

We had two servo motors moving our contraption. One on the horizontal (x-axis) making it rotate and follow side to side and the other on the vertical (y-axis) following up and down.

For a quick video of it mostly working (too much ambient light, we set our light threshold a bit to high). Check out my group member, Damien's, flickr site here. Her blog can be found here.
Related Posts with Thumbnails