Multi Funcional Sensors Play Ground With Arduino
by simaopintocorreia in Circuits > Tools
402 Views, 1 Favorites, 0 Comments
Multi Funcional Sensors Play Ground With Arduino

This is a multi-funcional project .
It can be mesure :distances,temperature in degrees Celcios,flame , light and tilt ,it is like a swiss knife ..no because it is eletroni and haven't knife ,how ever it is very use full very projects in just one .Amazing!!
Supplies
- HC-SR05(ultra-sonic sensor).
- Arduino UNO R3
- Piezo Buzzer.
- Flame Sensor
- tilt switch
- LDR
- LM35(temperature sensor)
- 10k potenciometer
- LCD 16x2
- Breadboard (large)
Mode's:





You can change the mode when you want ,you just have to turn the potenciometer to chose the mode.
1st Mode:Distance meter:
In this mode you can mesure distances between 0cm and 1000cm(or 10 meters if you want ), in "cm"(centimeters)unit.
2nd Mode :Fire Alarm:
If you have something burns it produce a noise(200Hz and 400Hz).
3rd Mode:Tilt alarm:
the same thing that the name exposes.
4th Mode:Light meter:
This mode mesure the light in "%".
5th Mode:Thermometer :
This thermometer isn't very precised put give us a real approximated read.
Wiring Sequence:
LCD:
* vss,GND * vdd,+5V * vo ,GND * rs,2 * rw,GND * e,3 * d4,4 * d5,5 * d6,6 * d7,7 * A,+5V * K,GND * ultra -sonic(HC-SR05): * vcc.+5V * echo,12 * trig,13 * output ,____ * GND,GND * BUZZER: * pin1,GND * pin2,9(PWM~) * potenciometer: * pin1,GND * Cursor,A4 * pin2,+5V * flame sensor * GND,GND * VCC,A3 * tilt swtch: * pin1,GND * pin2,A2 * LDR: * pin1,GND * pin2,A1 * LM35: * vcc,+5v * vood,A0 * GND,GND *
Code:
/*
* Creted by Simao Pinto Correia. * created in portugal , on Wednesday ,26th ,Jun,2019 * All rights reserved. */ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++WIRING SEQUENCE+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /* * LCD: * vss,GND * vdd,+5V * vo ,GND * rs,2 * rw,GND * e,3 * d4,4 * d5,5 * d6,6 * d7,7 * A,+5V * K,GND * ultra -sonic(HC-SR05): * vcc.+5V * echo,12 * trig,13 * output ,____ * GND,GND * BUZZER: * pin1,GND * pin2,9(PWM~) * potenciometer: * pin1,GND * Cursor,A4 * pin2,+5V * flame sensor * GND,GND * VCC,A3 * tilt swtch: * pin1,GND * pin2,A2 * LDR: * pin1,GND * pin2,A1 * LM35: * vcc,+5v * vood,A0 * GND,GND */ #include <LiquidCrystal.h> LiquidCrystal lcd(2,3,4,5,6,7); #define ECHO_PIN 12 #define TRIG_PIN 13 #define MELODY_PIN 9 #define FLAME_PIN A3 #define TILT_PIN A2 #define LDR_PIN A1 #define TEMP_PIN A0 //setup mode button: #define MODE_PIN A4 int faseButtom; void setup() { // put your setup code here, to run once: pinMode(MELODY_PIN,OUTPUT); pinMode(ECHO_PIN,INPUT); pinMode(TRIG_PIN,OUTPUT); pinMode(FLAME_PIN,INPUT); pinMode(TILT_PIN,INPUT); pinMode(LDR_PIN,INPUT); pinMode(TEMP_PIN,INPUT); pinMode(MODE_PIN,INPUT); lcd.begin(16,2); }void loop() { // put your main code here, to run repeatedly: if ((analogRead (MODE_PIN)<200)&&(analogRead(MODE_PIN)>0)){ faseButtom=1; } if ((analogRead (MODE_PIN)<400)&&(analogRead(MODE_PIN)>200)){ faseButtom=2; } if ((analogRead (MODE_PIN)<600)&&(analogRead(MODE_PIN)>400)){ faseButtom=3; } if ((analogRead (MODE_PIN)<800)&&(analogRead(MODE_PIN)>600)){ faseButtom=4; } if ((analogRead (MODE_PIN)<1023)&&(analogRead(MODE_PIN)>800)){ faseButtom=5; } if (faseButtom==1){ noTone(MELODY_PIN); long duration,distance; digitalWrite(TRIG_PIN,LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN,HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN,LOW); duration = pulseIn(ECHO_PIN,HIGH); distance = (duration/2) / 29.1; //lcd print the results. lcd.clear(); lcd.setCursor(1,0); lcd.print("distance:"); lcd.setCursor(1,1); lcd.print(distance); lcd.write(' '); lcd.print("cm"); } if (faseButtom==2){ noTone(MELODY_PIN); if (analogRead(FLAME_PIN)<200){ lcd.clear(); lcd.print("fire?"); } else{ lcd.clear(); lcd.print("FIRE!"); tone(MELODY_PIN,200); lcd.display(); delay(500); tone(MELODY_PIN,400); lcd.noDisplay(); delay(500); } } if(faseButtom==3){ noTone(MELODY_PIN); lcd.clear(); lcd.print("Tylt Mode"); if(digitalRead(TILT_PIN)==HIGH){ noTone(MELODY_PIN); lcd.clear(); lcd.setCursor(1,1); lcd.print("no Tylt"); } else{ lcd.clear(); lcd.setCursor(1,1); lcd.print("Tylting..."); tone(MELODY_PIN,200); delay(500); tone(MELODY_PIN,400); delay(400); tone(MELODY_PIN,600); delay(500); } } if(faseButtom==4){ noTone(MELODY_PIN); long READ; READ=analogRead(LDR_PIN)*100/1023; lcd.clear(); lcd.print("light"); lcd.setCursor(1,1); lcd.print(READ); lcd.write(' '); lcd.write('%'); } if (faseButtom==5){ noTone(MELODY_PIN); long temperature; temperature = analogRead(TEMP_PIN)*500/1023; lcd.clear(); lcd.print("Temp:"); lcd.setCursor(1,1); lcd.print(temperature); lcd.print(" degrees C"); delay(1000); } delay(200);
}
If you downlod this sketch to use ,download thi .ino version.
if you want this sketch to use some day that you don't no when , download the .zip file no1.
If you want to put this in a e-mail download .txt file.
if you want all these download fileNo2.zip that contains every thing.
2nd Revision.
I realise about some errors on the code and on the components .
Problems:
- HC-SR05 ultrasónic sensor is rare on the market
- The fire mode don't work very well.
- the temperature mode have bad mesures.
Solutions:
- Change the sensor to HC-SR04.
- Repair the fire mode.
- Repair the temperature mesure mode.
So ,I correct the code and change this one.
2nd Revision Code:
/*
* Creted by Simao Pinto Correia. * created in portugal , on Wednesday ,26th ,Jun,2019
modefied on Ago 21st '19 * All rights reserved. */ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++WIRING SEQUENCE+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /* * LCD: * vss,GND * vdd,+5V * vo ,GND * rs,2 * rw,GND * e,3 * d4,4 * d5,5 * d6,6 * d7,7 * A,+5V * K,GND * * ultra -sonic(HC-SR04): * vcc.+5V * echo,12 * trig,13 * GND,GND * * BUZZER: * pin1,GND * pin2,9(PWM~) * * potenciometer: * pin1,GND * Cursor,A4 * pin2,+5V * * flame sensor * GND,GND * VCC,A3 * * tilt swtch: * pin1,GND * pin2,A2 * * LDR: * pin1,GND * pin2,A1 * * LM35: * vcc,+5v * Vout,A0 * GND,GND */ #include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7); #define ECHO_PIN 12 #define TRIG_PIN 13 #define MELODY_PIN 9 #define FLAME_PIN A3 #define TILT_PIN A2 #define LDR_PIN A1 #define TEMP_PIN A0 //setup mode button: #define MODE_PIN A4 int faseButtom; void setup() { // put your setup code here, to run once: pinMode(MELODY_PIN,OUTPUT); pinMode(ECHO_PIN,INPUT); pinMode(TRIG_PIN,OUTPUT); pinMode(FLAME_PIN,INPUT); pinMode(TILT_PIN,INPUT); pinMode(LDR_PIN,INPUT); pinMode(TEMP_PIN,INPUT); pinMode(MODE_PIN,INPUT); lcd.begin(16,2); lcd.clear(); lcd.print("REV 2"); delay(2000); lcd.clear(); lcd.print("Created By"); lcd.setCursor(0,1); lcd.print("simaopintocorreia"); lcd.scrollDisplayLeft(); delay(200); lcd.clear(); }
void loop() { // put your main code here, to run repeatedly: if ((analogRead (MODE_PIN)<200)&&(analogRead(MODE_PIN)>0)){ faseButtom=1; } if ((analogRead (MODE_PIN)<400)&&(analogRead(MODE_PIN)>200)){ faseButtom=2; } if ((analogRead (MODE_PIN)<600)&&(analogRead(MODE_PIN)>400)){ faseButtom=3; } if ((analogRead (MODE_PIN)<800)&&(analogRead(MODE_PIN)>600)){ faseButtom=4; } if ((analogRead (MODE_PIN)<1023)&&(analogRead(MODE_PIN)>800)){ faseButtom=5; } if (faseButtom==1){ noTone(MELODY_PIN); long duration,distance; digitalWrite(TRIG_PIN,LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN,HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN,LOW); duration = pulseIn(ECHO_PIN,HIGH); distance = duration*0.034/2; //lcd print the results. lcd.clear(); lcd.setCursor(1,0); lcd.print("distance:"); lcd.setCursor(1,1); lcd.print(distance); lcd.write(' '); lcd.print("cm"); } if (faseButtom==2){ noTone(MELODY_PIN); if (analogRead(FLAME_PIN)<200){ lcd.clear(); lcd.print("fire?"); } else{ lcd.clear(); lcd.print("FIRE!"); tone(MELODY_PIN,200); lcd.noDisplay(); delay(500); tone(MELODY_PIN,400); lcd.display(); delay(500); } } if(faseButtom==3){ noTone(MELODY_PIN); lcd.clear(); lcd.print("Tylt Mode"); if(digitalRead(TILT_PIN)==HIGH){ noTone(MELODY_PIN); lcd.clear(); lcd.setCursor(1,1); lcd.print("no Tylt"); } else{ lcd.clear(); lcd.setCursor(1,1); lcd.print("Tylting..."); tone(MELODY_PIN,200); delay(500); tone(MELODY_PIN,400); delay(400); tone(MELODY_PIN,600); delay(500); } } if(faseButtom==4){ noTone(MELODY_PIN); long READ; READ=analogRead(LDR_PIN)*100/1023; lcd.clear(); lcd.print("light"); lcd.setCursor(1,1); lcd.print(READ); lcd.write(' '); lcd.write('%'); } if (faseButtom==5){ noTone(MELODY_PIN); long temperature,temp2;
map(temperature,0,1023,0,500); lcd.clear(); lcd.print("Temp:"); lcd.setCursor(1,1); lcd.print(temperature); lcd.print(" degrees C"); delay(1000); } delay(200);
}