George PopescuEmilian Simion
Created June 21, 2020

Parking senzor

Parking senzor with arduino nano and raspberry pi 0.

IntermediateFull instructions provided15 hours1
Parking senzor

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
Arduino Nano R3
Arduino Nano R3
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
LED progress bar
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×10
Male/Male Jumper Wires
×15
USB Connector, OTG
USB Connector, OTG
×1
Resistor 221 ohm
Resistor 221 ohm
×10

Software apps and online services

Arduino IDE
Arduino IDE
Putty
Raspbian
Raspberry Pi Raspbian

Story

Read more

Schematics

LED progress bar connected with raspberry pi

ultrasonic sensor

Code

sensor.py

Python
import serial
import RPi.GPIO as GPIO


ser = serial.Serial('/dev/ttyUSB0')
ser.flushInput
GPIO.setwarnings(False)

ledPins = [11, 12, 13, 15, 16, 18, 19, 21, 22, 23]
def setup():
        print("Program is starting")
        GPIO.setmode(GPIO.BOARD) #physical location
        for pin in ledPins:
                GPIO.setup(pin, GPIO.OUT) #mode output
                GPIO.output(pin, GPIO.HIGH) #off led

def destroy():
        for pin in ledPins:
                GPIO.output(pin, GPIO.HIGH)
                GPIO.cleanup()

if __name__ == '__main__':
        dict = {"5":"9", "10":"8", "15":"7", "20":"6", "25":"5", "30":"4", "35":"3", "40":"2", "50":"1", "60":"0" }
        dict = {int(k):int(i) for k, i in dict.items()}
        list = dict.keys()
        list.sort()
        numarLeduri = 0
        flag = 0

        setup()
        try:
                while True:
                        ser_bytes = ser.readline()
                        decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
                        dist = decoded_bytes    

                        ##
                        lungime = len(list)
                        for i in range(lungime - 1):
                                if dist >= list[i] and dist < list[i+1]:
                                        numarLeduri = dict[list[i]]
                                        continue
                                if dist >= 60:
                                        numarLeduri = 0

                        for pin in ledPins[:numarLeduri]:
                                GPIO.output(pin, GPIO.LOW)
                        for pin in ledPins[numarLeduri+1:]:
                                GPIO.output(pin, GPIO.HIGH)
                        ##
                        if dist<=10:
                                flag = flag + 1
                                if flag == 6:
                                        import smtplib
                                        server=smtplib.SMTP('smtp.gmail.com',587)

                                        server.starttls()

                                        server.login("gmail","pass")
                                        msg="Alerta senzor, distana este " + str(dist)                                               
    
                server.sendmail("emiraspberrypi0@gmail.com",
"nailimebale@yahoo.com",msg)
                                        server.quit()
                        ##
                        print("distanta este {}, iar noi ar trebui sa aprindem primele {} becuri".format(dist, numarLeduri))
        except KeyboardInterrupt:
                #destroy()
                print("exit")

MultipleUltrasonicSensors.ino

Arduino
#define echoPin 7
#define trigPin 8

long duration;
long distance;

void setup() {
  Serial.begin(9600);
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
}
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration / 58.2;
  Serial.println(distance);
  delay(500);
}

Credits

George Popescu

George Popescu

0 projects • 1 follower
Emilian Simion

Emilian Simion

0 projects • 1 follower

Comments