Thursday, July 21

Arduserve 01's program vids

Ok, so I have found some time to put up a couple videos in which I show my two main test programs.  If you go to YouTube to watch the clips, there is a bit more information about how the program actually works.
The first program is my latest try, and after you watch the video I will give you the code. Here it is:

And here is the code:

#include [Servo.h] 
Servo Tilt; Servo Turn; 
int pos = 100,   GKLpos = 0,  GKL = 0, smthns = 10;
int thresh = 75, allwnc = 10, drkst;
void setup() 

  Tilt.attach(9);  Turn.attach(8);  pinMode(4, OUTPUT);
  Tilt.write(180); Turn.write(pos); drkst = analogRead(0);

void loop() 
{
  int AR_0;
  drkst = analogRead(0);
  digitalWrite(4, HIGH);
  // Right / Left
  for(pos = 150; pos > 0 + smthns; pos = pos - smthns)
  {
    Turn.write(pos);
    delay(150); 
    AR_0 = analogRead(0);
    if(AR_0 > GKL)
    {
      GKLpos = pos;
      GKL = AR_0;
    }
  }
  Turn.write(GKLpos);
  delay(50);
  GKL = 0;
  GKLpos = 180;
  // Up / Down
  for(pos = 180; pos > 10 + smthns; pos = pos - (smthns*2))
  {
    Tilt.write(pos);
    delay(150);
    AR_0 = analogRead(0);
    if(AR_0 > GKL)
    {
      GKLpos = pos;
      GKL = AR_0;
    }
  }
  Tilt.write(GKLpos);
  GKL = 0;
  GKLpos = 180;
  delay(1000);
  AR_0 = analogRead(0);
  if(AR_0 > drkst + thresh + allwnc)
  {
    while(analogRead(0) > AR_0 - allwnc);
  }
  else delay(2000);
}


Here is the video of the program I did before that one, you will notice that once it loses the light, it takes a while to find it again, but if the light sensor is kept in the rotational axis, the can robot can find it again much quicker than in the previous program.
And here is the code for that program:

#include [Servo.h] 
Servo Tilt;
Servo Turn;
int thresh1 = 750,
  pos = 0, smthns = 3,
  pos2 = 180;
int cont = 0, M;
int ftx = 1;
void setup() 

  Tilt.attach(9);
  Turn.attach(8);
  pinMode(4, OUTPUT);
  Serial.begin(9600);
  pos = 0;
  Tilt.write(pos2);
  Turn.write(pos);

int forctr = 0;
void loop() 
{
  //Find the x axis.
  for(cont = 0; cont < 1; cont++){
  digitalWrite(4, HIGH);
  for (M = 180; pos < M - smthns;)//turn left
  {
    if (analogRead(0) < thresh1)
    {
      pos = pos + smthns;
      Turn.write(pos);
      delay(smthns * 10);
    }
    else
    {
      M = pos + 20;
      while(analogRead(0) > thresh1)
      {
        analogWrite(A2, 200);
        delay(500);
        analogWrite(A2, 20);
        delay(200);
      }
    }
  }
  delay(100);
  for (M = 15; pos > M + smthns;)//turn right
  {
    if (analogRead(0) < thresh1)
    {
      pos = pos - smthns;
      Turn.write(pos);
      delay(smthns * 10);
    }
    else
    {
      M = pos - 20;
      cont = cont - 1;
      while(analogRead(0) > thresh1)
      {
        analogWrite(A2, 200);
        delay(500);
        analogWrite(A2, 20);
        delay(200);
      }
    }
  }delay(500);}
  //find y.
  if (pos2 > 10 + 40)
  {
    pos2 -= 40;
    Tilt.write(pos2);
  }
  else{pos2 = 180; Tilt.write(pos);}
}

P.S. I recognize that by posting my code to the public, I have given you the permission to use and modify to any extent the said code.  But, this code may not be sold without permission from me, and I would appreciate it if you would give me credit if you do use this code.  Thank you!.

Tuesday, July 19

Arduino powered Book light

I am working on a book light right now.  Sounds simple? Well I wanted to make something useful out of my Arduino and some hobby servos, so I thought of making a two axis flashlight platform, and the first use for it that occurred to me was a book light. An advanced Booklight. I might call it the Booklight 3000 or something impressive like that.  Anyway, as a book light I wanted it to be able to follow the text that you are reading, so I devised a plan that would involve a light sensor.  If I could get the flashlight to follow the light sensor, I could mount the sensor to a ring or something that you hold.  This would be one of many applications like, for instance, an intruder light that flashes an alarm and wakes you up when the door or window gets opened.

Anyway, this is my first prototype of the Arduserve bot.  I cut all the wood with a jigsaw and shaped it with one of the best multipurpose tools invented; the rotozip.  I used two servo motors, the little blue one came with the kit I got the Arduino in, and the other I got from a friend.  I put it all together with hot glue (gotta love that stuff,) and a couple nails.  This project is fairly simple and fun to build and I might post the drawings and plans for how to build it if all you readers ask for them.  Until next time - good.enough -
P.S.  In the meantime, please check out my story, The Legoton Press.