A second iteration of the first version of the project "BuzzCane", in this iteration we'll be reducing the profile size of our microcontroller, by switching out the ESP32 for a smaller microchip, the ATmega328-PU. We will be adding
an external power source, a 9-Volts battery, a voltage regulator , the LM7805, and switches to enable/disable the buzzing functionality. As for everything else, the HC-SR04 sensor, and the active buzzer, they remain unchanged unless I
find cheaper, smaller-profile, alternatives that, even if they have reduced performance and accuracy, will see if they are fit enough for our use.
For our main change, we've switched the ESP32, with dimensions of approx. 48 mm in length & 25 mm in width. As well as a total height of 12 mm. While our ATmega328-PU is 35 mm in length, 7.49 mm in width, and 4.57 mm in height.
According to the documentations, the operating voltage is 1.8V-5.5 Volts, the maximum operating voltage sitting at 6 Volts, at which the microcontroller is prone to damage, so we refrain from running it or beyond 6 Volts.
It's an 8-bit AVR MCU, has a program memory size of 32 kB, Data RAM size of 2 kB, has a total of 28 pins, 23 of those 28 being GPIO, a minimum/maximum operating temperature of -40/+85 degrees Celsius,, and a weight of 4.1 grams.
below is what our wiring to the new ATmega328-PU MCU will look like:
In the schematic above, we've simply switched the ESP32-WROVER-DEV for an ATmega328-PU and changed the wiring accordingly. On the HC-SR04 ultrasonic sensor, the VCC wires up to VCC pin 7 on the MCU, Trig wires to pin 28, Echo
wires to pin 27, and GND wires to the GND pin on 22, the MCU having 2 GND pins (8 & 22). The Active Buzzer's short leg is wired to GND on pin 22 and the longer leg is wired to pin 14. I've also placed a switch on the wire
path between the positive leg of the Active Buzzer and pin 14 of the MCU to give the user the option to enable or disable the beeping sound in settings they deem it fine to work without the beeping warning functionality
#define TRIG_PIN 28 // ATmega328 pin GPIO28 connected to Ultrasonic Sensor's TRIG pin #define ECHO_PIN 27 // ATmega328 pin GPIO27 connected to Ultrasonic Sensor's ECHO pin #define Buzzer 14 // ATmega328 pin GPIO14 connected to Active Buzzer's positive pin float duration_us, distance_cm; // Declare float variables void setup() { // begin serial port Serial.begin (9600); // configure the trigger pin to output mode pinMode(TRIG_PIN, OUTPUT); // configure the echo pin to input mode pinMode(ECHO_PIN, INPUT); pinMode(Buzzer, OUTPUT); } void loop() { // generate 10-microsecond pulse to TRIG pin digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); // measure duration of pulse from ECHO pin duration_us = pulseIn(ECHO_PIN, HIGH); // calculate the distance distance_cm = 0.017 * duration_us; // print the value to Serial Monitor Serial.print("distance: "); Serial.print(distance_cm); Serial.println(" cm"); delay(500); if (distance_cm <= 5){ tone(Buzzer, 1000); delay(100); } else { noTone(Buzzer); delay(100); } }Please don't shy from sending suggestions or anything to the contacts listed in Whoami.