Friday, May 30, 2014

itWORKS

Everything put together and running!!!!


Final Arduino Code

I finally got the code to work and do everything I want (mostly)...


// Perpetual Windmill USB Charger for Arduino
// Kyle Thatcher
// Last Modified -- May 30, 2014

////////////////////////////////////////////
////////////////////////////////////////////
#include <Servo.h>

int pinMill = A0;  // input pin for the brushless motor phase sensor
int sensor[] = {0,0};  // stores the current sensor reading [0] and the previous sensor reading [1]
long i = 0;  // keeps count of revolutions of mill motor
long millRPM = 0;  // stores the RPM calculated from the mill motor's phase sensor
unsigned long t[] = {0,0};  // the elapsed time [0] and previous time at elapse [1]

Servo fan;  // creates a servo object
int pinFan = 9;  // output pin for PPM (servo) fan motor ESC
float battVolts = 7.4;  // the nominal voltage of the battery in use (7.4 or 11.1)
int kV = 1000;  // the kV value (RPM/Volt) of fan motor
int fanRPM = 0;  // stores the fans intended RPM
int maxFanRPM = 1000;  // the maximum fan RPM desired
int initVal = 18;  // the minimum value that the ESC will use
int val;  // the PPM value (18-179) to output to the ESC

int pinUSB = 4;  // the output pin for controlling USB charging port


////////////////////////////////////////////
void setup()
{
  pinMode(pinMill, INPUT);
  fan.attach(pinFan);
  pinMode(pinUSB, OUTPUT);

  fan.write(initVal);
  digitalWrite(pinUSB, LOW);

  Serial.begin(9600);
  Serial.println("Initializing");
}


////////////////////////////////////////////
void loop()
{
  // What is the mill's RPM //
    sensor[0] = digitalRead(pinMill);
    if ( sensor[0] == 1 && sensor[1] == 0) ++i;
    sensor[1] = sensor[0];
    t[0] = millis() - t[1];
    if ( t[0]  >= 200 )
    {
      millRPM = 1000 * i / t[0];
      i = 0;
      t[1] = millis();
    }


  // Control ESC (fan speed) values from 18-179  //
    if ( millRPM >= 15 )
    {
      //fanRPM = 2 * millRPM;
      //if ( fanRPM > 100 ) fanRPM = 100;
      //val = ( fanRPM * 255 ) / ( kV * battVolts );    
   
      val = 75;
    }
    else
    {
      val = initVal;
    }
 
    fan.write(val);


  // Control USB Charging Port //
    if ( millRPM >= 20 ) digitalWrite(pinUSB, 1);
    else digitalWrite(pinUSB, 0);
    //digitalWrite(pinUSB, 1);


  // Print Debug Values //
    //Serial.println(millRPM);


  delay(1);


}

////////////////////////////////////////////
////////////////////////////////////////////

Thursday, May 29, 2014

inConstruction

I finally got all my parts laser cut from the Acrylic. Yesterday I solvent glued together the base. Now on to the fun part. 


Here I am set up at home with all the circuitry components laid out and ready to solder together.

Wednesday, May 28, 2014

Initial Arduino Code

The process of developing the Arduino code has also a great way for me to organize my ideas. It forces me to write down there verminous aspects of the project in a symbolic, systematic and sequenced structure. My initial


// Perpetual Windmill USB Charger for Arduino
// thatchek
// Last Modified -- May 28, 2014

////////////////////////////////////////////
////////////////////////////////////////////

int pinRPM = 7;  // input pin for the brushless motor phase sensor
int sensor[] = {0,0};  // stores the current sensor reading [0] and the previous sensor reading [1]
long i = 0;  // keeps count of revolutions of mill motor
long millRPM = 0;  // stores the RPM calculated from the mill motor's phase sensor
unsigned long t[] = {0,0};  // the elapsed time [0] and previous time at elapse [1]

int pinMotor = 9;  // output pin for PWM fan motor ESC
float battVolts = 7.4;  // the nominal voltage of the battery in use
int kV = 1000;  // the kV value (RPM/Volt) of fan motor
int fanRPM = 0;  // stores the fans intended RPM
int maxFanRPM = 1000;  // the maximum fan RPM desired
float fanVal = 0;  // the PWM value (0-255) to output to the ESC

int pinUSB = 4;  // the output pin for controlling USB charging port


////////////////////////////////////////////
void setup()
{
  pinMode(pinRPM, INPUT);
  pinMode(pinMotor, OUTPUT);
  pinMode(pinUSB, OUTPUT);
  digitalWrite(pinUSB, LOW);

  Serial.begin(9600);
  Serial.println("Initializing");
}


////////////////////////////////////////////
void loop()
{
  // What is the mill's RPM //
    sensor[0] = digitalRead(pinRPM);
    if ( sensor[0] == 1 && sensor[1] == 0) ++i;
    sensor[1] = sensor[0];
    t[0] = millis() - t[1];
    if ( t[0]  >= 200 )
    {
      millRPM = 1000 * i / t[0];
      i = 0;
      t[1] = millis();
    }


  // Control ESC (fan speed) values from 0 to 255 //
    if ( millRPM >= 10 )
    {
      fanRPM = 2 * millRPM;
      if ( fanRPM > 500 ) fanRPM = 500;
      fanVal = ( fanRPM * 255 ) / ( kV * battVolts );
    }
    else
    {
      fanVal = 0;
    }
    analogWrite(pinMotor, fanVal);


  // Control USB Charging Port //
    if ( millRPM >= 50 ) digitalWrite(pinUSB, HIGH);
    else digitalWrite(pinUSB, LOW);
 

  // Print Debug Values //
//    Serial.println();


  delay(10);


}

////////////////////////////////////////////
////////////////////////////////////////////

Learning?

Reflecting on my design process thus far, I find myself rather disappointed... and I am realizing that this tends to be the norm for me. I am disappointed that I seem to always start a project with a ambitious goals. I incorporate a certain robust elegance into my designs. However, as it always happens, time and money decidedly ruin the day. I must learn to better optimize my design path in order to incorporate a cost effectiveness into my process. I think if I can manage to start with this as a design criteria, it may influence my creative drive to strive for economy.

Never the less, I am interested in witnessing the reactions to my Perpetual Windmill. I have never used my engineering background to produce a product solely for artistic value. This have been a challenging yet very rewarding experience for my educational development.