IAN LANG ELECTRONICS

We use four outputs from the RC board, these are whatever goes high as the relevant button on the transmitter is pressed. If you are supplying the RC board with 5V from the Arduino, the output at high will be 5V which will have a reading of 1023 at the analogue inputs (each digital step being equal to 4.9 mV) and when the output is low the pull down resistors will cause the pins to have a reading of zero. The servos are controlled by pulse width modulation and so you need to attach the signal pin to a pin of the Arduino capable of doing it; I'm using 9 and 10.

This is the entirity of the electronic control system except to say that I used 6 AA batteries in a box with a barrel adaptor on the end. You can make this for yourself, but you might find it cheaper to get a ready made one from Oomlout. The link is on the left.

 

On to the code that makes this work then. Here's the full version:

 

#include <Servo.h>  

Servo myservo;  

Servo myservo1;

int pos = 0;    // variable to store the servo position

boolean nobutton=true;

String lastway="";

void setup()

{

  myservo.attach(9);

   myservo1.attach(10);  // attaches the servo on pin 9 and on pin 10 to the servo objects

}

 

 

void loop() {

 

if (analogRead(A0)<700 && analogRead(A1)< 700 && analogRead(A2)< 700&&analogRead(A3)< 700){

  nobutton=true;}

  else{nobutton=false;  pinMode(9,OUTPUT);pinMode(10,OUTPUT);}

if (nobutton==true){

 if (lastway=="F"){ myservo.write(90); myservo1.write(90);}

  if (lastway=="R"){ myservo.write(90); myservo1.write(90);}

  if (lastway=="L"){ myservo.write(90); myservo1.write(90);}

 pinMode(9,INPUT);pinMode(10,INPUT);lastway="";}

if (analogRead(A1)>1000){

  forward();}

if (analogRead(A0)>1000){

  reverse();

   }

   if (analogRead(A2)>1000){

 lturn();

   }

      if (analogRead(A3)>1000){

rturn();}

}

 

 

 void forward(){

 myservo.write(180);

 myservo1.write(0);

lastway="F";

 

  }

 

  void reverse(){

  myservo.write(0);

 myservo1.write(180);

lastway="R";

 }

 

   void lturn(){

  myservo.write(180);

 myservo1.write(180);

 lastway="L";

   }

   void rturn(){

  myservo.write(0);

 myservo1.write(0);

 lastway="L";

 }

 

As you can see, there isn't a great deal of it. Most of the hard work has been done already at the RC board and it's just a case of seeing what's high there and moving or stopping the servos in the right directions or stopping them as the case dictates. Let's look through the top section:

 

#include <Servo.h>  

Servo myservo;  

Servo myservo1;

int pos = 0;    // variable to store the servo position

boolean nobutton=true;

String lastway="";

 

If you've read much of the earlier chapters on this site you'll be familiar with the concept of libraries. If you haven't, libraries are a sort of background program to your Arduino sketch which simplify how you work with the attachments that either output or input to the board. In this case the library file is Servo.h and we call it with the line:

 

#include <Servo.h>  

 

The library works by seeing servos as objects. We therefore have to give them object names:

 

Servo myservo;  

Servo myservo1;

 

Next we just set a variable of type int to control the position of the servos:

 

int pos = 0;    // variable to store the servo position

 

and a variable of type boolean to check whether a button on the transmitter has been pressed:

 

boolean nobutton=true;

 

How does it know? Because if no output from the board is high, then no input to the Arduino is high either. If there's no output and hence input, either no button's being pressed on the transmitter, or the transmitter or receiver is broken. Hopefully the latter is not the case.

Finally we set a string, lastway, and make it null. This is going to help with making sure the servos are reset and don't jerk momentarily in the wrong direction.

 

We now have to declare in the setup where the signal pins of the servos are attached to the Arduino board. We do it like so:

 

void setup()

 

{

  myservo.attach(9);

   myservo1.attach(10);  // attaches the servo on pin 9 and on pin 10 to the servo objects

}

 

 

The loop is of course where all the action takes place, and we'll be calling some functions from it. Over the page we go to canter through what's happening.

 

The Meccanoid

Go Back

The task-

 

Build a transporter which is capable of carrying a bag of sugar. You can use any electronic means, but the chassis cannot be pre-made and must be made out of anything that comes to hand. It must move backwards and forwards in a straight line, and be dirigible preferrably by being able to turn on its own axis.

Control must be achieved by a wireless method and the power supply must be on-board.

 

Yes, I had to look up dirigible in a dictionary too. It means steerable. The solution-

 

Ladles and jellyspoons, Ian Lang Electronics proudly(ish) presents:  The Meccanoid.

As you can see the chassis and all of the supporting structure is made from Meccano. The load is carried inside the wheelbase making it stable, and the driving wheels at the back are attached to the horns of two continuous rotation servos. I got these from Oomlout and if you click on the picture below it takes you to their webpage:

 

This little beast packs a lot of muscle. A servo is basically

an electric motor that can remain in one position, but the

continuous rotation variants go through a full 360 degrees

and rotate in the manner of a normal motor. You may now be

asking "well, what's the point then?" but it is this: through the

applied current and the gearbox, it produces an incredible load

of torque for its size- 4.8 kg per cm, in fact. That's more than enough

to shift that bag of Tate and Lyle on a flat surface, and a quick work-out suggests

it'd be able to hump it up a ramp of 20 degrees quite easily too. Spiffing. That's the

bunny we need then. Two of them driving one wheel each will mean that we can have

wheels going round in the same or opposite directions and joy of joys, they are just the right size to fit under a meccano baseboard. It's as if it were ordained by a benign deity.

Of course there are drawbacks. Once you start the servos rolling, it's difficult to stop them again by conventional methods. In addition, if you change direction, the servos will for a little while continue to move in the last direction they were, unless you do something to stop them. Fear not, for with a little applied geometry, observation and deduction, (i.e. guessing) these problems are not insurmountable.

 

First things first. Let's have a Fritzing diagram for the wiring:

www.oomlout.co.uk/6xaa-battery-arduino-adapter-p-201.html?zenid=1d82e623b57382e163ec4418766907a9 More>