Thursday, June 2, 2011

New Project

I got my H bridge IC a little while ago, but I've been a bit too lazy to get it going on my sun tracker. The whole sun tracker project is not really to my standards anyway. Using Lego is great and all, but there's just something about how it looks and functions that irks me. I've decided to cease progress on the sun tracker until a later date when my interest is restored.


Along with the H bridge, I got 4 N-channel MOSFETs. They're basically transistors that can be used to switch high-powered circuits. I've wanted some of these for a while, but so far I haven't had a real use for them. Also, I might have a problem using them on their own. It turns out that in order to switch a high load, the gate voltage must be greater than the drain-source voltage. This means that I might have to get a charge pump circuit in order to switch a high voltage circuit with a lower voltage. We shall see.


What I'm really excited about is that I also got a laser module! It's a 5mW class IIIa green laser. If it was class IV, then I probably wouldn't be able to purchase it. This thing is super bright, and it operates at 3 volts. Remember that CNC machine setup with the stepper motors? Well, I've re-purposed it into a laser light show machine.  I attached small mirrors to the motor shafts, and I run the motors in tandem, back and forth with very little rotation. This results in a sort of mirror vibration, which I can control with the Arduino timing structures. The system is not fully functional right now and makes too much noise while vibrating, hence there will be no pictures until the next post. Hopefully I can get everything functioning correctly so I can produce laser light show patterns.

Wednesday, May 18, 2011

Solar Tracker

That's right, a solar tracker. The principle behind it is quite simple: automatically point directly at the sun throughout the day. As the sun arcs across the sky, a solar tracker adjusts its azimuth and altitude in order to, say, keep a solar panel facing the sun at all times. I had all the parts necessary to make a working solar tracker, so I did.


I fiddled around with gearboxes and wood and scrap plastic pieces until i came up with this monstrosity:

And after determining that this thing was awful at doing anything but fall apart, I decided to whip out the trusty Legos:
It ended up being an even bigger monstrosity. Admittedly, the bulk of the Legos just control the azimuth drive. The altitude is controlled by a non-Lego servo motor, strapped onto that black beam with a rubber band. There are two photocells that I stuffed down those (olive colored?) tubes at the top of the gray beam. All of the electronics are connected through that breadboard for now. I'm not really planning on making this a permanent installment; it's just a fun project that I wanted to do.


You may be asking why I stuffed photocells down some tubes. I think it's time for a diagram:
As the servo changes the angle of incidence of the sun's rays, the photocells change resistances. The reason why there are two of them is to measure a difference in light levels. If one cell is getting more sunlight than the other, the altitude adjusts so that the difference between them is a minimum. They are offset both in altitude and azimuth, so the light levels in each will dictate which way the tracker moves. I haven't yet considered adding a third photocell for "triangulation" because I have yet to test the machine in automatic mode. I have a feeling that the addition of a third photocell exposed to ambient light will give better control of directionality. 

If you noticed in the picture, the azimuth drive is powered by a big Lego battery pack (~9V) which has two red buttons. The buttons control which way the Lego motor spins. Not very automatic, huh? This is the main reason why I haven't tested or calibrated the tracker. I am waiting for an order from Sparkfun that contains among other things an H-bridge IC (integrated circuit). An H-bridge is essentially a digitally-controlled version of those two red buttons. The Arduino will be able to toggle the direction of the Lego motor with the H-bridge.


I did write a little sketch for the Arduino so that I could see what values the photocells were sensing, and a rudimentary altitude control using that big black knob attached to a potentiometer.

#include <Servo.h>
 
Servo myservo; 
 
int potpin = 2; 
int cellone = 0;
int celltwo = 1;
int val;   
int val2;
int val3;
int val4;
 
void setup()
{
  myservo.attach(3); 
  Serial.begin(9600);
}

 
void loop()
{
  val = analogRead(potpin);
  val2 = map(val, 0, 500, 0, 179);
  myservo.write(val2);
  val3 = analogRead(cellone);
  val4 = analogRead(celltwo);
  Serial.print(val2);
  Serial.print(",");
  Serial.print(val3);
  Serial.print(",");
  Serial.println(val4);
  delay(50);
 
}
OK, you might be thinking that I spent very little time on this project, and you'd be right. I built the Lego part and wired it up within a half-hour. I even modified some servo control code that I wrote earlier. The upcoming coding after I get that H-bridge shouldn't be too hard to do, but it might take me longer than a half-hour. I'll keep you updated in the next post.


Link to Sparkfun. Awesome site for just about any DIY electronics.

Monday, May 16, 2011

CNC Milling Machine

OK, so this milling machine project has gotten pretty out of hand. I know what I want to do with it, but getting it to work with my hardware setup is difficult. This is what I have so far:


And the parts list:
  • 2 EasyDriver motor drivers from Sparkfun
  • 2 12V 4-wire bipolar stepper motors from Sparkfun
  • 1 12V small fan
  • 1 slide switch
  • 2 LEDs with 2 220K resistors
  • 1 small flyback diode
To power the motors and fan, I am using a 12V, 1000mA wall wart transformer that I found in our shop. The EasyDrivers take that power and sink it through the H-bridge circuits to the motors, as well as through a 5V regulator for on-board logic. The H-bridge circuits and voltage regulator get really hot from all that power, so that's the reason I have a fan blowing on both of them. The fan gets good airflow, and I'm able to keep it running indefinitely without anything getting too hot.

To run two motors at a time, I wrote a small sketch that alternates movements between the two motors. The control of a motor is wrapped up in a for loop, so there is no way to run two stepper motors simultaneously. For example:


 for (int j = 0; j<steps1[i]; j++)       
    {
      digitalWrite(steppin1, LOW); 
      digitalWrite(steppin1, HIGH);

      delayMicroseconds(spd1[i]);                                
    }
    for (int k = 0; k<steps2[i]; k++)      
    {
      digitalWrite(steppin2, LOW); 
      digitalWrite(steppin2, HIGH);

      delayMicroseconds(spd2[i]);                         
    }



The steps1, steps2, spd1, and spd2 are just arrays of values that I was using to test the motor movements. As you can see, the program runs through the first loop then the second, not at the same time. The only way to run them at the same time would be if they were moving for the exact same number of steps and speed. I'm not sure how to deal with that at the moment.


Another option aside from writing my own code is to find someone who has written it already. That is the beauty of Arduino: people post their projects on the web and give you access to the code. I found a project that a group of people have been working on called "RepRap." The RepRap is a self-replicating 3D printer, meaning it can print plastic parts that can then be used to build another RepRap. And it runs on an Arduino sketch! The only difference between a RepRap and what I want to do is that the third "axis" on the RepRap is a thermoplastic extruder. All I have to do is modify the RepRap code to run three stepper motor axes. And as it turns out, someone already did that, too. I still have to modify the code though because their hardware is a little different than mine.


Phew, all that and I still have to find a way to draw parts to mill (I'm thinking Google Sketchup), a way to generate a toolpath, a way to generate G-code from the toolpath, and a way for an Arduino sketch to read G-code (probably through serial using another application). Finding a way to do all of that will be very difficult. It might be a while before I actually implement anything for this project, so I'll probably talk about my other project in my next post. What is it? Well, all I will say is that it has to do with the sun.

Tuesday, May 10, 2011

Everybody run! It's a Blog!

Well, I never thought I'd be writing a blog. Writing blogs is like scattering your thoughts to the wind. A very powerful wind at that. Anyway, this blog is about all the things I make in my new hobby. I've been posting all of my previous creations on Facebook, but it wasn't a very good outlet for this kind of stuff, and probably just clogged up peoples' News Feeds. Call it what you want: physical computing, electronics, programming; it all boils down to my adventures with this guy:
This is the Arduino Uno. It is an open-source microcontroller that uses an Atmel ATmega328 microprocessor as its "brains." The Arduino has 13 digital input/output pins (6 of which are PWM, more on that later) and 6 analog input pins. There are also some power pins that you can power small circuits with.


To make the Arduino do what you want, you basically plug it into your computer and start programming away. Luckily in college I took a course in C programming, which just so happens to be the programming language that Arduino "sketches" are written in. Here is a snapshot of the Arduino IDE (Integrated Development Environment) where I write all my code:





As you may or may not have seen, I've already crafted a bunch of things that utilize the Arduino:
  • Anemometer
  • Temperature Logger
  • Infrared sensor with remote control hacking
  • LCD display
  • Binary Counter
I may come back to those in future posts and kinda go through them, but I'll likely move on to bigger and better things. Right now I'm working on a tabletop CNC milling machine. It is a massive undertaking for me, because I'm basically starting from scratch and Arduino-based milling machines are pretty sparse on the intertubes. I think I'll save that project for my next post.


For more information on Arduino or if you want to know what the dickens I'm talking about, here is the Arduino website.