Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Final Code

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)
6 views3 pages

Final Code

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
You are on page 1/ 3

#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

Serial.begin(9600);

myservo.attach(6);
//////////////////////////////////

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

clock_prescale_set(clock_div_1);

#endif

// END of Trinket-specific code.

pixels.begin();

void loop() {

// Read Sound sensor

pixels.clear();

int sensorData = analogRead(sensorPin);

Serial.println(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

myservo.write(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

myservo.write(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...

pixels.setPixelColor(i, pixels.Color(255, 50, 0));


pixels.show(); // Send the updated pixel colors to the hardware.

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

pixels.setPixelColor(i, pixels.Color(100, 100, 100));

pixels.show(); // Send the updated pixel colors to the hardware.

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

pixels.setPixelColor(i, pixels.Color(0, 255, 0));

pixels.show(); // Send the updated pixel colors to the hardware.

delay(100);

// colorWipe(strip.Color(random(0, 255), random(0, 255), random(0, 255)), 0); // Red

// strip.setBrightness(map(sensorData, 500, 1023, 0, 255));

// delay(10);

pixels.clear();

else

pixels.clear();

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

pixels.setPixelColor(i, pixels.Color(0, 0, 0));

pixels.show(); // Send the updated pixel colors to the hardware.

myservo.write(90);

You might also like