So continuing with my developments to Sparki I purchased this sound sensor:
It was really easy to use I connected the GND to GND and VCC to 5V VCC ports and then the pin labelled output to analog pin 0.
Then I wrote a simple conversation bot program to test out the sensor and see if by talking randomly to Sparki I could make it seem like a conversation. This is the code:
#include <Sparki.h> // include the sparki library void setup() { sparki.servo(0); delay(2000); int soundA = analogRead(0); delay (2000); sparki.clearLCD(); // print out the value you read: sparki.print(soundA); sparki.updateLCD(); delay (1000); int soundB=analogRead(0); delay(2000); sparki.print(soundB); sparki.updateLCD(); delay (1000); int soundC = analogRead(0); delay (2000); sparki.clearLCD(); // print out the value you read: sparki.print(soundC); sparki.updateLCD(); delay (1000); if ((soundB> 1.26) || (soundC>1.26)) { sparki.clearLCD(); sparki.drawString(10, 1, "hi ash how are you?"); sparki.updateLCD(); delay(1000); int soundA = analogRead(0); delay (2000); sparki.clearLCD(); // print out the value you read: sparki.print(soundA); sparki.updateLCD(); delay (1000); int soundB=analogRead(0); delay(2000); sparki.print(soundB); sparki.updateLCD(); delay (1000); int soundC = analogRead(0); delay (2000); sparki.clearLCD(); // print out the value you read: sparki.print(soundC); sparki.updateLCD(); delay (1000); if((soundB> 1.26) || (soundC>1.26)) { delay(2000); sparki.clearLCD(); sparki.drawString(10, 1, "affirmative, you have had a good day"); sparki.updateLCD(); delay(1000); sparki.clearLCD(); randomSeed(analogRead(1)); int response = random(1, 10); sparki.clearLCD(); sparki.print(response); sparki.updateLCD(); delay(1000); if (response<3) { sparki.drawString(20, 2, "when I am happy I dance...I'm dancing!"); sparki.updateLCD(); delay(1000); sparki.servo(0); sparki.moveForward(3); sparki.RGB(RGB_GREEN); sparki.beep(); sparki.moveLeft(90); sparki.RGB(RGB_RED); sparki.beep(); sparki.moveForward(3); sparki.RGB(RGB_GREEN); sparki.moveBackward(3); sparki.beep(); sparki.moveRight(90); sparki.RGB(RGB_BLUE); sparki.beep(); delay(2000); } if (response>=3) { sparki.clearLCD(); sparki.drawString(20, 2, "here is a rainbow"); sparki.RGB(RGB_RED); delay(500); sparki.RGB(RGB_ORANGE); delay(500); sparki.RGB(RGB_YELLOW); delay(500); sparki.RGB(RGB_GREEN); delay(500); sparki.beep(); sparki.RGB(RGB_BLUE); delay(500); sparki.RGB(RGB_INDIGO); delay(500); sparki.RGB(RGB_VIOLET); delay(500); sparki.beep(); sparki.RGB(RGB_WHITE); delay(500); sparki.RGB(RGB_OFF); delay(500); } else { delay(2000); sparki.clearLCD(); sparki.drawString(10, 1, "oh dear maybe i can cheer you up?"); sparki.updateLCD(); delay(1000); sparki.clearLCD(); randomSeed(analogRead(1)); int response = random(1, 10); sparki.clearLCD(); sparki.print(response); sparki.updateLCD(); delay(1000); if (response<3) { sparki.drawString(20, 2, "maybe my dance can make you smile"); sparki.updateLCD(); delay(1000); sparki.servo(0); sparki.moveForward(3); sparki.RGB(RGB_GREEN); sparki.beep(); sparki.moveLeft(90); sparki.RGB(RGB_RED); sparki.beep(); sparki.moveForward(3); sparki.RGB(RGB_GREEN); sparki.moveBackward(3); sparki.beep(); sparki.moveRight(90); sparki.RGB(RGB_BLUE); sparki.beep(); delay(2000); } if (response>=3) { sparki.clearLCD(); sparki.drawString(20,2, "This is my sad dance"); sparki.updateLCD(); delay(1000); sparki.moveForward(5); sparki.beep(500); sparki.moveRight(10); sparki.moveLeft(10); sparki.beep(350); sparki.moveBackward(5); sparki.moveLeft(30); sparki.beep(600); sparki.moveRight(60); sparki.beep(400); } } } } }
This is something that I will be continuing to work on and something I find really interesting. If anybody else is making something similar I would be really interested to know 🙂 🙂
I’ve never played with a sound sensor. I have an arduino starter kit that I picked up recently, but I haven’t gotten to sound yet. The sound you read is just an int? How much information can you get out of that?
LikeLike
Hardly an… It basically prints a number between 1 and about 138 – the longer it detects the sound for the higher the reading. I only use it for whether sparki hearing the sound or not- either sounds or no sounds -so for something more complicated I’m not sure what to do sorry
LikeLike