Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Programming Questions / Re: Increasing two different servo PWM's with different delay's on: July 11, 2012, 12:58:35 pm
Also I wanted to check if it is possible to increase the microseconds in decimal fractions such as 1.5 or 3.9.
You could using floating point, or you could use a fixed point representation.

Sorry, I am fairly new to this and still learning, how would I do this, and would this cause problems with the servo, or are they ok with reading a signal of say 3.9?

32  Using Arduino / Programming Questions / Re: Increasing two different servo PWM's with different delay's on: July 11, 2012, 12:55:27 pm
I realise this is very complicated for what is essentially a simple idea.

Here is the 'wrong code version' of what I am trying to do

Case 0:
MinutePulse = MinutePulse + 4; //(increases the value by 4 every loop)
ServoA.WriteMicroseconds(MinutePulse) //writes value to servo
Delay (60000); // delay for 60 seconds before moving again

// In the same case 0 I need the following to happen within the same program loop (simultaneously)

HourPulse = HourPulse + 3; //(increases the value by 3 every loop)
ServoB.WriteMicroseconds(HourPulse) //writes value to servo
Delay (120000); // delay for 120 seconds before moving again

33  Using Arduino / Programming Questions / Re: Increasing two different servo PWM's with different delay's on: July 11, 2012, 12:46:08 pm
I am basically trying to simulate a real clock with two servos, one for each hand (Hours and Minutes).
The reason for using servos is I have multiple buttons. You press one and the clock hands instantly zips to a particular time and starts running at a normal clock time. You press another and it zips to that time and starts running etc.

Normal servos can only do 180 degrees so I am using sail winch servos to allow me a couple of rotations however they work on the basis that 600pwm is all the way left and 2500pwm is approx three/four rotations to the right. I have calculated through testing that increasing the microseconds from 1000 to 1253 gives me one full rotation on the servo (this can be done anywhere within the 600-2500 range. I picked the 1000 point because it seems to be the most reliable area in the range.

So, to get one minute on the minute hand in a minute of normal time, matching a normal clock, the servo has to move 4pwm per minute (3.9 actually but it has been rounded up) I have this working in the code shown

Simultaneous to that I need the hour hand to move. This should move 1.5pwm per minute to simulate moving from say midnight to 1 over the space of an hour, however I have rounded this up to 3pwm per two minutes due to my belief that I can't use fractions of a pwm.

What I am asking is how can I have two different servos moving incrementally by different amounts with different delays.

Also I wanted to check if it is possible to increase the microseconds in decimal fractions such as 1.5 or 3.9.

34  Using Arduino / Programming Questions / Increasing two different servo PWM's with different delay's on: July 11, 2012, 11:49:42 am
  I have a program running a couple of sail winch servos to control some clock face hands.  One servo for hour hand, one for minute hand.

I have the minute hand working well using a delay to incrementally increase the pwm to simulate the minutes, simulating a real

The servo takes +235PWM to do a full rotation so for the minute hand I have been increasing the PWM by 2 increments every 30 seconds

(Maths bit - 235PWM / 60mins = 3.9PWM per min so - 4PWM per min (rough, but ok for what I need) = 2PWM per 30 seconds.

The code below works fine for the minute hand however I have now come to doing the hour hand and I need to find a way of having
two different delays, or an alternative method to have the pwm's increasing at different speeds.

(Hour hand maths bit - 4PWM (1 Min clock time) x 10mins (1 hr clock time) = 40PWM per 60 mins 'real time'

40PWM / 60mins = 1.5PWM Per min =

1.5 increments per minute or 3 increments every two minutes (due to not being able to use 0.5 of a PWM)

I hope this makes sense,

basically I want to know if

1/there is a way of increasing, incrementally the two different PWM's with different delays within the same case?

2/does anyone know if servo's can use fractions of a PWM, for example 1503.9PWM? or will this just cause problems?

Thanks in advance, please no suggestions of using Steppers etc, I have to use servos's for this particular setup for reasons
that will take too long to explain here.


case 7: // Commence Time
  MinutePulse = MinutePulse + 2;  //incremental time increase every 30 seconds (30000)
    //HourPulse = HourPulse + 3; //incremental time increase needs to be every two minutes (120000)


    //Serial.print("HOUR PWM VALUE IS SET TO ");
  Serial.print("MINUTE PWM VALUE IS SET TO ");
  delay (30000); 

35  Using Arduino / Programming Questions / Re: Moving two servos incrementally every second on: July 08, 2012, 10:45:44 am
Thankyou both very much. Very helpful and a lot simpler than I thought.

All the best

36  Using Arduino / Programming Questions / Moving two servos incrementally every second on: July 08, 2012, 10:21:45 am
Hi,  I am controlling the position of two servo's, (say A and B)

Let's say servo A and B both start at 1000ms position:


I want to be able to add to the position incrementally every second so say servo A starts at 1000 and moves 100ms every second and servo B starts at 1000 and moves 10ms every second.

I know I have to define two values, add to them every pass, then send that value to the servo position but I am slightly unsure on how to code this.

I think it is something like this:

Int APulse;
Int BPulse;

Void setup() {

APulse = 1000;
BPulse = 1000;

Void loop() {


(this is the bit I don't understand, adding to APulse, BPulse by 100ms and 10ms, then feeding it back in
To the next loop)

Delay 1000; delays by a second then back around again.


From looking into example code I am assuming I need to use the map command but don't quite understand it.

37  Using Arduino / General Electronics / Long wire Remote question on: July 08, 2012, 07:47:51 am
   I want to 'breakout' five switches from an UNO into a remote control box.  The box needs to be on a 30M long wire. It is for a theatre show, hence the distance needed. It is not an option to have the UNO in the remote, already considered that.

I was concerned that it may cause problems with the signal getting too much resistance over the length of the wire.  Can anyone see this being a problem? My plan was to have 6 core cable containing one 5v positive taken from the board and five 'switch' wires going through pushbuttons and back into the UNO pins with pull down resistors etc.

If it is a problem is there any difference/benefit between using the analog or digital pins for this? Or is there any way of boosting it to prevent problems.

Would I need to change the pull up/down resistors to adapt to the length of the cable?


38  Using Arduino / Project Guidance / Sail winch 360 servo question on: July 08, 2012, 07:19:19 am
   My project involves using two sail winch servos (HITEK HS-785 HB, apparently 3.5 rotations possible).  I am waiting for the servo's to turn up but just wondered if anyone has any experience using/programming for these?

I need to control the exact position of the servos all the way round the 3.5 turns, just wondered how this works on the programming (microseconds) side of things?  Is this possible?

For example, what happens when the servo reaches 360 degrees rotation, do I have to program it to go to 361 degrees to continue rotating or do I have to then tell it to go to 1 degree on the servo.

 Or is it similar to a normal servo where 1000ms is 'zero position' and 2000ms would be 3.5 rotations clockwise?


39  Using Arduino / Programming Questions / Interrupting switch (mode) on: June 28, 2012, 06:13:03 pm

I have my code running well for a stepper motor/weird clock I am working on.

I am using switch/mode to trigger different timings on the motor.

I want to be able to interupt case 2 when it is running by pressing startBswitch and have it immediatly go to case 0, stopping the sequence.

Currently it works but only if I hold down the switchB for more than 6 seconds, which I assume is due to it needing to clear the
6545ms delay I have running for every sequence in the mode.  The delay is required for adjusting my timings on the stepper
and I cant really touch it.

Is there a way of having the button press immediately interrupt case 2, regardless of whether it is in the delay period?

Here is the relevent part of the code:

void loop() {
if ( mode == 0 && digitalRead (setupAswitch) == LOW){ mode = 1;}
if ( mode == 0 && digitalRead (startAswitch) == LOW){ mode = 2;}
if ( mode == 2 && digitalRead (startBswitch) == LOW){ mode = 0;}

switch (mode){

case 0:  // do nothing and reset all counters
CountA = 0;
CountB = 0;
CountC = 0;
case 1:  // Set Clock(Stepper) start position A
 motor.step(1, BACKWARD, DOUBLE);
 if (digitalRead(reedswitchA) == LOW) mode = 8; // Stop shen it hits reedswitch go to mode 8 (REED discrepancy)
case 2: // Run Stepper Prog A
 motor.step(2, BACKWARD, SINGLE);
if ( CountA++ >776 ) mode = 0 ;
delay (6545); //6545ms delay

40  Using Arduino / Programming Questions / Re: Stepper motor repeat/interupt code on: April 22, 2012, 01:19:23 pm
Just realised my error there, should have been

int CountA = 0;

worked a charm.

Any ideas about my case 1 & 2 reed switch problem?

41  Using Arduino / Programming Questions / Re: Stepper motor repeat/interupt code on: April 22, 2012, 01:14:51 pm
thanks, sorry to be slow (newbie)

but is this what It should look like?

const int CountA = 0;

case 4: // Run Stepper Prog A
if ( CountA++ >500 ) mode = 6 ;

Is this all I need to add?

I also have another case that I want to loop for a different amount of time, can I just define another variable say CountB and do the same with a different amount in the other case?
42  Using Arduino / Programming Questions / Stepper motor repeat/interupt code on: April 22, 2012, 11:29:43 am
I am using a Duemilanove with an Arduino R3 motor shield to control a bipolar stepper motor.  I have the stepper working/rotating fine with basic code.


this snippet taken from my code (full code below)

case 4: // Run Stepper Prog A
mode = 6;

How do I get the first two lines of this case to run 500 times before moving onto the next mode (mode 6)?


Case 1 & 2, shown in the code below.  I want to rotate the stepper until it hits the reed switch (reed switchA or B) then stop and move onto the next mode.  I am stuck on how exactly what code to use to interupt the stepper rotation when it hits the switch?

Thanks in advance, this board is my saviour.

#include <Stepper.h>
 const int stepsPerRevolution = 200;  // Motor Resolution
 Stepper myStepper(stepsPerRevolution, 12,13);  // initialize the stepper library on the motor shield    
 // Stepper Pins
 const int pwmA = 3;
 const int pwmB = 11;
 const int brakeA = 9;
 const int brakeB = 8;
 const int dirA = 12;
 const int dirB = 13;
 int x = 0;
 // Switch Pins
 byte setupAswitch = 2;
 byte setupBswitch = 4;
 byte startAswitch = 5;
 byte startBswitch = 6;
 const int reedswitchA = 7;
 const int reedswitchB = 10;
 byte mode; // 0 = waiting to start, 1 = setupA, 2 = setupB, 3 = post setup, pre-startup, 4 = A code, 5 = Bcode, 6 = post A/B startup code
void setup() {

// Setup Stepper Pins
 pinMode(pwmA, OUTPUT);
 pinMode(pwmB, OUTPUT);
 pinMode(brakeA, OUTPUT);
 pinMode(brakeB, OUTPUT);
 digitalWrite(pwmA, HIGH);
 digitalWrite(pwmB, HIGH);
 digitalWrite(brakeA, LOW);
 digitalWrite(brakeB, LOW);
 // Setup switch pins
 pinMode (setupAswitch, INPUT); // set up the various push switches
 digitalWrite (setupAswitch, HIGH); // turn on internl pullup - check for a LOW input to indicate switch is closed to ground
 pinMode (setupBswitch, INPUT);
 digitalWrite (setupBswitch, HIGH);
 pinMode (startAswitch, INPUT);
 digitalWrite (startAswitch, HIGH);
 pinMode (startBswitch, INPUT);
 digitalWrite (startBswitch, HIGH);
 pinMode (reedswitchA, INPUT);  // set up the reed detector switches
 digitalWrite (reedswitchA HIGH);
 pinMode (reedswitchB, INPUT);
 digitalWrite (reedswitchB HIGH);
 Serial.begin(9600);  //initialise the serial port
 myStepper.setSpeed(1); // // set the motor speed:

 void loop() {
if (mode ==0 && digitalRead(setupAswitch) == LOW){ mode = 1;}
if (mode == 0 && digitalRead(setupBswitch_ == LOW) {mode = 2;}
if ( mode == 3 && digitalRead (startAswitch) == LOW){ mode = 4;}
if ( mode == 3 && digitalRead (startBswitch) == LOW){ mode = 5;}
switch (mode){

case 0:  // do nothing

case 1:  // Set Stepper start position A
//Rotate until reed switchA is LOW
mode = 3;

case 2:  // Set Stepper start position B
// Rotate until reed switchB is LOW
mode = 3;

case 3:// do nothing

case 4: // Run Stepper Prog A
mode = 6;

case 5: // Run Stepper Prog B
mode = 6;

case 6:
// whatever is done after setup & start
} // end switch

} // end loop
43  Using Arduino / Programming Questions / Re: Multiple button press choices on: April 22, 2012, 03:33:31 am
Wow, thankyou so much. It is so helpful to see it like this.

A quick question, where I have case 0 and case 3 (the holding/waiting points) do I need to define anything here to hold it at this point or just leave it blank as you have - is there an 'indefinite wait until input' command I need to put in there?

Thanks again

44  Using Arduino / Programming Questions / Multiple button press choices on: April 21, 2012, 09:40:55 pm
   I am still fairly new to programming and have trawled through pages of example code trying to find something similar to what I want to achieve but can't quite work this out.

I am using dueminalove with a motor shield/stepper motor. I have four push switches, let's say named SetupA, SetupB, StartA, StartB.

The end objective is to have my stepper motor, on pushing the relevant switch (setupA or B), move to one of its two starting positions then wait for the relevent start switch to be pressed (StartA or B) which then run through different motor sequences.

Code-wise this is what I am trying to achieve-

On power up I want the code to wait for input from either SetupA or SetupB switches.

When either is pressed it runs the relevent bit of code, say SetupCodeA or SetupCodeB, (getting the motor to one of the two start positions)

Then after running the relevant code it waits for an input from the StartA or StartB switch

When Start A or B button is pressed it runs either StartCodeA or StartCodeB (starting the motor on one of the two start sequences)

I am trying to work out exactly what statements to use to achieve or 'call' the different bits of code then wait.  My understanding is that I may need to use a switch/case statement but don't quite understand how to implement it in this case.

I don't have any problems with the rest of the setup, it is just the 'using different switches to run different code' that is confusing me.

Any help or pointers to something similar would be appreciated.
45  Forum 2005-2010 (read only) / Interfacing / Re: Minimal DC Motor control circuit question on: August 17, 2010, 05:36:57 pm
Thanks, will look into that. Any idea where I might find a schematic?
The motor literally needs to run this action once then the battery can either be recharged or changed. It is a stage trick. One shot a night.

The motor is 7v 30mA under load. about 14mm diameter and 38cm long - mini!

Unfortunately there is no room or way of implementing limit switches on my device hence me wanting to use a controller. This is causing me all kinds of headaches though.

Oh and apologies when I said H-Bridge I meant I was using the L293D to reverse the motor similar to a H bridge. Which I hope is correct??
Pages: 1 2 [3] 4