Jump to content
 
  • entries
    12
  • comments
    24
  • views
    16,199

Homework


nick_bastable

2,243 views

The plank has spent the last month cluttering up my limited work space, while a storage cover was made. This proved to be some what of a problem with some minor warp-age insuring very few angles where 90 degrees :scratchhead: however eventually this was resolved. The opportunity was taken to fit the crossing gate servos these been controlled via a Ardunio Micro given the required sequence required a slow opening of the first gate, a pause while the fireman crosses the road and then opens the second gate.

 

Hacking a simple Ardunio sketch appears to give the required sequence although final adjustments where time consuming.

 

for those intrested in such things I attach the code

 

 

 

/*

 

 

 

 

 

This example code is in the public domain.

 

http://www.arduino.cc/en/Tutorial/Button

*/

#include <VarSpeedServo.h>

 

VarSpeedServo myservo1; // create servo object to control a servo

// a maximum of eight servo objects can be created

VarSpeedServo myservo2; // create servo object to control a servo

// a maximum of eight servo objects can be created

 

 

 

// constants won't change. They're used here to

// set pin numbers:

const int buttonPin = 2; // the number of the pushbutton pin

const int servoPin1 = 9; // the digital pin used for the servo

const int servoPin2 = 6; // the digital pin used for the servo

// variables will change:

int buttonState = 0; // variable for reading the pushbutton status

// LED connected to digital pin 13

 

 

 

void setup() {

myservo1.attach(servoPin1); // attaches the servo on pin 9 to the servo object

myservo1.write(120,0,true); // set the intial position of the servo,

myservo2.attach(servoPin2); // attaches the servo on pin 9 to the servo object

myservo2.write(110,0,true); // set the intial position of the servo,

 

 

// initialize the servo pin as an output:

pinMode(servoPin1, OUTPUT);

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT);

 

}

 

void loop(){

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

 

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH) {

// turn servo on:

 

myservo2.write(110,2,true);

delay(6000); // waits for 6 seconds

myservo1.write(120,2,true);

 

}

else {

// turn servos off:

 

myservo1.write(55,2,true);

delay(6000); // waits for 6 econds

myservo2.write(55,2,true);

}

}

 

 

all a bit dry perhaps so some pictures and video to stop you falling asleep

 

blogentry-1480-0-34672200-1433681666_thumb.jpg

 

blogentry-1480-0-76573000-1433681699_thumb.jpg

 

  • Like 4

7 Comments


Recommended Comments

  • RMweb Gold

Nice work Nick.

 

That'll be the BLUE wire not the green that's doing that for you...there's a clue in there somewhere :lol:

Link to comment
  • RMweb Gold

Very clever. I expected the gates to open across the road. Forgive my ignorance but how do you talk to the Arduino. I presume the code has to be compiled. It has been some years but I used to write in C, Basic and assembler and have also input machine code direct. (you have to build your own timing loops for delays in machine code.

 

Don

Link to comment
  • RMweb Premium

Nice work Nick.

 

That'll be the BLUE wire not the green that's doing that for you...there's a clue in there somewhere :lol:

no greens down to earth....

 

 

Very clever. I expected the gates to open across the road. Forgive my ignorance but how do you talk to the Arduino. I presume the code has to be compiled. It has been some years but I used to write in C, Basic and assembler and have also input machine code direct. (you have to build your own timing loops for delays in machine code.

 

Don

 

 

It looks a lot like C++. There are presumably a large number of libraries?

 

 

code is a form of c/c++  the programmer / assembler is Java so should run on Windows/Linux/Apple  like all good things its open source and the libraries are quite extensive  I  upload via USB although it can be done by other methods

 

clone boards can be obtained via ebay for less than

Link to comment
  • RMweb Gold

Thanks Java was a bit after my time. I was using Boreland C compiler.

 

Don

Link to comment

Nick - great work. I've been thinking about doing the same sort of thing, after picking up an Arduino Uno recently and quickly getting it to control a couple of servos with minimal modifications to the free sample code provided. Such a great environment, just wish I could have been introduced to Arduinos and Raspberry PIs in my school days like many youngsters now!

 

I'm interested in your supporting electronics - I'm assuming this is to drive the power-hungry servos, but is there more to it than that? Do you have a circuit diagram?

 

Thanks!

Alan

Link to comment
  • RMweb Premium

Nick - great work. I've been thinking about doing the same sort of thing, after picking up an Arduino Uno recently and quickly getting it to control a couple of servos with minimal modifications to the free sample code provided. Such a great environment, just wish I could have been introduced to Arduinos and Raspberry PIs in my school days like many youngsters now!

 

I'm interested in your supporting electronics - I'm assuming this is to drive the power-hungry servos, but is there more to it than that? Do you have a circuit diagram?

 

Thanks!

Alan

Alan

 

you are correct,  the other bits are a simple 7805 based power supply  ( 12 volt DC is the master supply)  LED is only as a  visual indicator its working and the diode is simple short circuit protection

 

https://www.circuitlab.com/circuit/cy7x33/screenshot/540x405/

 

 

try using VarSpeedServo.h  its very useful

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...