0% found this document useful (0 votes)
3 views3 pages

Arduino Sound Sensor with NeoPixels

This document contains an Arduino sketch that controls a NeoPixel LED strip and a servo motor based on sound sensor input. When sound is detected above a certain threshold, the servo moves back and forth while the NeoPixels display different colors. If no sound is detected, the NeoPixels turn off and the servo returns to a neutral position.

Uploaded by

shreyapotdar234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Arduino Sound Sensor with NeoPixels

This document contains an Arduino sketch that controls a NeoPixel LED strip and a servo motor based on sound sensor input. When sound is detected above a certain threshold, the servo moves back and forth while the NeoPixels display different colors. If no sound is detected, the NeoPixels turn off and the servo returns to a neutral position.

Uploaded by

shreyapotdar234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#define sensorPin A0

#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 5 // On Trinket or Gemma, suggest changing this to 1

// How many NeoPixels are attached to the Arduino?

#define NUMPIXELS 150 // 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

unsigned long lastEvent = 0;

#include <Servo.h>

Servo myservo;

void setup() {

pinMode(sensorPin, INPUT); // Set sensor pin as an INPUT

[Link](9600);

[Link](6);
//////////////////////////////////

#if defined(_AVR_ATtiny85_) && (F_CPU == 16000000)

clock_prescale_set(clock_div_1);

#endif

// END of Trinket-specific code.

[Link]();

void loop() {

// Read Sound sensor

[Link]();

int sensorData = analogRead(sensorPin);

[Link](sensorData);

// If pin goes LOW, sound is detected

if(sensorData > 400){

for (int pos = 70; pos <= 130; pos += 5) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

[Link](pos); // tell servo to go to position in variable 'pos'

delay(1); // waits 15 ms for the servo to reach the position

for (int pos = 130; pos >= 70; pos -= 5) { // goes from 180 degrees to 0 degrees

[Link](pos); // tell servo to go to position in variable 'pos'

delay(1); // waits 15 ms for the servo to reach the position

for(int i=0; i<50; i++) { // For each pixel...

[Link](i, [Link](255, 50, 0));


[Link](); // Send the updated pixel colors to the hardware.

for(int i=50; i<100; i++) { // For each pixel...

[Link](i, [Link](100, 100, 100));

[Link](); // Send the updated pixel colors to the hardware.

for(int i=100; i<NUMPIXELS; i++) { // For each pixel...

[Link](i, [Link](0, 255, 0));

[Link](); // Send the updated pixel colors to the hardware.

delay(100);

// colorWipe([Link](random(0, 255), random(0, 255), random(0, 255)), 0); // Red

// [Link](map(sensorData, 500, 1023, 0, 255));

// delay(10);

[Link]();

else

[Link]();

for(int i=100; i<NUMPIXELS; i++) { // For each pixel...

[Link](i, [Link](0, 0, 0));

[Link](); // Send the updated pixel colors to the hardware.

[Link](90);

You might also like