$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS IoT

Intel® Edison Hands-on Day 5: Voice Activated Bulb

DFRobot Oct 31 2014 169

Voice Activated Bulb 
Had you ever been curious about the voice activated bulb in your childhood? Had you ever stamped again and again and just turn on the light? As long as you clap your hands, the light will be turn on. In this section we will make such a voice activated bulb. We would use a sound sensor. Through this sensor, we can make much more interactive stuffs, such as voice activated flaring drum.
 
Components required


 
Connection

Analog Sound Sensor → Analog Pin 0
Digital piranha LED light module → Digital Pin 13


Coding
 // Voice Activated Bulb int soundPin = 0;       //The Pin number of the sound sensor int ledPin =  13;       //The Pin number of the LED void setup() {  pinMode(ledPin, OUTPUT); // Serial.begin(9600);    //just for debuging } void loop(){  int soundState = analogRead(soundPin);  //Read the analog value from sound sensor // Serial.println(soundState);      //Print the value of the sound sensor //If the sound value is greater than 10, light will be turned on. Otherwise it will be turned off.  if (soundState > 10) {                digitalWrite(ledPin, HIGH);      delay(10000);  }else{      digitalWrite(ledPin, LOW);  } }
Try to clap your hands, or to say something near the sound sensor. Try whether the light will be light up.

 
Hardware Principle?Analog Input—Digital Output?

Actually, there are some difference between Analog and Digital. Analog uses continuous range of values to represent information (in our case 0~1023). Digital uses discrete or discontinuous values to represent information (in our case 0 and 1 )
So this is an analog input and digital output demo.


 
 
Code review 

Sound sensor is the input device, so we need to read the analog value from the specific pin. The Syntax looks like this?
analogRead(pin)
Reads the value from the specified analog pin. The Edison Arduino kit contains a 6 channel 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. For example, the analog value 512 stands for 2.5V.
 
If the sound value is greater than the threshold value (in this example is 10), light will be turned on. Otherwise it will be turned off.
if (soundState > 10) {          
       ...
}else{
       ...
}
   
Remove the comment and you can also open the serial monitor to see the value read from sound sensor. You can modify the threshold value to trigger the LED in different sound volume.
 
  

REVIEW