Wednesday, March 4, 2020

Smart Device with Arduino 


This is a simple project of using the ultrasonic sensor (HC-SR04) in Arduino that will turn on a led and buzzer with the variation of distance and print the distance from an object to the serial monitor. 

Components

  1. Arduino UNO 
  2. Ultrasonic Sensor (HC-SR04)
  3. Breadboard
  4. Jumper wires
  5. LED

Connect the Components

  • Connect VCC on the ultrasonic sensor to the 5V pin on the Arduino.
  • Connect the Trig pin on the ultrasonic sensor to pin 2 on the Arduino.
  • Connect the Echo pin on the ultrasonic sensor to pin 3 on the Arduino.
  • Connect the GND on the ultrasonic sensor to GND on the Arduino.
After that, make the connections for the buzzer and the Arduino. Connect the positive pin on the buzzer with pin 10 on the Arduino and the buzzer's negative pin with the GND pin on the Arduino
or connect a LED to the board


Write the code and upload it to the Arduino board

-------------------------------------------------------------------------------------------------------------------------
//code

const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;

long duration;
int distance;
int safetyDistance;

void setup(){
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  }

 void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;
  safetyDistance = distance;
//you can change the distance in here
  if(safetyDistance <=20){
    digitalWrite(buzzer, HIGH);
    digitalWrite(ledPin, HIGH);
    
    }
  else{
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW);
    Serial.print("Distance : ");
    Serial.print(distance);
    }
  
  }

--------------------------------------------------------------------------------------------------------------------------


for full video - https://youtu.be/sDo-uHNM1Xg


Thank you

Tuesday, March 3, 2020

Knight Rider LED pattern with Arduino Uno

Knight Rider

  The Knight Rider is one of the perfect Arduino projects for beginners. What is Knight Rider? It’s a set of LEDs that blinks one after another.


Components

  1. 5mm LEDs
  2. Arduino UNO
  3. Breadboard
  4. Jumper wires

Apps 

  1. Arduino IDE

Building the circuit 

  1. Place the LEDs next to each other in the breadboard so that the anode(+) is at the left and the cathode(-) is on the right.
  2. Join the anodes of the LEDs to pins 2 to 10 of the Arduino from left to right using single-core wire. Join the top rail to one of the GND pins of the Arduino.
  3. When finished building the circuit, connect the Arduino to the PC via the USB cable.

  4. The Knight Rider program code is shown below. Copy it and paste it into the Arduino IDE.
------------------------------------------------------------------------------------------------------------------------------
//copy this and paste it into the IDE


void setup(){
  for (int pin=1; pin<11; pin++){
    pinMode(pin, OUTPUT);
    }
  }

  void loop(){
//you can change the value of int t to change the blinking speed
    int t = 20;

    for(int i=1; i<11; i++){
      digitalWrite(i, HIGH);
      delay(t);
      digitalWrite(i+1, HIGH);
      delay(t);
      digitalWrite(i+2, HIGH);
      delay(t);
      digitalWrite(i, LOW);
      delay(t);
      digitalWrite(i+1, LOW);
      delay(t);
      }

      for(int i =10; i>1; i--){
        digitalWrite(i, HIGH);
      delay(t);
      digitalWrite(i-1, HIGH);
      delay(t);
      digitalWrite(i-2, HIGH);
      delay(t);
      digitalWrite(i, LOW);
      delay(t);
      digitalWrite(i-1, LOW);
      delay(t);
        }
    
    }

------------------------------------------------------------------------------------------------------------------------------
Upload the program to the Arduino and if the circuit was built correctly, your knight rider circuit will start operating.

check here for full video - https://youtu.be/TM5-WAe5WHo
Thank you.........