Wednesday, 16 January 2019

Simple Radar System Using Arduino and Ultrasonic Sensor

Simple Radar System Using Arduino and Ultrasonic Sensor

https://youtu.be/f-yGhTxBH-g



Program:

#define trigPin 10
#define echoPin 13
#define ledred 7
#define ledgreen 6


float duration, distance;

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

void loop() {
 

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
   duration = pulseIn(echoPin, HIGH);

      distance = (duration / 2) * 0.0343;
 
  Serial.print("Distance = ");
  if (distance >= 400 || distance <= 2) {
     Serial.println("Out of range");
     Serial.print(distance);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    delay(500);
    if (distance <= 15)
    {
      digitalWrite(ledgreen, LOW);
      digitalWrite(ledred, HIGH);
      delay(2000);                     
      digitalWrite(ledred, LOW);   
      delay(2000);                     
    }
    else
    {
      digitalWrite(ledred, LOW);
      digitalWrite(ledgreen, HIGH); 
      delay(2000);                     
      digitalWrite(ledgreen, LOW);   
      delay(2000);
    }
  }
  delay(500);
}

Saturday, 29 December 2018

Project : Control LED Using Raspberry Pi 3 B+ |

Project : Control LED Using Raspberry Pi 3 B+ | Python Program

YouTube URLs:

Project : Control LED Using Raspberry Pi 3 B+




program: Control LED Using Raspberry Pi 3 B+

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

RedLEDPin = 11 

def setup():
GPIO.setmode(GPIO.BOARD)     
GPIO.setup(RedLEDPin, GPIO.OUT) 
GPIO.output(RedLEDPin, GPIO.LOW)

def lightson():
while True:
GPIO.output(RedLEDPin, GPIO.HIGH)
time.sleep(2)
GPIO.output(RedLEDPin, GPIO.LOW)
time.sleep(2)
def stop():
GPIO.output(RedLEDPin, GPIO.LOW)   
GPIO.cleanup()                   

if (__name__ == '__main__'):   
setup()
try:
#
lightson()
except KeyboardInterrupt:
stop()



Project : LEDs Blink using Raspberry Pi | Python Programming

Project : LED Blink using Raspberry Pi | Python Programming 

YouTube URLs

Project : LED Blink using Raspberry Pi




Program: Project : LED Blink using Raspberry Pi | Python Programming

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

RedledPin = 11 
BlueledPin = 12
GreenledPin = 13
YellowledPin = 16


def setup():
GPIO.setmode(GPIO.BOARD)     
GPIO.setup(RedledPin, GPIO.OUT)
GPIO.output(RedledPin, GPIO.LOW)
GPIO.setup(BlueledPin, GPIO.OUT)
GPIO.output(BlueledPin, GPIO.LOW)
GPIO.setup(GreenledPin, GPIO.OUT)
GPIO.output(GreenledPin, GPIO.LOW)
GPIO.setup(YellowledPin, GPIO.OUT)
GPIO.output(YellowledPin, GPIO.LOW)

def lightsOn():
GPIO.output(RedledPin, GPIO.HIGH)
GPIO.output(BlueledPin, GPIO.HIGH)
GPIO.output(GreenledPin, GPIO.HIGH)
GPIO.output(YellowledPin, GPIO.HIGH)

def stop():
GPIO.output(RedledPin, GPIO.LOW) 
GPIO.output(BlueledPin, GPIO.LOW)
GPIO.output(GreenledPin, GPIO.LOW)
GPIO.output(YellowledPin, GPIO.LOW)
GPIO.cleanup()                   

if (__name__ == '__main__'):     # Main Program Start From Here
setup()
try:
lightsOn()
except KeyboardInterrupt:  # When 'Ctrl+C' is pressed or stopped program
stop()



Odd Or Even Program LED output using Raspberry Pi | Python Program

Odd Or Even Program LED output using Raspberry Pi | Python Programming


YouTube URLs:

Odd Or Even Program LED Output using Raspberry Pi



Program: OddOrEven.py

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time
RedLEDPin = 11 
GreenLEDPin = 22

def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(RedLEDPin, GPIO.OUT)
GPIO.output(RedLEDPin, GPIO.LOW)
GPIO.setup(GreenLEDPin, GPIO.OUT)
GPIO.output(GreenLEDPin, GPIO.LOW)

def FindOddEven():
        while True:
            player = int(input("Player Choise..."))
            remainder = player % 2
            if(remainder == 0):
                print("Even LED on")
                GPIO.output(RedLEDPin, GPIO.HIGH)
                time.sleep(3)
                GPIO.output(RedLEDPin, GPIO.LOW)
            else:
                print("Odd LED on")
                GPIO.output(GreenLEDPin, GPIO.HIGH)
                time.sleep(2)
                GPIO.output(GreenLEDPin, GPIO.LOW)

def destroy():
GPIO.output(RedLEDPin, GPIO.LOW)
GPIO.output(GreenLEDPin, GPIO.LOW)
GPIO.cleanup()

if (__name__ == '__main__'):     #Main Program Starting From Here
setup()
try:
FindOddEven()
except KeyboardInterrupt:
destroy()