Introduction
In this project, we will create a smoke detector setup using Arduino in the Tinkercad platform. The setup is simple and can be made by anyone. Also, the components we use are cheap and the hardware setup can be used in our homes, workplaces, etc. So let’s get started with the project and see its simulation.
You can visit the Tinkercad platform by clicking here. If you’re unfamiliar with the Tinkercad platform and want to know more about it, you can click here.
Components Required
- Arduino UNO R3
- Gas sensor
- Piezo sensor
- RGB LED
- 220Ω resistors (3)
- 1kΩ resistor
- 22kΩ resistor
- Breadboard
Setting up the Smoke Detector
First and foremost, drag all the above-mentioned components into the Tinkercad workspace.
Subsequently, let’s start connecting the components one by one. So, let’s start by looking into the gas sensor connections. The gas sensor provided in Tinkercad has 6 terminals, namely A1, H1, A2, B1, H2, and B2. Connect the terminals A1, H1, and A2 to the power supply. After that, connect terminal B1 to the power supply and the terminals H2 and B2 to the ground. In order to increase the accuracy and sensitivity of the gas sensor, we connect a 22kΩ load resistor between the terminal B2 and the ground.
Subsequently, let’s connect the RGB LED which acts as an indicator for the smoke detector setup. The RGB LED has 4 terminals, namely RED, CATHODE, BLUE, AND GREEN. Connect the cathode terminal to the ground. Next, connect the terminals red, blue, and green to the digital pins 13, 11, and 10 respectively (we have chosen these pins for this project, any of the digital pins can be used for the connection). We use the 1kΩ resistors in the connection between the terminals and the digital pins. This is done to limit the current through the LED. As a result, the setup would look like this
Following this, we connect the piezo sensor to our setup. This is done so as to make a buzzing noise when smoke is detected. The piezo sensor has two terminals namely POSITIVE(+) and NEGATIVE(-). Connect the positive terminal to pin number 6 and the negative terminal to the ground. We need to limit the current flow to the sensor. Hence, connect the 1kΩ resistor in between the connection from the positive terminal to the digital pin. Therefore, the final circuit would look as follows
Coding the Smoke Detector
So now that the smoke detector circuit is complete, let’s dive into the coding part. The complete code is as follows
// C++ code
//
void setup()
{
Serial.begin(9600);
pinMode(A1,INPUT);
pinMode(6,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(13,OUTPUT);
}
void loop()
{
int sensorValue = analogRead(A1);
Serial.print("Gas sensor reading = ");
Serial.println(sensorValue);
if(sensorValue > 800){
digitalWrite(13,HIGH);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(6,HIGH);
}
else{
digitalWrite(13,LOW);
digitalWrite(11,LOW);
digitalWrite(10,HIGH);
digitalWrite(6,LOW);
}
}
Firstly, within the setup() function, we use Serial.begin() function in order to establish a serial communication. We set pin A1 as the input, and pins 6, 10, 11, and 13 as the output using the pinMode() function.
Subsequently, we start coding the loop() function. We read the smoke sensor readings from pin A1 using the analogRead() function. Then we assign the values to an integer type variable named “sensorValue”. Next, we print the gas sensor readings to the serial monitor using the Serial.print() function. For this project, we have set the threshold value for gas sensor readings as 800. So, if the readings are over the threshold value, the LED turns RED and the piezo sensor starts buzzing. If the readings are below the threshold value, the LED remains GREEN and the piezo sensor doesn’t make any buzzing noise. We accomplish this by using the if-else loop and setting the pins as HIGH/LOW using the digitalWrite() functions.
So now, the coding part is complete. Further, let’s simulate the circuit and see the results.
Here, we can see that when the gas sensor readings are below the threshold value, the LED remains GREEN and the piezo sensor doesn’t make any buzzing noise. The serial monitor continuously displays the gas sensor readings on a real-time basis.
Here, we can see that when the readings are above the threshold value, the LED turns RED and the piezo sensor starts buzzing. The serial monitor value updates on moving the smoke nearer to the gas sensor.
Conclusion
So with this, we have completed our smoke detector setup using the Tinkercad platform. Hope that this project was informative as well as interesting.
Happy Learning!