Talking Jaw using attiny 85

I am using thumb USB Arduino to move puppet jaw servo. Using the code below but the issue here is that servo moves at every tiny sound change, ..Is there a way to filter the signal that servo moves only when significant characters are said ? or should I deal with it using hardware adding certain filters (capacitors and resistors) before the input pin 1 ?

/*
  Make a Servo Move to Sound.
   This example code is in the public domain.
   2012 by Cenk Özdemir
*/
// for servo stuff we include the servo library
#include <Servo.h>
// creating a servo object
Servo myservo;
// Some Variables we need
int ServoPin = 1;
int SoundInPin = 5;
// the setup routine runs once when you press reset:
void setup() {
  // initialize

    myservo.attach(ServoPin);
     pinMode(SoundInPin, INPUT);
   
}
// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(SoundInPin);
  // We Map it here down to the possible range of servo moovment.
  sensorValue = map(sensorValue,0,512,0,180);
  // note normaly the 512 is 1023 becouse of analog reading shud go so far, but i changed that to get better readings.
myservo.write(90);
// setting the servo into standard position
  int MoveDelayValue = map(sensorValue,0,255,0,sensorValue);

  // maping the same reading a little bit more down to calculate the time your servo gets to make the one Move
if (sensorValue > 33) { // to cut off some static readings only if the reading gets higher then 33 it begings to work
   delay(1);  // a static delay to smooth things out...
// now move the servo to our mapped reading
  myservo.write(sensorValue); 
 
} 

 
      
}

Try higher sensor value

Is there a way to filter the signal that servo moves only when significant characters are said ?

Yes.

You can filter either in software or hardware. In hardware you need an envelope follower before the A/D converter. Envelope detector - Wikipedia

Or you can do the same thing in software by following the values and making note of the biggest one. After a certain time use the biggest sample you have to set the jaw servo value.

A bit like this, which was done with lights.

thanks, I found the envelope detector circuit . I will try it tonight and see. One thing I found from working on this digispark usb arduino is that many libraries do not function with it. therefore one may not benefit from some very neat servo libraries and stick to basics.

This is already in your sketch:

if (sensorValue > 33) { // to cut off some static readings only if the reading gets higher then 33 it begings to work

Does it work if you use a bigger value than 33?

The Digispark is an Attiny85 based microcontroller development board , as the name implies it is a tiny processor. Not much memory, not much in the way of peripherals like timers and UARTs.

In fact I think is is false advertising to call it a Uno. It is nothing like a Uno.

The code below does not run
the error message say
exit status 1
'Servo' does not name a type

#include <SoftwareServo.h>

//audio 2 jaw
// for servo stuff we include the servo library
Servo servo1;
int SensorPin = 5;
// creating a servo object
int audioVal = 0;
void setup() {
  Serial.begin(9600);
  servo1.attach(1);
  pinMode(SensorPin, INPUT);  
}
void loop() {
 audioVal = analogRead(SensorPin);
 Serial.println(audioVal);
 if (audioVal <= 500)
 {servo1.write(150);}
 else if (audioVal > 500);
{servo1.write(30);}
 delay(50);
}

Replace

Servo servo1;

with

SoftwareServo servo1;

Grumpy_Mike:
Replace

Servo servo1;

with

SoftwareServo servo1;

Yes that was the mistake, Many thanks. But since I ran it on digispark USB stump, I need to make sure both input and output are PWM pins. wish me luck.

Now I loaded this code..compiles & loads but not working..plz advice :frowning:

#include <SoftwareServo.h>

//audio 2 jaw
// for servo stuff we include the servo library
SoftwareServo servo1;
int SensorPin = 4; // pin 4 can read analog input
// creating a servo object
int audioVal = 0;
void setup() {
  Serial.begin(9600);
  servo1.attach(1); // pin 1 is PWM can feed the servo
  pinMode(SensorPin, INPUT);
 pinMode(1, OUTPUT);
}
void loop() {
 audioVal = analogRead(SensorPin);
 Serial.println(audioVal);
 if (audioVal <= 500)
 {servo1.write(150);}
 else if (audioVal > 500);
{servo1.write(30);}
 delay(50);
}

I advise that you describe what you mean by "not working". What happened? What did you expect to happen? I also advise to never use the words "not working' on this forum without an explanation.

But since I ran it on digispark USB stump, I need to make sure both input and output are PWM pins.

Why is this?

Try reducing the threshold values you have. A value of 500 implies you have a 5V peak to peak audio signal, and that is not very normal. You need it at least 1.4V peak to peak to overcome the diode's forward voltage.

Why are you using the serial port? The ATtiny does not have any UART and so can not print anything.
The documentation says:-

he Digispark supports all features found in the IDE with the exception of the serial monitor and the burn bootloader functionality.

Not working meant servo not moving although applying audio to analog input.
I removed the serialPrint, yes was meant to show whats happening, but then as GM pointed attiny cannot do it...
I tried removing the 2 threshold limits the 500 , and removed the if statement, all of it..then I named a variable called mover at the beginning of code, and used mapping code, but still servo not responding to audio.

mover = map(audioVal ,0 , 1023, 20, 150);//mapping audio value into servo limits
servo1.write (mover);

the audio input circuit I used is this

Yes you are applying audio to it but at what voltage? Unless the voltage is big enough you will get no change on the analogue input.

audio hovers between 1-3 volt

Goldenshuttle:
audio hovers between 1-3 volt

How are you measuring that?

I think we need to see a photograph that clearly shows your wiring.