Monday, January 7, 2013

Making Arduino Shields in the classroom

Last month I challenged my grade 12 Computer Technology class to make traffic light simulator Arduino Shields. We used Fritzing to lay out the traces and Inkscape to make them thicker. We used a laser printout as a mask to etch the boards and finally the students put their skills to work assembling and programming the shields.

FRITZING
Fritzing.org is the source for a free neat circuit board layout utility. You can also use Fritzing to make schematics and bread-board layouts. I have tried to use Fritzing to do the bread-board, schematic and PCB all at the same time but the process became too complex and frustrating. Its better to use Fritzing to do one thing at a time. If you want to do a PCB, start there. As a teacher I like to use Fritzing to do bread-board layouts that my students can follow. I will lay out the circuit and then take a screen shot to generate the diagram.

When you pull an Arduino into the PCB in Fritzing you see two rows of points that match the i/o pin configuration. At this point you need to remember that the headers will be inserted from below and soldered on this side, the PCB trace side of your project. Components like resistors can be inserted on the underside as well but components like LEDs need to be seen and other components like transistors are too tall. These components need to be soldered onto the PCB trace side of the shield (see photos below). This is somewhat irregular but students who had minimal soldering practice were able to do this without any problems. I buy SH-2 snappable headers. You get 40 pins for 69 cents. Clearly you need to have a good understanding of the circuit before you begin. My students completed several labs involving LEDs and push buttons before starting this assignment.

Here is a dual H bridge shield layout in Fritzing.

Export the file as an 'etchable' SVG file. We use Inkscape to increase the trace width to 4 px and the donuts to 3 px. Group and flip horizontally. Print it out using a laser printer.


ETCHING
Next a piece of copper clad board is cut to size and the edges sanded. Safety glasses and a dust mask should be employed. The board is cleaned with acetone then buffed with an abrasive nylon scouring pad to get it as clean and shiny as possible. Real elbow grease should be employed. Finally the board is cleaned with rubbing alcohol. We use Nitrile gloves to protect our skin from the chemicals.

The printout is cut to fit the board and then arranged on top of the copper clad board toner down. The arrangement is passed through a common office laminator set to high at least 20 times in a row. After the second pass the paper becomes stuck to the copper and will not move. After 5 passes you will need pliers or tweezers to handle the hot board. This process fuses the toner into the copper. Let the board cool for 5 minutes and then place it in a bowl of water. After 5 to 10 minutes you can remove a thick layer of the paper by rolling your thumb over the surface. Check first to see if more soaking is indicated by carefully working on a corner. (Thats why I add some text to one corner of the board.) With the first layer of paper gone another 5 to 10 minute soak and you will be able to 'roll' the rest of the paper off. Let your board dry over-night.

We use hot Ammonium Persulphate etchant in a bubble tank to do the etching. The hotter the better but watch out for the fumes. A fume hood or exhaust hood is mandatory because the ammonia gas can burn upper respiratory tissue. Nitrile gloves and safety glasses should be employed. A lab coat will keep your Maple Leafs Hockey Jersey clean. For ease of handling we drill a small hole in one corner of the board and hang it from a popsickle stick using some string. When the board is done etching wash it with water, dry it and then wash the toner off with more acetone. Buff up the copper using the scouring pad just before soldering your components in place.

Why use Ammonium Persulphate? The alternative is Ferric Chloride. This liquid is black and stains anything it touches. Even one drop in a stainless steal sink will discolour the sink almost instantly. When the Ammonium Persulphate is exhausted and has turned dark blue you are left with a strong solution of Copper Sulphate which can be used to grow Copper Sulphate crystals by evaporation. Either chemical should go to a hazardous waste depot when you are done with it.

ASSEMBLY

Top view: Two set of lights (RYG) and one Walk-Dont Walk (RG) with a PB to call for a walk signal. Notice how the LEDs and PB are soldered to the copper trace side of the board.



Bottom view:


All the resistors in the traffic light simulator tie in to ground so we used a 330 ohm SIP Common Bus package bent at an angle to avoid hitting the Atmel chip on the Arduino. 

Once the package is ready to test insert shield onto the Arduino and start by rewriting Blink to test each LED independently. If you get a USB bus overload warning on your computer you need to unplug the Arduino immediately and test your circuit for shorts. We found it was best to leave the shield in place on the Arduino until the project is finished and marked.

Thursday, January 3, 2013

Line Follower part 2

In the next phase of this project I attached 2 QRE 1113 Line Sensor breakout boards to the Arduino Line Follower and tried out a simple line-following algorithm.



I decided to put the QRE1113 breakout boards onto movable arms so that I could experiment with the spacing between them.  The breakout boards themselves are soldered to 3 lengths of 22 gauge hookup wire. Three different wire colours makes hookup simpler. The wires are enclosed in a 3" length of straw. The arms are made out of found pieces of plastic moulding attached to the Line Follower base with a single #6 bolt and nut. The hole for the straw is a tight fit so that the height of the QRE1113 can be easily adjusted.


The QRE1113 is connected to +5V power and ground and the signal wires (out) connected to digital inputs 2 and 3.
This is the code used to verify the operation of the detectors:
//Code for the QRE1113 Digital board
//Outputs via the serial terminal - Lower numbers mean more reflected
//3000 or more means nothing was reflected.

int QRE1113_Pin = 2; //connected to digital 2

void setup(){
  Serial.begin(9600);
}

void loop(){

  int QRE_Value = readQD();
  Serial.println(QRE_Value); 

}

int readQD(){
  //Returns value from the QRE1113 
  //Lower numbers mean more reflective
  //More than 3000 means nothing was reflected.
  pinMode( QRE1113_Pin, OUTPUT );
  digitalWrite( QRE1113_Pin, HIGH );
  delayMicroseconds(10);
  pinMode( QRE1113_Pin, INPUT );

  long time = micros();

  //time how long the input is HIGH, but quit after 3ms as nothing happens after that
  while (digitalRead(QRE1113_Pin) == HIGH && micros() - time < 3000);
  int diff = micros() - time;

  return diff;
}


The simplest line following algorithm is to stall the wheel on the same side causing the platform to move away from the line. If the left hand detector encounters the line then the left hand motor stops for a period of time while the right hand motor continues causing the platform to turn left or away from the line. This assumes that the line is always between the 2 sensors. In the code below the amount of time the wheel stalls is the variable turn.


int M1F = 6; // motor 1 forward
int M1R = 5; // motor 1 reverse
int M2F = 11; // motor 2 forward
int M2R = 10; // motor 2 reverse
int turn = 120;
int forward = 2000;
int leftPin = 2; //left detector connected to digital 2
int rightPin = 3; //right detector connected to digital 3
int rightQRE_Value;
int leftQRE_Value;


void setup(){
  //Serial.begin(9600);
}

void loop(){
  rightQRE_Value = readQD(rightPin);
  leftQRE_Value = readQD(leftPin);
  //Serial.println(rightQRE_Value);
  //Serial.println(leftQRE_Value);
  if (rightQRE_Value > 100){
    analogWrite(M2F,0);
    delay(turn);
  }
  else if (leftQRE_Value > 100){
    analogWrite(M1F,0);
    delay(turn);
  }
  else{
    analogWrite(M1F, 150);
    analogWrite(M2F, 150);
  }

}

int readQD(int pin){
  //Returns value from the QRE1113 
  //Lower numbers mean more reflective
  //More than 3000 means nothing was reflected.
  pinMode( pin, OUTPUT );
  digitalWrite( pin, HIGH );
  delayMicroseconds(10);
  pinMode( pin, INPUT );

  long time = micros();

  //time how long the input is HIGH, but quit after 3ms as nothing happens after that
  while (digitalRead(pin) == HIGH && micros() - time < 3000);
  int diff = micros() - time;

  return diff;
}

A little adjustment to the speed (ended up at 150) and turn (ended up at 120) and the platform was able to follow this path.


Here is the PCB pattern for the dual H bridge:
... and reversed, ready to print: