Microphone, detect sound from piezo to move servo

Hey guys,

I'm really new to this.. Have been trying quite a few basic projects and i was trying to combine a few of them together.
The microphone works with the Piezo or the servo but when i combined them all up, the servo just does not seem to work.
And is there any possibility to re-adjust the sensitivity of the servo so it does not react to every noise detected ?
if there are more tutorials about this in the web pls do kindly state below

Cheers,
K

#include <Servo.h> 
Servo MyServo; 
int ServoPin = 9;
int piezo = 8;
int duration = 250;
int notes[] = 
{392,493,523,0,0,523,0,0,392,493,523,0,0,523,0,0,523,493,440,0,0,440,0,0,392,392,440,0,0,440,0,0,440,392,349,0,0,349,0,0,349,440,392,0,0,392,0,0,392,493,523,0,0,523,0,0,392,493,523,0,0,523,0,0}; //stand by me verse by ben.e.king

void setup() {
Serial.begin(300); 
MyServo.attach(ServoPin);
pinMode(piezo, OUTPUT);
}
void loop() {
int sensorValue = analogRead(0);
Serial.println(sensorValue);
for (int i = 0; i < 64; i++)
  {tone(piezo, notes[i], duration);
  delay (duration);
  }
  for (int i = 64; i>0; --i)
  {tone(piezo,notes[i],duration);
  }
sensorValue = map(sensorValue,0,250,0,180);
MyServo.write(sensorValue); 
}

Try running the servo off a seprate supply, don't forget to connect the grounds.

kelvinkl08:

...

int sensorValue = analogRead(0);
...
sensorValue = map(sensorValue,0,250,0,180);
MyServo.write(sensorValue);
}

sensorValue, being an analog input, will be between 0 and 1023 but you're only using the bottom 1/4 of that in map().... is that what you meant to do or are you anticipating this being a scaling?

sensorValue, being an analog input, will be between 0 and 1023 but you're only using the bottom 1/4 of that in map().... is that what you meant to do or are you anticipating this being a scaling?

I was anticipating it to be of scaling that might reduce the sensitivity of the noise. Would there be any way you could do that?

Try running the servo off a seprate supply, don't forget to connect the grounds.

Do you mean plugging the servo into a different Arduino and run them together?

I'm not sure what you mean by scaling there: the way you have it at the moment it only uses 0-200 which is 1 volt of the 5 possible.

By using another power supply, Grumpy_Mike means connect the servo to a power supply, like a 6V wall plug or 4xAA batteries, not power it from the Arduino 5V which may not have enough current. See pic attached.

servo power.png

I'm not sure what you mean by scaling there: the way you have it at the moment it only uses 0-200 which is 1 volt of the 5 possible.

By using another power supply, Grumpy_Mike means connect the servo to a power supply, like a 6V wall plug or 4xAA batteries, not power it from the Arduino 5V which may not have enough current. See pic attached.

I've changed the mapping back to 0,1023 and the wall plug of 9v connection into the arduino but still no avail. the 1st pict attached below shows my connections. the mic sensor is still working due to the light flickering along with the piezo. However, not the servo.

The 2nd pict would be my previous experiment before the 1st. Its about using the mic sensors to detect noise and move the servo. I'm not sure whether its a good thing, as the mic detects the noise made by the turning of servo or a bad thing where it is too sensitive resulting in the servo moving vigorously, making it hard to control. I'm not quite sure whether the problem has any relevance to this.

My aim was to make the servo turn when the mic detects a certain noise level, which is all part of the experiment project that i'm doing to generate a responsive facade where it will opens up when the noise level gets too high. the code for the previous experiment is seen below.

#include <Servo.h> 
Servo MyServo; 
int ServoPin = 9; 
void setup() {
Serial.begin(115200); 
MyServo.attach(ServoPin);
}
void loop() {
int sensorValue = analogRead(0);
Serial.println(sensorValue);
sensorValue = map(sensorValue,0,1023,0,180);
MyServo.write(sensorValue); 
}

the wall plug of 9v connection into the arduino but still no avail

That is not using a separate supply. I mean one supply to power the Arduino and another supply to power your servo.