Components and supplies
1
Arduino UNO
1
DHT11 Temperature & Humidity Sensor (4 pins)
1
Jumper wires (generic)
1
Light Detector, OPIC
1
Breadboard (generic)
1
Solderless Breadboard Half Size
1
RGB LCD Shield Kit, 16x2 Character Display
1
Ultrasonic Sensor - HC-SR04 (Generic)
1
Resistor 100 ohm
1
SparkFun Sound Detector (with Headers)
1
Buzzer
Project description
Code
Code for 5 sensor and 2 actor module
csharp
1/* This arduino code for the Arduino UNO detects various data from different sensors. With a 2HC SR04 Ultrasonic Sensor Distance Measuring Module it measures the distance in cm. With the 3use of a Humidity sensor it measures temperatures and huminity in the air. All of the data 4is sisplayed on a connected LCD 1062 screen the buzzer will also react on the distance meter if < 20 5and if noise is louder then 40. All the data are displayed in a constant seq- 6uence. All the measurements are done in different frequencies, to ensure a more precise reading. 7For further data there is a lightsensor attached that measures the amunt of light in uint Lux. 8When these data are shown on the display, there are also comments set per interval of data. 9This means when the light sensor has a value between 0 and 5 it also says Dark on the LCD. 10The last measurement this setup does is sound. The soundsensor measures the amount of Db, 11and displays the text "Keep quiet, shhh". This is of course as all other output editable via 12the codes below */ 13 14 15#include <LiquidCrystal_I2C.h> 16LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD. 17const int trigPin = 9; // trigpin digital pin 9 18const int echoPin = 10; // Echopin digital pin 10 19long duration; 20int distanceCm, distanceInch; 21 22#include <DHT.h> // For Dht sensor 23#include <Wire.h> // Including wire 24 25 // Set DHT pin: 26#define DHTPIN A0 27 // Define SDA and SCL pin for LCD: 28#define SDAPin A4 // Data pin 29#define SCLPin A5 // Clock pin 30 // Set DHT type, uncomment whatever type you're using! 31#define DHTTYPE DHT11 // DHT 11 32 // Initialize DHT sensor for normal 16mhz Arduino: 33DHT dht = DHT(DHTPIN, DHTTYPE); 34 // Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered): 35 36int AudioPin = A3; // Analog Sound Sensor Module connected To This Pin 37int value; // Variable to store the sensor input value 38int buzzer_pin = 12; 39 40float RLDR; // define RLDR value (measured value of the LDR with the resistance) 41float Vout; // define Vout value (output voltage) 42float Lux; // define Vout value (vibrance of the light 43 44void setup() { 45Serial.begin (9600); 46lcd.init(); // Initiate LCD 47lcd.backlight(); // Initiate Backligth lcd screen 48pinMode(trigPin, OUTPUT); // Set trigpin as output 49pinMode(echoPin, INPUT); // Set Echopin as Input 50pinMode(AudioPin,INPUT); // Set the pin to read from sensor 51pinMode (buzzer_pin, OUTPUT); 52dht.begin(); // initiate Dht sensor 53} 54 55 56 57void loop() { 58{ 59 delay(100); // stop output trigpin 60 digitalWrite(trigPin, LOW); // 2 ms delay before signal repeats 61 delayMicroseconds(2); // Delay 2 ms 62 digitalWrite(trigPin, HIGH); // start output trigpin 63 delayMicroseconds(10); // Delay 10ms 64 digitalWrite(trigPin, LOW); // stop output trigpin 65 duration = pulseIn(echoPin, HIGH); // Duration of pulse 66 distanceCm= duration*0.034/2; // formula to measure distance in cm 67 distanceInch = duration*0.0133/2; // formula to measure distance in inches 68 lcd.setCursor(0,0); // Sets the location at which the text will be written to the LCD display 69 lcd.print("Distance: "); // Prints string "Distance" on the LCD 70 lcd.print(distanceCm); // Prints the distance value from the sensor 71 lcd.print(" cm"); // print cm on screen 72 delay(3000); // Delay 3000ms 73 lcd.begin (16, 8); // start Lcd 74 delay(1000); // Delay 1000ms 75 if (distanceCm < 20) 76 { 77 tone(12, 100); // The"tone ( x , y )" command creates a sound 78 delay(1000); // with the duration of one second 79 noTone(12); // The tone is deactivated 80 delay(1000); // for one second 81 tone(12, 100); // The"tone ( x , y )" command creates a sound 82 delay(1000); // with the duration of one second 83 noTone(12); // The tone is deactivated 84 delay(1000); // for one second 85 } 86 87} 88{ 89 lcd.clear (); 90 delay(100); // Reading temperature or humidity takes about 250 milliseconds! 91 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 92 // Read the humidity in %: 93 float h = dht.readHumidity(); // Read the temperature as Celsius: 94 float t = dht.readTemperature(); // Read the temperature as Fahrenheit: 95 float f = dht.readTemperature(true); // Compute heat index in Fahrenheit (default): 96 float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius: 97 float hic = dht.computeHeatIndex(t, h, false); // Print the temperature and the humidity on the LCD: 98 99 lcd.setCursor(0, 0); // Sets text to firts row of Lcd 100 lcd.print("Temp: "); // Sets word temp: to row 1 101 lcd.print(t); // Shows temperature 102 lcd.print(" " "\\xDF" "C"); // shows C with degrees sign 103 lcd.setCursor(0, 1); // Sets text to Second row of Lcd 104 lcd.print("Humid: "); // Sets word humid: to row 1 105 lcd.print(h); // Shows the humidity 106 lcd.print(" %"); // sets percentage after humidity number 107 delay(3000); // Print screen for 3000ms 108 lcd.begin (16, 2); // Begin Lcd screen 109 lcd.clear (); // Clear Lcd screen printe 110 delay(100); // Delay 100 for next sensor 111} 112 { 113 value = analogRead (AudioPin); // Reading the sensor data 114 if (value > 40) 115 { // Initializing the minimum sensitivity value 116 lcd.setCursor(5,0); // Set the screen print location 117 lcd.print( "Keep" ); // Printing the message 118 lcd.setCursor(2,1); // Set the screen print location 119 lcd.print("Quite, shhht"); // Printing the message 120 delay(3000); // Providing delay for the message 121 lcd.clear(); // Clear the lcd screen for next printing 122 } 123 value = analogRead (AudioPin); // Reading the sensor data from analogread ( audiopin) 124 if (value > 40) 125 { 126 tone(12, 100); // The"tone ( x , y )" command creates a sound 127 delay(100); // with the duration of one second 128 noTone(12); // The tone is deactivated 129 delay(100); // for one second 130 tone(12, 100); // The"tone ( x , y )" command creates a sound 131 delay(100); // with the duration of one second 132 noTone(12); // The tone is deactivated 133 delay(100); // for one second 134 tone(12, 100); // The"tone ( x , y )" command creates a sound 135 delay(100); // with the duration of one second 136 noTone(12); // The tone is deactivated 137 delay(100); // for one second 138 tone(12, 100); // The"tone ( x , y )" command creates a sound 139 delay(100); // with the duration of one second 140 noTone(12); // The tone is deactivated 141 delay(100); // for one second 142 } 143 } 144 { 145 int sensorValue = analogRead(A2); // initiate sensor value from pin analog A2 146 Vout = (sensorValue * 0.0048828125); // measured value times 0.0048828125 to get vout number 147 RLDR = (10000.0 * (5 - Vout))/Vout; // to get RLDR value 10000.0 * (5-vout)) / Vout 148 Lux = (RLDR/500); // RLDR / 500 to extract 149 lcd.setCursor(0, 0); // set cursur on 0,0 on lcd screen 150 lcd.print("LIGHT : "); // Print Light on lcd 151 lcd.print( Lux ); // Print Lux on lcd 152 delay(6000); // Delay with 6000ms 153 lcd.setCursor(0, 1); 154 if ((Lux >= 0) && (Lux <= 5)) 155 { 156 lcd.print("DARK"); //Print dark if between 0-5 157 } 158 else if ((Lux > 5) && (Lux <= 14)) 159 { 160 lcd.print("DIM"); //Print Dim if between 0-14 161 } 162 else if ((Lux > 14) && (Lux <= 50)) 163 { 164 lcd.print("BRIGHT"); //Print Bright if between 14-50 165 } 166 else 167 { 168 lcd.print("VERY BRIGHT"); // Print Very Bright 169 } 170 delay(6000) ; // show for 6000ms 171 lcd.clear(); // clear screen and start loop over 172 delay(100); // Delay 100 for next sensor 173 } 174 } 175
Downloadable files
Setup
Setup

Setup
Setup

Comments
Only logged in users can leave comments