(QUICK START GUIDE) Set Up An Ultrasonic Range Finder On An Arduino
(QUICK START GUIDE) Set Up An Ultrasonic Range Finder On An Arduino
(QUICK START GUIDE) Set Up An Ultrasonic Range Finder On An Arduino
T = Temperature in °C
Trig = The Arduino sends a signal to this pin to start the distance measurement.
Echo = The ultrasonic range finder returns the time data to the Arduino at this pin.
Circuit Basics
Raspberry Pi, Arduino, and DIY Electronics Tutorials
Now upload this code to the Arduino, then open the serial monitor to see the distance
measurements:
#define trigPin 10
#define echoPin 13
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
float duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) * 0.0344;
else {
Serial.print("Distance = ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
delay(500);
}
Connect the ultrasonic range finder and thermistor to your Arduino like this:
If you want to use a 100K Ohm thermistor instead, change the resistor to 100K Ohms,
and change line 7 in the code below to:
Temp = log(100000.0*((1024.0/RawADC-1)));
Circuit Basics
Raspberry Pi, Arduino, and DIY Electronics Tutorials
Now upload this program to the Arduino and open up the serial monitor:
#include <math.h>
#define trigPin 10
#define echoPin 13
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
int val;
double temp;
val=analogRead(0);
temp=Thermistor(val);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
The DHT11 temperature and humidity sensor provides both temperature and
humidity data. To use the DHT11 on the Arduino, you’ll need to install the DHTLib
library on your computer. First, download the .zip file from here, then open your
Arduino IDE and go to Sketch > Include Library > Add ZIP Library, then select the
DHTLib.zip file.
Now, connect the ultrasonic range finder and DHT11 to your Arduino:
Circuit Basics
Raspberry Pi, Arduino, and DIY Electronics Tutorials
Next, upload this code to your Arduino and open the serial monitor:
#include <dht.h>
#define trigPin 10
#define echoPin 13
#define DHT11_PIN 7
dht DHT;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);