How to Make a Voice Controlled Fan with Arduino?
1.Introduction
The sound sensor has a built-in capacitive electret microphone and power amplifier. It can be used to detect the sound intensity of the environment.
In this project, we use a sound sensor and a 130 motor to make a voice-activated smart fan.
2.Components Required
|
|
|
|
|
---|---|---|---|---|
Keyestudio Plus Mainboard*1 |
Sound Sensor*1 |
130 Motor Module*1 |
USB Cable*1 |
F-F Dupont Wires |
3.Component Knowledge
Sound sensor is usually used to detect the loudness of the sound in the surroundings. Arduino can collect its output signal through the analog input interface. The S pin is an analog output, which is the real-time output of the microphone voltage signal. The sensor comes with a potentiometer so you can adjust the signal strength. It also has two fixing holes so that the sensor can be installed on any other equipment. You can use it to make some interactive works, such as voice-operated switches.
4.Read the Analog Value of the Sound Sensor
We first use a simple code to read the analog value of the sound sensor and print it to the serial monitor, please refer to the following wiring diagram for the wiring.
/*
Read_the_sound_sensor_analog_value
http//www.keyestudio.com
*/
int soundpin=A1;// initializes the analog PIN A1 of the sound sensor
int val=0;// initializes the variable "val" with a value of 0
void setup()
{
Serial.begin(9600);// sets baudrate to 9600
}
void loop()
{
val=analogRead(soundpin);// reads the analog value of the sensor and assigns its value to "val"
Serial.println(val);// displays the value of "val"
delay(1000);// waits a second
}
Upload the code to the Plus Mainboard, connect the wires and power on first. Open the serial monitor, set the baud rate to 9600, and tap or clap the sensor, you can see that the analog value of the sound sensor has changed significantly.
5.Schematic Diagram and Wiring Diagram
Next, we use a sound sensor, a 130 motor module and a fan leaf to make a voice-activated fan. The schematic diagram and wiring diagram is as follows.
6.Code
/*
Voice controlled fan
http//www.keyestudio.com
*/
void setup() {
Serial.begin(9600);
pinMode(A3, OUTPUT);//sets digital A3 to "output"
pinMode(A2, OUTPUT);//sets digital A2 to "output"
}
void loop() {
int Soundvalue = analogRead(A1); // reads the analog value
Serial.println(Soundvalue);
if(Soundvalue>700)
{
// when the analog value is greater than the set value, starts the motor
digitalWrite(A3,HIGH);
digitalWrite(A2,LOW);
for(int i=0;i<5;i++){
delay(5000); // waits 5 seconds
}
}
else{
// closes the motor
digitalWrite(A3,LOW);
digitalWrite(A2,LOW);
}
}
7.Result
Upload the code to the PLUS Mainboard, connect the wires and power on. Then open the serial monitor, set the baud rate to 9600. The serial monitor displays the analog value of the sound. We blow into the sound sensor, the louder the sound is, the larger the analog value displayed on the serial monitor. When the value is greater than 700, the fan starts to work.
(Turn the blue potentiometer to adjust the sensitivity of the sound sensor)