In this lesson we show you how to quickly and easily plot live data from the arduino using the Serial Plotter in the Arduino IDE. The nice thing about this feature is that it is very easy to use. The downside is you have absolutely no formatting options. I hope they will improve this feature in the future, but it is very useful, even with its limitations.
Category Archives: Tutorial
Arduino Tutorial 55: Measuring Distance With HC-SR04 Ultrasonic Sensor
This lesson builds on the work done in Lessons 53 and 55. In this lesson we use the Ultrasonic Sensor to build a distance sensor. The HC-SR04 ultrasonic sensor can be programmed to send out a ping, and then measure the time it takes to hear the echo of the ping come back, after bouncing off a target. Knowing the speed of sound allows us to calculate distance to the sensor.
The circuit uses the following Schematic:
This is the code we develop in the video
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | int trigPin=12; int echoPin=11; int pingTravelTime; float pingTravelDistance; float distanceToTarget; int dt=50; void setup() { // put your setup code here, to run once: pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin,LOW); delayMicroseconds(10); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); pingTravelTime=pulseIn(echoPin,HIGH); delay(25); pingTravelDistance=(pingTravelTime*765.*5280.*12)/(3600.*1000000); distanceToTarget=pingTravelDistance/2; Serial.print("Distance to Target is: "); Serial.print(distanceToTarget); Serial.println(" in."); delay(dt); } |
The sensor is part of our Elegoo Kit , so if you get this kit, you will be using the same hardware we are using. This project builds on the work we did in Lesson 53.
For this build we will be using an Arduino Nano, which allows the project to be built on a single breadboard. You can use the Arduino Uno if you do not have a Nano, and things will work out the same. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.
Arduino Tutorial 54: Measuring Speed of Sound With HC-SR04 Sensor
In this lesson we explore use of the HC-SR04 sensor to measure the speed of sound. The hookup and programming are pretty simple. The Elegoo Kit includes this sensor, so if you have the kit, you will be using the same hardware we are using. This project builds on the work we did in Lesson 53.
For this build we will be using an Arduino Nano, which allows the project to be built on a single breadboard. This allows cleaner build, and one less likely to have problems from intermittent connections. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.
You can connect the sensor up according to this schematic:
The connection pins are the same when connecting to a Nano.
The video below explains how to measure speed of sound from data coming from this sensor.
Code used in Today’s Lesson:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | int trigPin=12; int echoPin=11; int pingTravelTime; void setup() { // put your setup code here, to run once: pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin,LOW); delayMicroseconds(10); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); pingTravelTime=pulseIn(echoPin,HIGH); delay(25); Serial.println(pingTravelTime); } |
Arduino Tutorial 53: Understanding and Connecting the HC-SR04 Sensor
In this lesson we explore using the HC-SR04 from our Arduino Kit to measure distance. The sensor sends out a ping, and then waits to hear the echo. It measures the time between when the ping is sent and when the echo is heard. Knowing pingTravelTime, allows you to calculate distance from the sensor. In this lesson we will show you how to connect the sensor, and program it to read pingTravelTime. In future lessons we will show you how to change this into distance.
Notice we used an Arduino Nano, which allows the entire project to be build on a single breadboard. This allows a neater, smaller build, and one less likely to have problems from poor or loose connections. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.
Connecting up the HC-SR04 sensor is simple, as illustrated in this diagram:
This video will take you through our build and initial work step-by-step.
The simple code below is what we used in the video to begin making measurements with the sensor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | int trigPin=12; int echoPin=11; int pingTravelTime; void setup() { // put your setup code here, to run once: pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin,LOW); delayMicroseconds(10); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); pingTravelTime=pulseIn(echoPin,HIGH); delay(25); Serial.println(pingTravelTime); } |
Arduino Tutorial 52: Portable Temperature and Humidity Sensor with DHT11
In this lesson we build a completely portable Temperature and Humidity Sensor using the DHT11 sensor. The project is powered by a 9 Volt battery, through the power supply board supplied in the Elegoo Kit. This project builds on the work we did in Lessons 50 and 51.
Also, notice we used an Arduino Nano, which allows the entire project to be build on a single breadboard. This allows a neater, smaller build, and one less likely to have problems from poor or loose connections. The build neatness is also facilitated by using small straight jumper wires, which you can get HERE.
In the configuration in this project, the regulated power supply is providing power to the Arduino through the 5 Volt pin. In such cases, you should not Also plug the USB cable into the arduino. When powering the Arduino with a regulated power supply, do not connect the USB. If you need to program the arduino, disconnect the external power supply first.
The video below gives a detailed step-by-step description of the project.
The code we developed is presented below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include "DHT.h" #define Type DHT11 #include <LiquidCrystal.h> int rs=7; int en=8; int d4=9; int d5=10; int d6=11; int d7=12; LiquidCrystal lcd(rs,en,d4,d5,d6,d7); int sensePin=2; DHT HT(sensePin,Type); float humidity; float tempC; float tempF; int setTime=500; int dt=1000; void setup() { // put your setup code here, to run once: Serial.begin(9600); HT.begin(); delay(setTime); lcd.begin(16,2); } void loop() { humidity=HT.readHumidity(); tempC=HT.readTemperature(); tempF=HT.readTemperature(true); lcd.setCursor(0,0); lcd.print("Temp F= "); lcd.print(tempF); lcd.setCursor(0,1); lcd.print("Humidity= "); lcd.print(humidity); lcd.print(" %"); delay(500); lcd.clear(); Serial.print("Humidity: "); Serial.print(humidity); Serial.print("% Temperature "); Serial.print(tempC); Serial.print(" C "); Serial.print(tempF); Serial.println(" F "); } |