Tuesday, November 10, 2020

How to measure distance using Ultrasonic sensor|How to Find Distance using soundwaves? (Full tutorial)

ManiTesla.tech

In this post, we are going to use the Ultrasonic Sensor to build a distance sensor. The HC-SR04 ultrasonic sensor can be programmed to send out a ping using an ultrasonic transmitter, and then measure the time it takes to hear the echo of the ping come back to the receiver, after bouncing off a object body. Since we know the speed of sound we can calculate the distance to the sensor.

     The circuit uses the following Schematic:Circuit diagram

        Schematic for Connecting the HC-SR04 to an Arduino
 

In order to produce ultrasonic sound, we need to set the Trigger Pin on HIGH for 10 µs. That will send out a sonic burst which will travel at the speed of sound and it will be received in the Echo Pin. The Echo Pin will send the output the time in microseconds the sound wave traveled.


timing diagram
        An ultrasonic HC-SR04 timing diagram



ultrasnoic distance calculate


For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave have to travel for about 294 microseconds. But the output will get from the Echo pin will be double that number because the sound wave needs to travel and bounce backward. So in order to get the distance of the object in cm we need to multiply the received travel time value from the echo pin by speed of sound that is 0.034 and divide it by 2.
 

 Click to  direct download full arduino file code 

download
  Arduino Code: (Copy the code from below  or directly downlod arduino file from above )

/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* by Manikant savadatti
*
*
*/
// defines pins numbers
const int trig = 9;
const int echo = 10;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trig, OUTPUT); // trigPin as an Output
pinMode(echo, INPUT); // echoPin as an Input
Serial.begin(9600); // Starts the serial monitor
}
void loop() {
// Clears the trigPin
digitalWrite(trig, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
// Reads the echoPin,returns the sound travel time in microseconds
duration = pulseIn(echo, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}









Monday, November 9, 2020

#3 How to use Bread board and How to calculate Resistor value for led (Full tutorial)

ManiTesla.tech

The Arduino can be used to connect and interact with different types of sensors and actuators.  Prototyping can be easily done by using a breadboard.The video below explains in detail how to use a breadboard and how to calculate series resistance for a led.



As explained in the video, the easiest way to start using the breadboard is to understand how the little holes on the breadboard are connected. The below diagram will help you understand which holes are connected in which way.

breadboard


Observe this image, and make sure you understand how the breadboard works. You can see that to connect two leads, they should be inserted into the same column on the breadboard. If you carefully follow the video, you should be able to get your first circuit connected and working.

Resistance Calculation:


led ohm law  circuit




led ohms law formula

where:

  • VSource is the source voltage, measured in volts (V),
  • VLED (Vf) is the voltage drop across the LED, measured in volts (V),
  • ILED is the current through the LED*, measured in Amperes (Amps/A), and
  • R is the resistance, measured in Ohms (Ω).

     Vled valued for different leds:                                                                   

led voltage chart



Sunday, November 8, 2020

#1 Arduino detailed explanation and DigitalWrite Explained(Full tutorial)

ManiTesla.tech

 Hello, I'm Manikant Savadatti and today I will introduce you all to Arduino. This post is for absolute beginners. So in this post, you guys will learn the following things and will get answers to the following points.

1)What is Arduino and Arduino Ide?

2)How to use it?

3)Circuit connection?

4)How to blink a led using Arduino?


 1:What is Arduino and Arduino Ide

Whenever you ask what is Arduino the first answer what you get is it is a microcontroller.
Now, what is a microcontroller? It is like a mini-brain or a mini-computer. So we can use Arduino to control sensors, led's, motors etcc.. the same way the brain controls our hand's eyes legs etc...

For example: let us compare humans to the Arduino .human brain is like the Arduino, LED sensors motors, etc are like the eyes hands sense organs of a human body. If someone tells you to sit down your brain understands that language and sends a signal to sit down. In the same way, we tell the microcontroller to turn on the led in a particular language (c, c ++, python). Arduino understands this language like c,c++, python etcc.. and makes a led to turn on.

2)How to use it?

ARduino pinout


You guys can see the pinout diagram of the Arduino .In the above image, you guys can see black holes we use those wholes to connect sensors led's motors etc.All those holes are called as pins and those pins act as switches.All those switches are controllers using the Microcontroller. The black chip which you guys can see is the microcontroller and its name is Atmega328p.This microcontroller is attached to a breakout board which makes easy access of the pins . There are total 13 digital pins ,6 analog pins in Arduino.


3)Circuit Connection:


Circuit diagram


4)How to write your first program?

Arduino ide
This is the Arduino ide.You can download it from this link-Arduino ide

Code for led blink

This declares built-in led of Arduino as output

pinMode(LED_BUILTIN, OUTPUT);

In the void  loop, you can turn the LED on using this code:

digitalWrite(LED_BUILTIN, HIGH);

This supplies 5 volts to the LED anode. 

digitalWrite(LED_BUILTIN, LOW);

This makes the LED_BUILTIN pin back to 0 volts and turns the LED off. We need time  delay for a person to see the change in the state of led , so the delay(1000) commands tell the board to wait or  do nothing for 1000 milliseconds, or one second.

#2 Arduino AnalogWrite Explained

ManiTesla.tech

led circuit diagram


 Hi everyone, I'm your Manitesla.In the last post, we learned how to turn Arduino pins on and off with the Arduino digitalWrite command. This command is best if you only want 0 or 5 volts. In this post, I'll show how you can get the in-between values (0-5)by using the analogWrite command. In the upcoming post, I will in detail how analogWrite works, but this present post  gets you started, and shows you how to control the brightness of an LED. U can watch the video below to learn how to control led brightness.