To ensure I pick the correct sensor for my final project, I designed a sample slot with the specific dimensions I want so I could test the sensors on it.
Here is the design process using Fusion 360:
Here is the Fusion 360 file to download.
And here is the 3D design:
which you can download from here.
I cut the slot sample using the laser cutter, and here is the cutting process:
And here is the part after cutting:
And here is the final result:
During week9 I tested multiple sensors and hose ultrasonic sensors. you could see the full tests and results from week9 page.
During week10 I tested multiple output devices and chose neopixels for the light indication and and OLED screen to display the status. you could see the full tests and results from week10 page.
To connect the OLED display with the ultrasonic sensor and neopixel LEDs, I used the following connections:
Here is the connection diagram using Wokwi.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define TRIG_PIN 3
#define ECHO_PIN 4
long duration;
float cm, inches;
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 2 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 3 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
Serial.begin(115200); // ESP32 usually uses higher baud
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
Wire.begin(6, 7);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
// Clean trigger
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(5);
// Send pulse
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read echo
duration = pulseIn(ECHO_PIN, HIGH);
// Convert to distance
cm = (duration / 2.0) / 29.1;
inches = (duration / 2.0) / 74.0;
pixels.clear();
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(3);
display.setCursor(0, 0);
// LED control
if (cm < 18) {
pixels.setPixelColor(0, pixels.Color(0,255, 0));
display.println("Item detected");
} else {
pixels.setPixelColor(0, pixels.Color(255,0, 0));
display.println("No item detected");
}
pixels.show();
display.display();
// Print
Serial.print(inches);
Serial.print(" in, ");
Serial.print(cm);
Serial.print(" cm");
Serial.println();
delay(50);
}
And here is the testing process: