Sound Sensor & Servo: Reactive Motion

by moont087 in Circuits > Arduino

5527 Views, 5 Favorites, 0 Comments

Sound Sensor & Servo: Reactive Motion

Audio Sensor Servo Arduino.JPG
a000066_featured_5.jpg
51cAzOCgkRL._AC_SY355_.jpg
PRO-00010-JUMPER-WIRES-MALE-MALE-BUNDLE-OF-10.jpg
Servo-Motor-Wires.png
sound-sensor-factoryforward-458x458.png
Duracell-Procell-9-Volt-Battery-for-Precision-tDCS.png
9 volt adapter.JPG

First you need to gather relevant materials to put this circuit together.

Supplies

1 Arduino

1 Ultrasonic Sensor HC-SR04

1 Servo

1 Breadboard

1 9 Volt Battery

1 9 Volt Battery Adapter

3 Black Jumper Wires (Ground/Negative)

3 Red Jumper Wires (Voltage/Positive)

2 Color Jumper Wires (Input/Output)

Understanding the Components

Audio Sensor.JPG
Breadboard Layout.JPG
Servo-Motor-Wires.png

It is important before putting together the physical circuit to understand each component:

The breadboard has two sets of power rails on either side, that have slots for negative (black/blue) and positive (red) inputs. They are connected in series vertically. Terminal strips share the connection horizontally, however parallel terminal strips will require a jumper wire to bridge the divider.

The sound sensor has a VCC/5V pin (red), a Ground/GND pin (black) and an output pin (Color). They can have Analog and/or Digital outputs depending on the sensor.

The servo has a 5V port (red), a Pulse Width Modulation/PWM port (color) and a Ground/GND port (black). Click the link to know more about how it works.

Setting Up the Circuit

Audio Sensor Servo Arduino.JPG

Follow the diagram layout. While setting up the circuit, always remember to keep the arduino unplugged to avoid any damage to your components. In the layout the Sound Sensor is represented by a potentiometer since they work in the same way in terms of code.

Plug the sound sensor into the power rail of the breadboard, taking note of its orientation (this will be important when using the jumper wires to connect to the arduino). Connect VCC with a red jumper wire into breadboard's positive power rail. Connect GND with a black jumper wire into the breadboard's negative power rail. Connect Out pin with a color jumper wire into the Analog Port A5.

Plug the servo into to the breadboard and arduino. Use a color jumper wire to connect it's input/signal port to the digital PWM port, 13 on the arduino. Plug black jumper wire into GND power rail. Plug the red jumper wire into a terminal row. The servo will need extra power which is provided by the 9V battery.

Plug the 9V batter, red jumper wire into the same terminal row as the servo's red jumper wire. The black jumper wire will plug into the same side power rail as the rest of the components.

Download Arduino GUI and Input Code

Arduino Download.JPG
Arduino Code GUI 4.JPG

Download Arduino Graphical User Interface (GUI) here.
Plug in the code below, note the information to the right of "//" tells you what that line of code is doing:

----copy below and paste into arduino GUI----

#include

Servo servo_test;

const int soundSensor = A5;

int servoPin = 13;

int soundValue;

int angle;

void setup() {

servo_test.attach(servoPin);

Serial.begin(9600);

}

void loop() {

soundValue = analogRead(soundSensor);

Serial.print("SoundValue = ");

Serial.println(soundSensor);

delay(50);

angle = map(soundValue, 0, 1023, 0, 180);

servo_test.write(angle);

delay(50);

}

Sound Sensor + Servo + Arduino

Sound Sensor & Servo
IMG_3935.jpg
IMG_3933.jpg

This is how the final circuit should look. Watch the video to see how it works.