Arduino Tutorial for Beginners – Read from Photosensitive Sensor,Gas Sensor,Microphone Sensor




We’ve already known how to read an analog signal from some basic devices in the previous article : Analog Signal

In this post on Arduino Tutorial For Beginners, this topic about how to read Analog Signal from the popular peripheral devices to make an application in life. We will know how to connect some devices : Photosensitive Sensor,Gas Sensor,Microphone Sensor,… to Arduino and read analog from them to control led. With this simple control we can apply to control the huge things in our life.

  • Detect Light to create an automatic light, door ,…
  • Detect Gas to avoid burn, explosive ,…
  • Detect Sound to control via voice(expert knowledge require),…
  • And many analog devices help you build your smart environment

In this topic I will make an example with 2/3 devices above:

  • First is Photosensitive Sensor, we will connect the sensor as the diagram below:

Diagramphotosensor

 

 

Example code:

With the code below, we will print out to Serial Monitor the value are read from Photosensitive sensor when we put the light near or far of the sensor. And then we will use that value with if condition to control our device (led,..).


void setup()
{
Serial.begin(9600); // Baudrate Serial Monitor 9600
pinMode(13,OUTPUT); // Set default led on Arduino board is OUTPUT
}
void loop()
{
Serial.println(analogRead(A0)); // Print the value to SerialMonitor
if(analogRead(A0) > 600) // If the analog value is greater than 600 -> led will be turned on, because when we put the light near the sensor, the value will print out greater than 600 -> we will take 600
{
digitalWrite(13,HIGH);
}
else // If not, we will turned off led. because when we put the light far of the sensor, the analog value will be lower than 600
{
digitalWrite?(13,LOW);
}

  • Second, we will use Gas Sensor:

DiagramGassensor

Example code:

With the code below, we will print out to Serial Monitor the value are read from Gas sensor when we spray gas to the sensor. And then we will use that value with if condition to control our device (led,..).


void setup()
{
Serial.begin(9600); // Baudrate Serial Monitor 9600
pinMode(13,OUTPUT); // Set default led on Arduino board is OUTPUT
}
void loop()
{
Serial.println(analogRead(A0)); // Print the value to SerialMonitor
if(analogRead(A0) > 300) // If the analog value is greater than 300 -> led will be turned on, because when we spray gas into the sensor the value will be increase greater than 300 around 15seconds
{
digitalWrite(13,HIGH);
}
else // If not, we will turned off led. because when we don't spray gas, the analog value will be lower than 300
{
digitalWrite?(13,LOW);
}
}

  • Extra diagram for microphone sensor (SP2430) or the other basic microphone sensors:

MicDiagram


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*