0% found this document useful (0 votes)
46 views3 pages

For Temperature Sensor Dht11

The document provides code for reading sensor values from four different sensors: a DHT11 temperature and humidity sensor, a pH sensor, an LDR light sensor, and a TDS sensor. The DHT11 code initializes the sensor and prints the temperature and humidity readings every 5 seconds in a loop. The pH sensor code initializes software serial communication and prints readings from the sensor every second after parsing the response. The LDR code initializes analog read on the connected pin and prints the light level values every 100ms. The TDS section is only labeled without providing code.

Uploaded by

Devesh Murali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

For Temperature Sensor Dht11

The document provides code for reading sensor values from four different sensors: a DHT11 temperature and humidity sensor, a pH sensor, an LDR light sensor, and a TDS sensor. The DHT11 code initializes the sensor and prints the temperature and humidity readings every 5 seconds in a loop. The pH sensor code initializes software serial communication and prints readings from the sensor every second after parsing the response. The LDR code initializes analog read on the connected pin and prints the light level values every 100ms. The TDS section is only labeled without providing code.

Uploaded by

Devesh Murali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

FOR TEMPERATURE SENSOR DHT11:

#include "dht.h"
#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
//Start of Program

DHT.read11(dht_apin);

Serial.print("Current humidity = ");


Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop()

FOR PH SENSOR:
#include <SoftwareSerial.h>
#define rxpin 0
#define txpin 1
SoftwareSerial myserial(rxpin, txpin);
String inputstring = "";
String sensorstring = "";
boolean input_stringcomplete = false;
boolean sensor_stringcomplete = false;
void setup(){
Serial.begin(38400);
myserial.begin(38400);
inputstring.reserve(5);
sensorstring.reserve(30);
}
void serialEvent() {
char inchar = (char)Serial.read();
inputstring += inchar;
if(inchar == '\r') {input_stringcomplete = true;}
}
void loop(){
if (input_stringcomplete){
myserial.print(inputstring);
inputstring = "";
input_stringcomplete = false;
}
while (myserial.available()) {
char inchar = (char)myserial.read();
sensorstring += inchar;
if (inchar == '\r') {sensor_stringcomplete = true;}
}
if (sensor_stringcomplete){
Serial.print(sensorstring);
sensorstring = "";
sensor_stringcomplete = false;
delay(1000);
}
delay(1000);
}
For LDR
define LDRpin A0 // pin where we connected the LDR and the resistor

int LDRValue = 0; // result of reading the analog pin

void setup() {
Serial.begin(9600); // sets serial port for communication
}

void loop() {
LDRValue = analogRead(LDRpin); // read the value from the LDR
Serial.println(LDRValue); // print the value to the serial port
delay(100); // wait a little
}

FOR TDS:

You might also like