Go Down

Topic: Arduino Lightsaber (Read 407821 times) previous topic - next topic

billpealer

I believe the 3.3V on a Nano comes from the FTDI chip, and is only capable of 50mA.
that actually may be the case.
But the ADXL335 has a low min operating current of...  350 μA.
50ma would do it. right?

I like the nano. i love the ease of USB connectivity and sending the 8.2v direct to the RAWpin, and 5v RIGHT to the WT via VCC.  i hate soldering.  we are a good match :)

JakeSoft

that actually may be the case.
But the ADXL335 has a low min operating current of...  350 μA.
50ma would do it. right?

I like the nano. i love the ease of USB connectivity and sending the 8.2v direct to the RAWpin, and 5v RIGHT to the WT via VCC.  i hate soldering.  we are a good match :)
I'm sure you'll be very happy together.  :D 

billpealer

#452
Jan 16, 2016, 01:23 am Last Edit: Jan 16, 2016, 01:28 am by billpealer
Ha!


i tried to make that smaller.

jonnieZG

#453
Jan 16, 2016, 09:00 pm Last Edit: Jan 17, 2016, 03:24 pm by jonnieZG
Just wanted to give something back to this great community:

Well, here's my LED driver, in fact 3 of them, one for each RGB channel. Each one will get its own thermal-shrinking insulation sleeve.


Red and black wires above are LED outputs, red and black wires below are power in, naked wire is the PWM switch input

This is a current source based on one N-MOSFET (T1) and one NPN transistor (T2):



The principle is very simple: the current that comes out from the Source pin of the T2 (S) must be the same as the one as enters the Drain pin (D), since current that enters the Gate (G) is zero. Therefore, by controlling the Source current we control the current through the LED, no matter the voltage on the LED. Setting the source current is fairly easy, since the BE voltage on a transistor is always around 0.5 V and the current that enters the T1 Base pin is also around zero. Therefore, the current through the R2 is Is=Ube/R2, that is R2=Ube/Is

So, if we want the current to be 700 mA, then the R2 has to be 0.5V/0.7A~0.7 Ohm! No matter the battery voltage, as long as it is above some 3.5 V, depending on the voltage on the LED. In practice, the current slightly depends on the input voltage, but does not depend at all on the diode voltage (or any consumer connected between Vcc and the Drain, for that matter), which is exactly what we need, since the diode voltage dramatically changes with the temperature. This way we completely override the problem with the changing voltage on the diode.

This is the Vcc-Current chart of the driver, driving one blue LED:


I used two 0,6 W resistors - 1 Ohm and 1.5 Ohm, resulting in 0.6 Ohm. Even though I used the same components in all the 3 drivers, the current varies from one to another from 0.70A to 0.73A - so you can see how it is hard to tweak. Fortunately enough, that does not affect the light intensity that much and it is still in the safe zone.

Now about switching the LED on and off: when the Gate pin is pulled up to Vcc, the Gate opens and the current flows. When the Gate is pulled down to 0V, the Gate closes and the current through the LED stops. That is done through a 100 kOhm resistor to minimize the pull-up current. By connecting it to a PWM signal from your controller, you can regulate the resulting current and the intensity of the light.

But, there is a caveat here - resistors that small are a pretty tricky thing to work with, because the very contact resistance between two wires ranges from 0.2 Ohm when not welded together (depending on the pressure used to hold them together and the properties of the wire) to around 0.05 Ohm when welded. And that's on each contact! So forget about testing it on a prototype board - you will just have to weld them directly on the other components as I did on the photo above, and tweak the resistors to get the right current.

Don't forget to insulate the pins with thermal-shrinking insulation sleeves to prevent wires from breaking off and short circuiting!

Components:
  • T1 : any N-MOSFET with a T-220 package (IRFZ44N)
  • T2 : any NPN transistor in a TO-92 package (BC337-40)
  • R1 : 100 kOhm, at least 1/4 W
  • R2 : 0.6 to 0.7 Ohm, at least 1/2 W - I used one 1 Ohm and 1.5 Ohm in parallel

Power dissipation considerations: Bare in mind that all the voltage difference between the input voltage and the voltage on the diode, minus 0.5 V on the R2, remains on the T1 FET, producing possibly significant heat (P = U * I). For example, if you power it with a 7V input and the voltage drop on the LED is 3.2V, then the remaining voltage on the T2 is 3.3V, producing 3.3*0.7 = 2,3 W which is quite much. If you keep it at 4.5V, then the power dissipation on T2 would be only about 0.5W. Therefore, keep the driver input voltage as low as possible!

Important note on pinout: The black output line is the floating one, while the red output is the same point as the power input! Therefore, when using several drivers in parallel, you must connect all the anodes of the LEDs to Vcc, and cathodes to the driver's black output line!

Important note on handling FETs: FETs (MOSFETs) are very sensitive components and are very easy to damage if you are not properly grounded. It is also likely that you'll burn it (electrically, not thermally) with your soldering iron. You'll now you did it if you notice that you cannot properly fade your LED: with a healthy MOSFET the light goes linearly up from 0 to 100%, while on a burnt one the LED will start lighting up at about 75% of PWM input level. Therefore, it is necessary to wrap all 3 pins with a piece of naked wire short-circuiting all pins, while you are soldering it. Once all the components are in place, you can wrap-off the short-circuiting wire.

billpealer

Johnnie, could you show a current (amps) read on a multi meter showing the 700ma for that set up?

jonnieZG

"I find your lack of faith disturbing..." ;)


billpealer

is that a 4x AA ? alkaline?

JakeSoft

#457
Jan 17, 2016, 05:36 am Last Edit: Jan 17, 2016, 05:47 am by JakeSoft
This is something I hacked together in PhotoShop using Canobi's drawings as a reference. It's only meant to express concepts, but maybe someone more savvy could turn this into a real board by drawing it in PCB design tools that I don't know how to use.

This is intended to be the easy button; the most accessible, simple to build PCB that I can think of for an end user to assemble and still get full functionality. Anything that makes it complicated got tossed out in favor of simplicity. It's not the highest performing or the most flexible. It won't please everyone or accommodate every combination of parts. It's not the loudest. It's not supposed to be any of those things. It is what it is and nothing more. Simple.



Click here for high-res image

Key Features:
- 100% through-hole components.
- Minimalist design: Everything you need, nothing you don't
- Should be pretty easy to produce; only one jumper that could be end user installed
- Uses Canobi's pinout
- LDO regulator mounted under the WT588D to save space
- WT588D assumed to be mounted on pin-headers or a socket interface to facilitate removal for reprogramming without any non-standard hardware
- Arduino right-angle pin headers assumed to be available for reprogramming at the edge of the board over the FETs
- Pure 3.3V design eliminates dual-voltage power distribution complexities
- Narrow parts list removes parts selection ambiguity
- Only easy-to-find, commonly available parts are required
- Compatible with both ADXL335 accelerometer or SW-200D swing sensors

Parts:
- Arduino Pro Mini 3.3V
- 3.3V LDO Voltage Regulator (up to TO-220 size, >= 500 mA output)
- WT588D 16p
- GY-61 ADXL335 Accelerometer (Or SW-200D Swing Sensors)
- I-PAK style N-channel MOSFETs (1 to 3, depending on how many channels you want)
- SW-18020P impact sensor (mounted off the board)

I know I am probably off on the dimensions a few places. Like the holes for the main LED negative vias at the end of the board probably need to be moved left a bit to clear the FETs, but I think something like this would be good. It doesn't require any advanced soldering skills and could be built with a cheap iron without an especially fine tip. A decent high school student could probably build the board in an afternoon. A skilled person could do it in an hour or less.

With some modifications to the power distribution, a separate version could be made 5V capable to support Nanos and 5V Pro-Minis.

Feedback welcome. (Please read the second paragraph of this post before posting feedback, please.)

jonnieZG

is that a 4x AA ? alkaline?
No, that's 4xAA NiMH, resulting in 5,1 V. I added a current-vs-voltage chart in my original post (#455), which you might find useful.

I have not yet decided how I will power the driver, since I want the voltage to be around 5V. I will probably use a 3.3V Arduino with one down-switching buck stabilizer for the Arduino and another one down to 5V for the LED drivers.

The idea is to use switching-stabilizers rather than the semi-conductor based ones, since power dissipation is significantly lower.

Kamensky

Dear Jedi (or almost Jedi), i rly need some help with writing code. I'm using MPU-6050 accelerometer+gyro, so i'm incredibly dumb at this thing. I would appreciate any help with at least building an algorithm for triggering sound. And it would be sooo amazing, if someone here already has worked with MPU-6050 or just can share the code for it. Prayin' for your help :)

stinky1

#460
Jan 18, 2016, 04:02 am Last Edit: Jan 18, 2016, 04:11 am by stinky1
I have this saved as PROTONERD LED STRING CODE (ARDUINO NANO, MP3-TF-16P, MPU6050 GYRO)
I believe that this is just the MPU6050 gyro code, but don't quote me as I have like 0 so far work done with arduino,  parts on the way........ link is in post #53 and is ryang's not Protonerds.

Arduino Lightsaber for/with LED string blade





#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>

MPU6050 accelgyro;
int16_t ax, ay, az;    // define accel as ax,ay,az
int16_t gx, gy, gz;    // define gyro as gx,gy,gz
int16_t px, py, pz;    // previous accel settings
long x, y, z;
long accel;         // calc accel

int inPin = 9;         // the number of the input pin
int outPin = 10;       // the number of the output pin
int ledPin = 11;

int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

int track = 20;
int prev = 20;

boolean state = false; // the current state of the circuit

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 500;   // the debounce time, increase if the output flickers
long looptime = 0;     // the last time the loop was played
long gtime = 0;

SoftwareSerial mySerial(0, 1); // RX, TX

void setup()
{
  Wire.begin();              // join I2C bus
  //Serial.begin(38400);       // initialize serial communication
  //while (!Serial);           // wait for Leonardo enumeration, others continue immediately
  Serial.println("INIT");
  accelgyro.initialize();

  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
 
  mySerial.begin(9600);
  mp3_set_serial(mySerial);  //set Serial for DFPlayer-mini mp3 module

  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  reading = digitalRead(inPin);
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);   // read measurements from device

  if(millis() - gtime > 500) {
    x=px-ax; y=py-ay; z=pz-az;
    x=abs(x); y=abs(y); z=abs(z);
    accel = (x+y+z);
    px = ax; py = ay; pz = az;

    if(state && accel > 15000) {
      mp3_play(random(31,34));
        //analogWrite(outPin, 255); delay(100);
        //analogWrite(outPin, 50); delay(100);
        //analogWrite(outPin, 255); delay(100);
        //analogWrite(outPin, 200); delay(100);
      looptime = millis()-2000;
    }

    Serial.print(gx);Serial.print(" ");Serial.print(gy);Serial.print(" ");Serial.println(gz);
    Serial.println(accel);

    gtime = millis();
  }
 
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (!state) {
      digitalWrite(ledPin, HIGH);
      looptime = millis();
      mp3_play(1);
      for(brightness = 0; brightness < 200; brightness++) {
        analogWrite(outPin, brightness);
        delay(16);
      }
      state = true;
    } else {
      mp3_play(2);
      for(brightness = 200; brightness > -1; brightness--) {
        analogWrite(outPin, brightness);
        delay(7); 
      }
      digitalWrite(ledPin, LOW);
      state = false;
    }
    time = millis();   
  }

//  if (state && millis() - looptime > 4000) {
//    while (track == prev) {
//      track = random(21,24);     
//    }
//    mp3_play(track);
//    prev = track;
//    looptime = millis();
//  }
 
  previous = reading;
}

JakeSoft

I have this saved as PROTONERD LED STRING CODE (ARDUINO NANO, MP3-TF-16P, MPU6050 GYRO)
I believe that this is just the MPU6050 gyro code, but don't quote me as I have like 0 so far work done with arduino,  parts on the way........ link is in post #53 and is ryang's not Protonerds.

Arduino Lightsaber for/with LED string blade

This is clearly more than the gyro code. This looks like an entire sketch which won't work without the MPU6050.h header file. Provided you had that, then maybe some examples could be gleaned from this code.

ryang

This is clearly more than the gyro code. This looks like an entire sketch which won't work without the MPU6050.h header file. Provided you had that, then maybe some examples could be gleaned from this code.
Yeh, it's the complete code - including unused parts... :P

MPU6050.h can be found here;
https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/MPU6050.h

And more details here;
http://playground.arduino.cc/Main/MPU-6050

Also needs the DFPlayer code from here;
http://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299

iamearlgrey



Click here for high-res image


This is fantastic. I understand the connections much more now. I've been trying to rebuild the schematic to make a gerber file for production, but I am still learning the tools. Are the resistors off the board and connected between the led and the board? I'm also trying to figure out all of this code on my own with only a virtual arduino. Anyway, great job.

Protonerd

that actually may be the case.
But the ADXL335 has a low min operating current of...  350 μA.
50ma would do it. right?

I like the nano. i love the ease of USB connectivity and sending the 8.2v direct to the RAWpin, and 5v RIGHT to the WT via VCC.  i hate soldering.  we are a good match :)
I supply the MPU6050 using the 3V3 output from the FTDI and no issue, although the MPU should be more power hungry. So it's a match.

Go Up