After Width: | Height: | Size: 3.6 MiB |
After Width: | Height: | Size: 4.5 MiB |
After Width: | Height: | Size: 4.6 MiB |
After Width: | Height: | Size: 4.6 MiB |
After Width: | Height: | Size: 4.2 MiB |
After Width: | Height: | Size: 4.2 MiB |
After Width: | Height: | Size: 3.9 MiB |
@ -0,0 +1,37 @@ |
|||||
|
/*
|
||||
|
* Simple code to test the temperature sensor function and electrical connections. |
||||
|
*/ |
||||
|
#include <DHT.h> |
||||
|
|
||||
|
// Type of DHT sensor used is 11
|
||||
|
#define DHTTYPE DHT11 |
||||
|
#define DHTPIN 2 |
||||
|
|
||||
|
// Initializes DHT sensor
|
||||
|
DHT dht(DHTPIN, DHTTYPE); |
||||
|
|
||||
|
/* ===== SETUP AND LOOP ===== */ |
||||
|
void setup() { |
||||
|
// Starts the serial com with PC
|
||||
|
Serial.begin(9600); |
||||
|
Serial.println("Running setup function"); |
||||
|
|
||||
|
dht.begin(); |
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
// Reads temperature as Celsius
|
||||
|
float temperature = dht.readTemperature(); |
||||
|
|
||||
|
// Checks if the read failed and handles the failure
|
||||
|
if (isnan(temperature)) { |
||||
|
Serial.print(F("Failed to read from DHT sensor!")); |
||||
|
} |
||||
|
|
||||
|
Serial.print(F("Temperature: ")); |
||||
|
Serial.print(temperature); |
||||
|
Serial.println(F("°C ")); |
||||
|
|
||||
|
// Waits a few seconds between measurements.
|
||||
|
delay(1000); |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
/*
|
||||
|
* Simple code to test the distance sensor function and electrical connections. |
||||
|
*/ |
||||
|
int DIST_ECHO_PIN = 10; |
||||
|
int DIST_TRIG_PIN = 11; |
||||
|
long duration, cm; |
||||
|
|
||||
|
void setup() { |
||||
|
// Starts the serial com with PC
|
||||
|
Serial.begin(9600); |
||||
|
Serial.println("Running setup function"); |
||||
|
|
||||
|
//Defines inputs and outputs
|
||||
|
pinMode(DIST_TRIG_PIN, OUTPUT); |
||||
|
pinMode(DIST_ECHO_PIN, INPUT); |
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
|
||||
|
// Gives a short LOW pulse beforehand to ensure a clean HIGH pulse:
|
||||
|
digitalWrite(DIST_TRIG_PIN, LOW); |
||||
|
delayMicroseconds(5); |
||||
|
digitalWrite(DIST_TRIG_PIN, HIGH); |
||||
|
delayMicroseconds(10); |
||||
|
digitalWrite(DIST_TRIG_PIN, LOW); |
||||
|
|
||||
|
// Reads the signal from the sensor: a HIGH pulse whose
|
||||
|
// duration is the time (in microseconds) from the sending
|
||||
|
// of the ping to the reception of its echo off of an object.
|
||||
|
//pinMode(DIST_ECHO_PIN, INPUT);
|
||||
|
duration = pulseIn(DIST_ECHO_PIN, HIGH); |
||||
|
|
||||
|
// Converts the time into a distance
|
||||
|
cm = (duration/2) / 29.1; |
||||
|
|
||||
|
Serial.print(cm); |
||||
|
Serial.print("cm"); |
||||
|
Serial.println(); |
||||
|
|
||||
|
delay(1000); |
||||
|
} |