ESP8266 ultrasonic distance measuring Displayed on MAX7219 Dot Matrix

ESP8266 ultrasonic distance measuring Displayed on MAX7219 Dot Matrix

In this Arduino Tutorial we will learn how the HC-SR04 Ultrasonic Sensor works and how to use it with the Arduino Board. You can watch the following video or read the written tutorial below.
The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the esp8266

Schema



download

ESP8266 ESP-12F WIFI Development Board


Ultrasonic Module HC-SR04 Distance Measuring Ranging Transducer Sensor

Ultrasonic Module HC-SR04 Distance Measuring
https://www.banggood.com/custlink/KmDD799F7I
ESP8266 ESP-12F WIFI Development Board
https://www.banggood.com/custlink/3G33WYMqOm
MAX7219 Dot Matrix Module 4-in-1 LED Display Module
https://www.banggood.com/custlink/vKvKuS8VwE


Code: Download

Library

// REQUIRES the following Arduino libraries:
// - HCSR04 library: https://github.com/Martinsos/arduino-lib-hc-sr04
// - MD_Parola Library: https://github.com/MajicDesigns/MD_Parola
// - MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
// Find All "Great Projects" Videos : https://www.youtube.com/channel/UCCC8DuqicBtP3A_aC53HYDQ/videos

Code

// - REQUIRES the following Arduino libraries:
// - MD_Parola Library: https://github.com/MajicDesigns/MD_Parola
// - MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
// - HCSR04 library: https://github.com/Martinsos/arduino-lib-hc-sr04
// - More videos : https://www.youtube.com/channel/UCCC8DuqicBtP3A_aC53HYDQ/videos

// includes

#include <ESP8266WiFi.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <HCSR04.h>
UltraSonicDistanceSensor distanceSensor(12, 4); // Initialize sensor that uses digital pins 13 and 12.
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 3

#define CLK_PIN 14 // or SCK
#define DATA_PIN 13 // or MOSI
#define CS_PIN 15 // or SS

// SPI hardware interface
//MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

char ssid[] = "Verus"; // your network SSID (name)
char pass[] = "Bou3bou3@.com"; // your network password
bool newDistance = false;
int distance;
char szTime[9];

void readDistance() {
distance = distanceSensor.measureDistanceCm();
newDistance = true;
delay(300);
}
void setup() {
P.begin(1);
P.setZone(0, 0, 2);
P.displayZoneText(0, szTime, PA_CENTER, 25, 0, PA_PRINT, PA_NO_EFFECT);
}

void loop() {
readDistance();
P.displayAnimate();
P.getZoneStatus(0);
if (newDistance)
{
sprintf(szTime, "%d", distance);
P.displayReset(0);
newDistance = false;
}
}

1 comment: