Defect Detector – Schematic

Here you can see the servo motor to the left that was connected to our A3BU which is being controlled by PWM. The duty cycles ranged from 15 (middle), 10 (left), and 20 (right)

Wiring:

In order to connect the servo motor and pressure sensor to the A3BU, first we had to look up what colors were used for the power, ground, and signal for the servo and then pins that were used for the pressure sensor. The servo motor is wired up to an external 5V DC power supply with an orange cable connected to the PWM pin on the A3BU. The pressure sensor was connected to a 3.3V power supply from the board and was connected to the ADC pin of the A3BU. The A3BU received power from a laptop.

Defect Detector – Code

The most interesting part of the code for our project was, without a doubt, the code used to filter out false positives read by the ADC. There were two main methods we utilized to do this:

• Get a good threshold value
```// in main

for (int i = 0; i < 25; i++) {
_delay_ms(100);
}

CUTOFF = THRESHOLD + OFFSET;

/* … */

{
float xbar = 0.0, s = 0.0;
for (int i = 0; i < read_count; i++) {
}
for (int i = 0; i < read_count; i++) {
}
s = sqrt(s);
return (int) (xbar + 0.75 * s);
}```

The first method employed is simply setting a good threshold that the readings must surpass in order for the program to act upon them. To obtain this threshold a number of readings are taken at the start of the program. These preliminary readings are then used to get a good baseline for the threshold by finding the arithmetic mean of them and adding a fraction of a standard deviation. The precise number of standard deviations we added was arrived at through trial and error.

• Ensure that the reading is consistent
```do {
// busy loops 200 ms at a time until a sufficiently large weight is placed on the sensor
int streak = 0;
do {
_delay_ms(100);
if (last_result < THRESHOLD)
streak = 0;
else
streak++;
} while (streak < STREAK_THRESHOLD);
streak = 0;
// sorts the object appropriately
sort_object(&mypwm, last_result, CUTOFF);
} while (1);```

The other method employed is to ensure that the readings we get from the ADC are consistently significant. To do this, instead of calling the sort routine whenever a result is significant, we only call the sort routine when each of the last N results have been significant. This helps to filter out fleeting spikes of voltage read by the ADC whether they are from simple noise or from the spike that results when an object is dropped onto the sensor rather than placed on top of it.

Defect Detector – Big Picture

The purpose of our final project was to build a device where a user could place an object into a box to be sorted. The pressure sensor embedded between two plates is designed to give an analog voltage output. The raw voltage obtained from the pressure sensor is converted by an analog to digital converter (ADC) on our A3BU board, and given a digital value between 0 and 127. The plate was controlled by a servo motor which could rotate to three positions; left, center, and right.