/* This arduino code for the Arduino UNO detects various data from different sensors. With a
HC SR04 Ultrasonic Sensor Distance Measuring Module it measures the distance in cm. With the
use of a Humidity sensor it measures temperatures and huminity in the air. All of the data
is sisplayed on a connected LCD 1062 screen the buzzer will also react on the distance meter if < 20
and if noise is louder then 40. All the data are displayed in a constant seq-
uence. All the measurements are done in different frequencies, to ensure a more precise reading.
For further data there is a lightsensor attached that measures the amunt of light in uint Lux.
When these data are shown on the display, there are also comments set per interval of data.
This means when the light sensor has a value between 0 and 5 it also says Dark on the LCD.
The last measurement this setup does is sound. The soundsensor measures the amount of Db,
and displays the text "Keep quiet, shhh". This is of course as all other output editable via
the codes below */
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.
const int trigPin = 9; // trigpin digital pin 9
const int echoPin = 10; // Echopin digital pin 10
long duration;
int distanceCm, distanceInch;
#include <DHT.h> // For Dht sensor
#include <Wire.h> // Including wire
// Set DHT pin:
#define DHTPIN A0
// Define SDA and SCL pin for LCD:
#define SDAPin A4 // Data pin
#define SCLPin A5 // Clock pin
// Set DHT type, uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
// Initialize DHT sensor for normal 16mhz Arduino:
DHT dht = DHT(DHTPIN, DHTTYPE);
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered):
int AudioPin = A3; // Analog Sound Sensor Module connected To This Pin
int value; // Variable to store the sensor input value
int buzzer_pin = 12;
float RLDR; // define RLDR value (measured value of the LDR with the resistance)
float Vout; // define Vout value (output voltage)
float Lux; // define Vout value (vibrance of the light
void setup() {
Serial.begin (9600);
lcd.init(); // Initiate LCD
lcd.backlight(); // Initiate Backligth lcd screen
pinMode(trigPin, OUTPUT); // Set trigpin as output
pinMode(echoPin, INPUT); // Set Echopin as Input
pinMode(AudioPin,INPUT); // Set the pin to read from sensor
pinMode (buzzer_pin, OUTPUT);
dht.begin(); // initiate Dht sensor
}
void loop() {
{
delay(100); // stop output trigpin
digitalWrite(trigPin, LOW); // 2 ms delay before signal repeats
delayMicroseconds(2); // Delay 2 ms
digitalWrite(trigPin, HIGH); // start output trigpin
delayMicroseconds(10); // Delay 10ms
digitalWrite(trigPin, LOW); // stop output trigpin
duration = pulseIn(echoPin, HIGH); // Duration of pulse
distanceCm= duration*0.034/2; // formula to measure distance in cm
distanceInch = duration*0.0133/2; // formula to measure distance in inches
lcd.setCursor(0,0); // Sets the location at which the text will be written to the LCD display
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print(" cm"); // print cm on screen
delay(3000); // Delay 3000ms
lcd.begin (16, 8); // start Lcd
delay(1000); // Delay 1000ms
if (distanceCm < 20)
{
tone(12, 100); // The"tone ( x , y )" command creates a sound
delay(1000); // with the duration of one second
noTone(12); // The tone is deactivated
delay(1000); // for one second
tone(12, 100); // The"tone ( x , y )" command creates a sound
delay(1000); // with the duration of one second
noTone(12); // The tone is deactivated
delay(1000); // for one second
}
}
{
lcd.clear ();
delay(100); // Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read the humidity in %:
float h = dht.readHumidity(); // Read the temperature as Celsius:
float t = dht.readTemperature(); // Read the temperature as Fahrenheit:
float f = dht.readTemperature(true); // Compute heat index in Fahrenheit (default):
float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius:
float hic = dht.computeHeatIndex(t, h, false); // Print the temperature and the humidity on the LCD:
lcd.setCursor(0, 0); // Sets text to firts row of Lcd
lcd.print("Temp: "); // Sets word temp: to row 1
lcd.print(t); // Shows temperature
lcd.print(" " "\xDF" "C"); // shows C with degrees sign
lcd.setCursor(0, 1); // Sets text to Second row of Lcd
lcd.print("Humid: "); // Sets word humid: to row 1
lcd.print(h); // Shows the humidity
lcd.print(" %"); // sets percentage after humidity number
delay(3000); // Print screen for 3000ms
lcd.begin (16, 2); // Begin Lcd screen
lcd.clear (); // Clear Lcd screen printe
delay(100); // Delay 100 for next sensor
}
{
value = analogRead (AudioPin); // Reading the sensor data
if (value > 40)
{ // Initializing the minimum sensitivity value
lcd.setCursor(5,0); // Set the screen print location
lcd.print( "Keep" ); // Printing the message
lcd.setCursor(2,1); // Set the screen print location
lcd.print("Quite, shhht"); // Printing the message
delay(3000); // Providing delay for the message
lcd.clear(); // Clear the lcd screen for next printing
}
value = analogRead (AudioPin); // Reading the sensor data from analogread ( audiopin)
if (value > 40)
{
tone(12, 100); // The"tone ( x , y )" command creates a sound
delay(100); // with the duration of one second
noTone(12); // The tone is deactivated
delay(100); // for one second
tone(12, 100); // The"tone ( x , y )" command creates a sound
delay(100); // with the duration of one second
noTone(12); // The tone is deactivated
delay(100); // for one second
tone(12, 100); // The"tone ( x , y )" command creates a sound
delay(100); // with the duration of one second
noTone(12); // The tone is deactivated
delay(100); // for one second
tone(12, 100); // The"tone ( x , y )" command creates a sound
delay(100); // with the duration of one second
noTone(12); // The tone is deactivated
delay(100); // for one second
}
}
{
int sensorValue = analogRead(A2); // initiate sensor value from pin analog A2
Vout = (sensorValue * 0.0048828125); // measured value times 0.0048828125 to get vout number
RLDR = (10000.0 * (5 - Vout))/Vout; // to get RLDR value 10000.0 * (5-vout)) / Vout
Lux = (RLDR/500); // RLDR / 500 to extract
lcd.setCursor(0, 0); // set cursur on 0,0 on lcd screen
lcd.print("LIGHT : "); // Print Light on lcd
lcd.print( Lux ); // Print Lux on lcd
delay(6000); // Delay with 6000ms
lcd.setCursor(0, 1);
if ((Lux >= 0) && (Lux <= 5))
{
lcd.print("DARK"); //Print dark if between 0-5
}
else if ((Lux > 5) && (Lux <= 14))
{
lcd.print("DIM"); //Print Dim if between 0-14
}
else if ((Lux > 14) && (Lux <= 50))
{
lcd.print("BRIGHT"); //Print Bright if between 14-50
}
else
{
lcd.print("VERY BRIGHT"); // Print Very Bright
}
delay(6000) ; // show for 6000ms
lcd.clear(); // clear screen and start loop over
delay(100); // Delay 100 for next sensor
}
}
Comments
Please log in or sign up to comment.