Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Solderless Breadboard Full Size
USB-A to B Cable
42BYGHM809 Bi-polar stepper motor
Angled DIP IC Sockets
Stepper motor driver board A4988
5mm Flange Shaft
DAOKI High Sensitivity Sound Microphone Sensor Detection Module For Arduino AVR PIC
Hardware & Tools
Variable Power Supply
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Computer
Software & Tools
Arduino IDE
Project description
Code
SoundLocator
arduino
This code/sketch makes finding the general direction of sound easy. This code/sketch is for a sound location finder using two microphone sensors in conjunction with an Arduino Uno. The code/sketch polls two microphone sensors in a sound location finder circuit. If sound is detected in one microphone sensor and not the other, the Arduino request a stepper motor in the circuit to turn the sound detection board in the direction of the sound. If the sound is detected in both microphones or no sound is detected, the circuit does nothing and continues to poll the microphone sensors.
1/* 2 File/Sketch Name: SoundLocator 3 4 Version No.: v1.0 Created 8 September, 2019 5 6 Original Author: Clyde A. Lettsome, PhD, PE, MEM 7 8 Description: This code/sketch makes finding the general direction of sound easy. This code/sketch is for a sound location finder using two microphone sensors 9 in conjunction with an Arduino Uno. The code/sketch polls two microphone sensors in a sound location finder circuit. If sound is detected in one microphone sensor and not the 10 other, the Arduino request a stepper motor in the circuit to turn the sound detection board in the direction of the sound. If the sound is detected in both microphones or no 11 sound is detected, the circuit does nothing and continues to poll the microphone sensors. 12 13 License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) version 3, or any later 14 version of your choice, as published by the Free Software Foundation. 15 16 Notes: Copyright (c) 2019 by C. A. Lettsome Services, LLC 17 For more information visit https://clydelettsome.com/blog/2019/09/08/my-weekend-project-sound-location-finder/ 18 19 */ 20const int stepsPerRevolution = 400; // change this to fit the number of steps per revolution for your motor 21const int numberOfSteps = stepsPerRevolution/8; //45 degree turns 22const int dirPin=12; 23const int stepPin=13; 24const int rightSensorPin=7; 25const int leftSensorPin=8; 26const int enablePin=5 ; 27boolean rightVal = 0; 28boolean leftVal = 0; 29 30void setup() 31{ 32 pinMode(leftSensorPin, INPUT); //Make pin 8 an input pin. 33 pinMode(rightSensorPin, INPUT); //Make pin 7 an input pin. 34 pinMode (stepPin, OUTPUT); //Make pin 13 an output pin. 35 pinMode (dirPin, OUTPUT); //Make pin 12 an output pin. 36 pinMode (enablePin, OUTPUT); //Make pin 5 an output pin. 37 38 digitalWrite(enablePin, LOW); //Enable is active low 39 Serial.begin (9600); // initialize the serial port: 40} 41 42void loop () 43{ 44 //poll inputs for signal 45 rightVal =digitalRead(rightSensorPin); 46 leftVal =digitalRead(leftSensorPin); 47 48 // when the sensor detects a signal above the threshold value set on sensor, turn finder to the direction of sound 49 if (leftVal==LOW && rightVal==HIGH) 50 { 51 Serial.println("Turning Right"); 52 digitalWrite(dirPin,LOW); //turn counter-clockwise 53 54 //turn finder in the direction of the sound 55 for(int steps = 0; steps < numberOfSteps; steps++) 56 { 57 //create pulse to turn motor one step at a time 58 digitalWrite(stepPin,HIGH); 59 delayMicroseconds(10000); 60 digitalWrite(stepPin, LOW); 61 delayMicroseconds(10000); 62 } 63 delayMicroseconds(100000); 64 rightVal = 0; 65 leftVal = 0; 66 } 67 else if (leftVal==HIGH && rightVal==LOW) 68 { 69 Serial.println("Turning Left"); 70 digitalWrite(dirPin,HIGH); //turn clockwise 71 72 //turn finder in the direction of the sound 73 for(int steps = 0; steps < numberOfSteps; steps++) 74 { 75 //create pulse to turn motor one step at a time 76 digitalWrite(stepPin,HIGH); 77 delayMicroseconds(10000); 78 digitalWrite(stepPin, LOW); 79 delayMicroseconds(10000); 80 } 81 delayMicroseconds(100000); 82 rightVal = 0; 83 leftVal = 0; 84 } 85 else 86 { 87 //Do nothing 88 rightVal = 0; 89 leftVal = 0; 90 } 91} 92 93
Downloadable files
Fritzing Diagram
Fritzing Diagram

Fritzing Diagram
Fritzing Diagram

Comments
Only logged in users can leave comments