Arduino Tutorial 3 : Proximity Sensor & Piano

preview_player
Показать описание

In the last video I asked for requests so in this video I cover those requests. I'll make both a Proximity Sensor and a Piano using an Arduino.

We'll learn about Ultrasonic Sensors, How Sound is Turned into a Current, Passive Buzzers and much more.

Thank you to my Patreon supports like the following :
Рекомендации по теме
Комментарии
Автор

Your channel is like university where we are learning everything ... In whole my life, I will always be thankful for you.

jdoesec
Автор

Mr. Derek, you are the best teacher I have ever seen.

dinozoe
Автор

Me and my friends had made with a ultrasonic sensor which was used as a replacement to a walking stick for blind people.
We called it the 'Project Weihanmayer'.
Btw
Awesome video!

viditkhandelwal
Автор

Hi Derek, thanks for sharing your knowledge with us, I hope you can explain state machines in a future tutorial!
Greetings from Greece!

VasilisKarastergios
Автор

Just wanted to contribute, through your thread. Just bought a ESP32 Wemos lolin32, and thought I would convert your code, for the UltraSonic sensor, to code for the ESP32. And yes the code, for using LED's, is different from an Arduinos, even though its the same for the UltraSonic Sensor, on both boards. Also, be aware I used different pins, out of the convenience of their placement.


// Create easy ways to identify what pins are being used for
int triggerPin = 27; // instead of 11
int echoPin = 26; // instead of 10

long duration, distance;


// ESP32 the number of the LED pin
uint8_t ledPin1 = 13; // 13 corresponds to GPIO13
uint8_t ledPin2 = 12;
uint8_t ledPin3 = 14;

// ESP32 setting PWM properties, assigned to channels 1, 2, 3
const int freq = 5000;
const int ledChannel_1 = 1;
const int ledChannel_2 = 2;
const int ledChannel_3 = 3;

const int resolution = 8; // 0-255 (resolution 16 bit 1-1024)

void setup() {
Serial.begin(9600);

// Designate which pins are used for output and input reasons
pinMode(echoPin, INPUT);
pinMode(triggerPin, OUTPUT);

// ESP32 configure LED PWM functionalitites
//ledcSetup(ledChannel, freq, resolution);
ledcSetup(ledChannel_1, freq, resolution);
ledcSetup(ledChannel_2, freq, resolution);
ledcSetup(ledChannel_3, freq, resolution);

// ESP32 Prepare LED pins to provide an output voltage
ledcAttachPin(ledPin1, ledChannel_1);
ledcAttachPin(ledPin2, ledChannel_2);
ledcAttachPin(ledPin3, ledChannel_3);
}

void loop() {

// As we loop the trigger pin that sends the 8 cycle frequency is turned on and off
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);

// Get the travel time from playing the sound to receiving
// it back
// pulseIn() turns a pin on and waits times the period from LOW to HIGH
// and returns the period in microseconds
duration = pulseIn(echoPin, HIGH);

// Convert that time to centimeters
distance =
Serial.print("Distance : ");
Serial.println(distance);

// The PWM amounts vary, because I used 3 different sized LED's
// and wanted the same intensity in brightness
// If less then 20 centimeters turn on 1 LED
if(distance < 20){
ledcWrite(ledChannel_1, 95.5);
} else {

// If not true turn off LED
ledcWrite(ledChannel_1, 0);
}

// If less then 15 centimeters turn on next LED
if(distance < 15){
ledcWrite(ledChannel_2, 85.5);
} else {
ledcWrite(ledChannel_2, 0);
}

// If less then 10 centimeters turn on next LED
if(distance < 10){
ledcWrite(ledChannel_3, 85.5);
} else {
ledcWrite(ledChannel_3, 0);
}
}

// The speed of sound is .0343 cm/μs
// We receive both the distance from the sensor and
// back again so we must divide by 2
long duration){
long d = (duration / 2) * .0343;
return d;
}

rodmanunderhilliii
Автор

Just wanted to say thank you for all your work.
I just started going to an C# course and your videos definitely help!

daristotell
Автор

Excellent performance of Mary had a little lamb! :)

Piggsvin
Автор

Thanks Derek for the great tutorials. You’re awesome

masoud
Автор

this tutorial is very helpful
you're awesome sir
thank you so so much for making this even easier to understand

hanaamelindaazizah
Автор

Perfect! I'm so grateful, keep going, please make more videos about Arduino and C/C++(and it's well-known frameworks).
By the way, isn't the speed of sound (335 meter/sec) 0.0335sm per micro sec. (sorry if I have mistaken :D)

sardorbayramov
Автор

Hi, I had a problem with the code, both the one I made myself following the video and the one downloaded from your link. The LEDs are constantly on when both sketches are uploaded regardless of the sensed distance. The output to the serial monitor shows that the device is able to detect the distance accurately. The LEDs appear to flicker slightly at the distances in the if statement but never turn off. Do you have any idea what might be happening?

nouseforaname
Автор

I've learned so much from your videos alone, they are great. I'm still stuck with a problem in my project though. I'm using an MPR121 Capactive Touch sensor attached to an Arduino Leonardo. I have 12 electrode attached to this module and they are working great, but I'm lost when I try to use this sensor touch/release information to create MIDI note values.. I'm trying to implement sections of your code where you define frequencies but nothing seem to work. Would you know how to solve this?

Kloppsserialbottlers
Автор

Hi, Can you make a launchpad using breadboard and Arduino Uno?and I wanna use spoons as a keys for this launchpad...do I have to use anything else? What are the components required?please help

gibinjoseph
Автор

Hey Derek :) Thank you very much for the tutorials, arduino looks awesome.

exodus
Автор

I was just thinking how you could possibly change the wave style of your buzzer’s output. I’m sure by default, it’s a square wave but I’m sure you could convert it to a sine or sawtooth using some type of amplifier circuit :)

KingDuken
Автор

Make a roomba. It has to remember where is came from and "redock" itself too. So steppers, servos, dc motors, proximity and colission sensors and a database! You can take the pueces of this and go on to make anything from there!

davidjhyatt
Автор

Hey Derek, couple of simple questions (simple for you anyway). Would it be more efficient to use some kind of Case statement in place of all those While statements? I know it is getting away from the basic nature of the example, but just curious. Also what happens if you try to play two or more notes at the same time? Is that possible?

DodgyBrothersEngineering
Автор

Excellent explanation but according to my documentation, the second parameter of the analogWrite function is an integer. How did you get to the value of 91.5 to use with a LED?

captainpugwash
Автор

It would be great if you cover about how to connect arduino with c++ (qt creator)

ronistiawan
Автор

are you doing a phoenix tutorial soon?

jordi