Currently I have a manually working plant which can rotate from left to right and move up and down with inputs from two potentiometers. I have been having difficulty working with the input values from the photosensor (eliminating noise) and then problems with the servo twitching and not responding correctly to the photosensor values.
int pulse = 0;
int StemServoPin = 10;
int BaseServoPin = 11;
int LED = 5;
long count = 0;
int phi[] = {100};
int theta[] = {180} ;
int buffer = 5000;
void setup() {
pinMode(StemServoPin, OUTPUT);
pinMode(BaseServoPin, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(0, INPUT);
pinMode(1, INPUT);
Serial.begin(9600);
digitalWrite(13,HIGH);
}
void pulseStemServo(int phi)
{
int time;
time = phi*10+1500;
digitalWrite(StemServoPin, HIGH);
delayMicroseconds(time);
digitalWrite(StemServoPin, LOW);
}
void pulseBaseServo(int theta)
{
int time;
time = theta*0.555+1450;
digitalWrite(BaseServoPin, HIGH);
delayMicroseconds(time);
digitalWrite(BaseServoPin, LOW);
}
int smooth(int buffer, int Pin){
long sum = 0;
for(int i = 0; i 100){
count = 0;}
count++;
phi[count] = smooth(buffer, 0);
theta[count] = smooth(buffer, 1);
Serial.print(phi[count]);
Serial.print(":");
Serial.println(theta[count]);
pulseBaseServo(theta[count]);
pulseStemServo(phi[count]);
}
These photos are of my project from Saturday.
Laser Cut Parts before assembly
some of the mounting parts
The base assembled
closeup of the stem which shows the actuator cable
My last midterm project (the interactive indo board) was cumbersome and hard to set up/transport, so for this project I wanted to make something that was easy to install and simple to set up. I thought of something that could sit in a room that people could interact with but not take up too much room or be too distracting, like an interactive decoration. So my idea was to have something that reflected a plant’s behavior, that would sense light and react.
A photosensor gets a reading of what the light is in the surrounding environment initially, and then calibrates an activation value based on this reading. When the light reaches a value that is higher than the activation value, the servo rotates a fabricated wooden gear and wooden column with a hexagonal top rises. LEDs protruding from the column light up, and the photosensor is at the top, all soldered to longer jumper wires. There are four cases to the code:
Case 1: Light is sensed as above the activation and the column is down.
The servo rotates the column up.
The LEDs light up.
Case 2: Light is sensed as above the activation value and the column is up.
The servo does not rotate.
The LEDs stay light.
Case 3: Light is sensed as below the activation value and the column is up.
The servo rotates the column down.
The LEDs turn off.
Case 4: Light is sensed as below the activation value and the column is down.
The servo does not rotate.
the LEDs stay off.
Code:
Servo servo1;
int ledPin1 = 13;
int photoPin = 0;
int ledPin2 = 2;
int ledPin3 = 3;
int ledPin4 = 4;
int ledPin5 = 5;
int readIn = 0;
int initialRead = 0;
int activateVal = 0;
int status = 0;
void setup()
{
Serial.begin(19200);
servo1.attach(15);
servo1.setMinimumPulse(800);
servo1.setMaximumPulse(2000);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(photoPin, INPUT);
blink(); //blinks the status LED
initialRead = analogRead(photoPin); //gets initial reading for photosensor
activateVal = (initialRead * 2) + 5; //the activation value will be double the initial
blink();
}
void loop()
{
Servo::refresh();
readIn = analogRead(photoPin);
//Case 1: Light Turned On (Servo move up, LEDs on)
if ((readIn >= activateVal))
{
servo1.write(0);
status = 1;
digitalWrite(ledPin1, HIGH);
lightLeds();
}
//Case 2: Light Turned Off (Servo move down, LEDs off)
if ((readIn < activateVal) &amp;&amp; (status == 1))
{
servo1.write(90);
status = 0;
digitalWrite(ledPin1, LOW);
turnOffLeds();
}
//Case 3: Lighting the same and off (Servo off, LEDs off)
if ((readIn < activateVal) &amp;&amp; (status == 0))
{
status = 0;
digitalWrite(ledPin1, LOW);
turnOffLeds();
}
//Case 4: Lighting the same and on (Servo off, LEDs on)
if ((readIn >= activateVal) &amp;&amp; (status == 1))
{
status = 1;
digitalWrite(ledPin1, HIGH);
lightLeds();
}
Servo::refresh();
}
void blink()
{
digitalWrite(ledPin1, HIGH);
delay(100);
digitalWrite(ledPin1, LOW);
delay(100);
}
void lightLeds()
{
for (int i = 2; i < 6; i++)
{
digitalWrite(i, HIGH);
}
}
void turnOffLeds()
{
for (int i = 2; i < 6; i++)
{
digitalWrite(i, LOW);
}
}
The code should read ‘#include ‘ which was an imported package used to code the servo’s rotation.
The wiring before soldering the LEDs and photosensor.
The servo attached to the gear.
The wiring after soldering.
The final product after hiding the hardware.
Parts List:
5 1 kilo ohm resistors
4 LEDs
1 photosensor
1 Hi-Tec Standard Servo
Breadboard
Arduino
Jumper wire
Bass wood, PCM board, balsa wood
Flowerpot
Here is the youtube link, but I couldn’t rotate the video after it was imported: