Show Posts
Pages: [1]
1  Using Arduino / Motors, Mechanics, and Power / Stepper motor not working as expected on: January 31, 2014, 10:43:06 pm
Ok, I'm trying to control a stepper motor (link) through a ULN2004 transistor array. I'm following the circuit diagram on this page, the 4-pin one since mine has 4 coil wires and two common wires. From what I can gather, the white and yellow wires should be common, and the black, red, green, and blue wires are powered in that order to rotate the motor. Originally, I thought it should go black-green-red-blue, but when I manually powered it in that order, it didn't work. When I go black-red-green-blue, I can feel an even rotation in one direction. When I have the yellow and white to +12v, the other four in 16, 15, 14, and 13, (of the array, not the arduino) and gnd of the transistor array connected to the negative battery pole, it functions as expected, sort of. I can connect pins 1, 2, 3, and 4 of the array to +12v sequentially, and each successive coil in the motor activates. The problem is that when I connect the common pin of the array to +12v, as in the diagram, the motor locks up, which I assume means that all the coils are active. My first thought was that perhaps the arduino has to pull each pin successively down to ground to activate that coil, but with pins 1, 2, 3, and 4 all connected to ground, nothing changes. Throwing caution to the wind, I plugged them all to +12v, but still no dice. The other strange thing is that with the common pin disconnected, I can activate each coil by powering pins 1, 2, 3 or 4 to +12v, but connecting one of them to +5v on the arduino does nothing. I thought this transistor could be activated by 5v, no? Anyway, as it stands, I suspect the fault lies with my inadequate understanding of transistors and/or stepper motors. Any help would be greatly appreciated.
2  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 11:07:29 am
You didn't have to, but it would do no harm.

Hmm, well it didn't work before I type cast it. Oh well, it works. Anyway, thanks guys for all the help!
3  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 11:01:42 am
Got it working, it had to do with the fact that sVal was assigning improperly due to being an integer. I mad sVal a float, and it started working, but I had to type cast sVal to int in the myservo.write statement.
4  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 10:04:08 am
Ok, I tried what you said, the servo moves as expected, and the message prints just fine. Now I will try bringing back the servo related bits of the void loop and see what happens.
5  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 08:20:26 am
Well, that would do it. Any other ideas about the servo?
6  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 08:10:09 am
Yes, I see your point, but no there is no carriage return at the end of transmission. If I create a program that just  relays information from one serial to another, I just get a long string of numbers separated by 'E's. Also, I know that's not the case because the data being printed to the computer would also be screwed up, but it's not. About the precision, I am wondering what would cause there to be a difference between calculating hundredths and printing hundredths. By the way, thanks for the help so far.
Just for clarity, here is the python script on the phone:

Code:
import android, time

BT_DEVICE_ID = '00:12:09:13:97:48'

droid = android.Android()
droid.bluetoothConnect('00001101-0000-1000-8000-00805F9B34FB', BT_DEVICE_ID)
x = 0
while x<100:
droid.startSensingTimed(1, 25)
time.sleep(0.1)
s4 = droid.sensorsReadAccelerometer().result
droid.stopSensing()
ret = round(s4[1], 3)
droid.bluetoothWrite(str(ret)+"E")
print(ret)
x += 1

exit()
7  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 07:59:46 am
Au contraire, mon ami. I have explained exactly where the data is coming from. It originates in an android phone, it is sent by a python script to the JY-MCU bluetooth module connected to the Serial1 input of the Arduino Mega 2560. The data received by the bluetooth chip is sent to the arduino, fed into a character array until the program hits the end character 'E', then it converts the character array to a floating point number, maps it to the servo's range of 0 to 179, and sends it to the servo via myservo.write(sVal). The data is sent to the computer via Serial both before and after mapping and appears to be correct. Another possibly related issue is that I have the program set up to go to the thousandths place on the float value, but I appear to only be getting hundredths. For a specific example, refer to my second post.
8  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 07:43:11 am
Paul, yes, but this servo is not under load, as I am just testing it. As to the input, my thoughts exactly. Read my first two posts to see what the input is.
If I set it to 0, then it goes to 0 and stays there for the duration of the program. Currently it goes to 90 and stays there.
9  Using Arduino / Programming Questions / Re: My Servo won't move on: November 14, 2012, 07:28:40 am
Lol, yes I am missing the point.  smiley-wink
As to the servo, the white is connected to pin 9, the red is on VIN (Straight to the USB cable powering the device), and the black is obviously ground. Servos usually don't draw more than 50 mA, or so I have read, and USB can supply up to 500mA, so I think power is fine. What makes me think the wiring is good is that the "sweep" example works fine. I am at rather a loss here, not even getting any errors. I tried myservo.writeMicroseconds, mapping the data between 1000 and 2000, but that didn't work either.
10  Using Arduino / Programming Questions / Re: My Servo won't move on: November 13, 2012, 09:41:14 pm
Wow, that was fast. Ok. how about this:

Code:
#include <Servo.h>

char byteIn;
char numberChar[6];
int sVal;
int x;
int y;
float number = 0.000;
Servo myservo;

void setup() {
  Serial1.begin(9600);       // start serial communication at 9600bps
  Serial.begin(9600);
  myservo.attach(9);
  myservo.write(90);
}

void loop()
{
  if (Serial1.available())
  {
    byteIn = Serial1.read();
    if (byteIn == 'E')
    {
     x = 0;
     y = 0;
     if (numberChar[0]=='-')\
     {
      y = 1;
     }
     number = numberChar[0+y]-'0';
     number += ((numberChar[2+y]-'0')/10.0);
     number += ((numberChar[3+y]-'0')/100.0);
     number += ((numberChar[4+y]-'0')/1000.0);
     if (numberChar[0]=='-')\
     {
      number = number*-1;
     }
     sVal = (int)map(number, -10, 10, 0, 179);
     myservo.write(sVal);
     Serial.print("Raw value: ");
     Serial.println(number);
     Serial.print("Servo angle: ");
     Serial.println(sVal);
     Serial.println();
     delay(10);
    }
    else
    {
     numberChar[x] = byteIn;
     x++;
    }
  }
}

The input is actually coming from a python script running on scripting layer for android (SL4A) over bluetooth through a JY-MCU module to the Serial1 input, so it's a little hard to tell you exactly what is coming in, given that the data goes through a couple layers of android data manipulation then the bluetooth module, but I can tell you with reasonable certainty that the value coming in (for this example) is "5.057" as a series of bytes through Serial1. The output is

Raw value: 5.06
Servo angle: 134


So yes, I am pretty sure the data is right. The servo essentially does nothing. Hence the problem, since it started at 90 degrees and should be at 134.
11  Using Arduino / Programming Questions / My Servo won't move [SOLVED] on: November 13, 2012, 08:41:55 pm
I have a program that receives data over Serial1 of the mega 2560. The data is a series of bytes that represent a number in english from about -10 to 10, followed by an 'E'. anyway, what this is supposed to do is map the number to 0 to 179 for the servo, and write it to the motor. The problem is that after initially moving the servo to 90, nothing happens to the servo. I know from the Serial output that the values are being manipulated correctly, so it is definitely a problem with the implementation of Servo. The hardware is right because the servo sweep example works. Any ideas? Also, if anyone knows an easier way to cast from a character array to a float, that would be much appreciated.

Code:
#include <Servo.h>

char byteIn;
char numberChar[6];
int sVal;
int x;
int y;
float number = 0.000;
Servo myservo;

void setup() {
  Serial1.begin(9600);       // start serial communication at 9600bps
  Serial.begin(9600);
  myservo.attach(9);
  myservo.write(90);
}

void loop()
{
  if (Serial1.available())
  {
    byteIn = Serial1.read();
    if (byteIn == 'E')
    {
     x = 0;
     y = 0;
     if (numberChar[0]=='-')\
     {
      y = 1;
     }
     number = numberChar[0+y]-'0';
     number += ((numberChar[2+y]-'0')/10.0);
     number += ((numberChar[3+y]-'0')/100.0);
     number += ((numberChar[4+y]-'0')/1000.0);
     if (numberChar[0]=='-')\
     {
      number = number*-1;
     }
     sVal = (int)map(number, -10, 10, 0, 179);
     myservo.write(sVal);
     Serial.println(number);
     Serial.println(sVal);
     delay(10);
    }
    else
    {
     numberChar[x] = byteIn;
     x++;
    }
  }
}
12  Using Arduino / Motors, Mechanics, and Power / Re: AC light dimmer on: January 28, 2012, 06:06:32 pm
Since posting, I ran accross a thread in which someone got it working and posted a schematic and code. Here is the post. I ordered 2x H11AA1 opto isolators, 3x MOC3082M opto TRIACs, and 3x BTA16-600SWRG TRIACs from digikey. This looks like a better way to do it. As soon as I receive the parts, I will build it and try it.
13  Using Arduino / Motors, Mechanics, and Power / AC light dimmer on: January 25, 2012, 06:13:49 pm
Hi,

I am working on a project that I will briefly outline here:

First is a web interface, based on an apache network server. This communicates to a python CGI script, which sends a serial signal to my Arduino Mega 2560. This will control the lights and sound system volume and such in a room of my house. My question is regarding the AC light control portion. As you can no doubt tell from the title, I want to dim them. I have mostly figured out how to do this from several google searches, but I want to detail the circuit for inspection by those of you more experienced in electronics than me. I will have a triac (BTA16-600SWRG from digikey), I chose the one that did not say snubberless because the manufacturer's website said the standard ones are suitable for dimming. The TRIAC will be connected straight to mains, with the gate connected to a digital out of the arduino. Possibly with a transistor in between? I will also have an AC transformer connected to an opto=isolator connected between the 5v output on the arduino and an analog input. When the analog input reads 0v, delay for x milliseconds, and fire a pulse at the TRIAC. This should cut  off the waveform somewhere in the middle, depending on how bright you want the light. I also had thought to put a relay (Datasheet) on the line to the light, so that when the desired brightness is below 10% or so, just to turn off the current in the AC line. Does this all sound workable?
Pages: [1]