Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Report on Proximity Detector using Micro Python, Summaries of Computer Programming

This is a project report on the proximity alert built on hardware using a microcontroller and coded in Micro Python. It covers some basic functionalities of Micro Python and showcases its versatility in real life applications.

Typology: Summaries

2021/2022

Uploaded on 09/28/2023

samhita-patil
samhita-patil 🇮🇳

1 document

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROXIMITY DETECTOR
USING ULTRASONIC
SENSORS
Project By:
U22EC027
U22EC019
U22EC026
U22EC024
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download Report on Proximity Detector using Micro Python and more Summaries Computer Programming in PDF only on Docsity!

PROXIMITY DETECTOR

USING ULTRASONIC

SENSORS

Project By:

U22EC

U22EC

U22EC

U22EC

rd

June 2023

PYTHON PROGRAMMING

Submitted To: Dr. Suresh

Dahiya

OVERVIEW OF THE PROJECT

The Proximity Alert is designed and implemented with the idea of creating a system that detects potential blockages and hinderances in a path without coming in contact with them itself. It has been developed to avoid any chances of abrasion or damage by electrically detecting the distance between the subject body and the

PROXIMITY DETECTOR PAGE 5

HARDWARE DESCRIPTION

1. ESP32 MICROCONTROLLER

ESP32 is a low-power development board (Microcontroller) with an integrated Wi-Fi and Bluetooth. It achieves very low power consumption through power saving features including clock synchronization and multiple modes of operation. It can perform as a complete standalone system or as a slave device to a host MCU, reducing communication stack overhead on the main application processor.

2. HC-SR04 ULTRASONIC SENSORS

The HC-SR04 is an economical sensor that provides 2cm to 400cm of non-contact

measurement functionality with a ranging accuracy that can reach up to 3mm. An

HC-SR04 ultrasonic distance sensor actually consists of two ultrasonic transducers.

One acts as a transmitter that converts the electrical signal into 40 KHz ultrasonic

sound pulses. The other acts as a receiver and listens for the transmitted pulses.

When the receiver receives these pulses, it produces an output pulse whose width is

except OSError as ex: if ex.args[0] == 110: # 110 = ETIMEDOUT raise OSError('Out of range') raise ex def distance_mm(self): """ Get the distance in milimeters without floating point operations. """ pulse_time = self._send_pulse_and_wait()

To calculate the distance we get the pulse_time and divide it by 2

(the pulse walk the distance twice) and by 29.1 becasue

the sound speed on air (343.2 m/s), that It's equivalent to

0.34320 mm/us that is 1mm each 2.91us

pulse_time // 2 // 2.91 -> pulse_time // 5.82 -> pulse_time * 100 // 582

mm = pulse_time * 100 // 582 return mm def distance_cm(self): """ Get the distance in centimeters with floating point operations. It returns a float """ pulse_time = self._send_pulse_and_wait()

To calculate the distance we get the pulse_time and divide it by 2

(the pulse walk the distance twice) and by 29.1 becasue

the sound speed on air (343.2 m/s), that It's equivalent to

0.034320 cm/us that is 1cm each 29.1us

cms = (pulse_time / 2) / 29. return cms

  1. CODE FOR OLED SCREEN DISPLAY (ssd1306.py) import time import framebuf

    register definitions

    SET_CONTRAST = const(0x81) SET_ENTIRE_ON = const(0xa4) SET_NORM_INV = const(0xa6) SET_DISP = const(0xae) SET_MEM_ADDR = const(0x20) SET_COL_ADDR = const(0x21) SET_PAGE_ADDR = const(0x22) SET_DISP_START_LINE = const(0x40) SET_SEG_REMAP = const(0xa0) SET_MUX_RATIO = const(0xa8) SET_COM_OUT_DIR = const(0xc0) SET_DISP_OFFSET = const(0xd3) SET_COM_PIN_CFG = const(0xda) SET_DISP_CLK_DIV = const(0xd5) SET_PRECHARGE = const(0xd9) SET_VCOM_DESEL = const(0xdb) SET_CHARGE_PUMP = const(0x8d) class SSD1306: def init(self, width, height, external_vcc): self.width = width self.height = height self.external_vcc = external_vcc self.pages = self.height // 8 # Note the subclass must initialize self.framebuf to a framebuffer. # This is necessary because the underlying data buffer is different # between I2C and SPI implementations (I2C needs an extra byte). self.poweron() self.init_display() def init_display(self): for cmd in ( SET_DISP | 0x00, # off # address setting SET_MEM_ADDR, 0x00, # horizontal # resolution and layout SET_DISP_START_LINE | 0x00,

def pixel(self, x, y, col): self.framebuf.pixel(x, y, col) def scroll(self, dx, dy): self.framebuf.scroll(dx, dy) def text(self, string, x, y, col=1): self.framebuf.text(string, x, y, col) class SSD1306_I2C(SSD1306): def init(self, width, height, i2c, addr=0x3c, external_vcc=False): self.i2c = i2c self.addr = addr self.temp = bytearray(2)

Add an extra byte to the data buffer to hold an I2C data/command byte

to use hardware-compatible I2C transactions. A memoryview of the

buffer is used to mask this byte from the framebuffer operations

(without a major memory hit as memoryview doesn't copy to a separate

buffer).

self.buffer = bytearray(((height // 8) * width) + 1) self.buffer[0] = 0x40 # Set first byte of data buffer to Co=0, D/C= self.framebuf = framebuf.FrameBuffer1(memoryview(self.buffer)[1:], width, height) super().init(width, height, external_vcc) def write_cmd(self, cmd): self.temp[0] = 0x80 # Co=1, D/C#= self.temp[1] = cmd self.i2c.writeto(self.addr, self.temp) def write_framebuf(self):

Blast out the frame buffer using a single I2C transaction to support

hardware I2C interfaces.

self.i2c.writeto(self.addr, self.buffer) def poweron(self): pass class SSD1306_SPI(SSD1306): def init(self, width, height, spi, dc, res, cs, external_vcc=False): self.rate = 10 * 1024 * 1024 dc.init(dc.OUT, value=0) res.init(res.OUT, value=0) cs.init(cs.OUT, value=1) self.spi = spi self.dc = dc self.res = res

self.cs = cs self.buffer = bytearray((height // 8) * width) self.framebuf = framebuf.FrameBuffer1(self.buffer, width, height) super().init(width, height, external_vcc) def write_cmd(self, cmd): self.spi.init(baudrate=self.rate, polarity=0, phase=0) self.cs.high() self.dc.low() self.cs.low() self.spi.write(bytearray([cmd])) self.cs.high() def write_framebuf(self): self.spi.init(baudrate=self.rate, polarity=0, phase=0) self.cs.high() self.dc.high() self.cs.low() self.spi.write(self.buffer) self.cs.high() def poweron(self): self.res.high() time.sleep_ms(1) self.res.low() time.sleep_ms(10) self.res.high()

INDIVIDUAL COMPONENTS

1. JUMPER WIRES

HARDWARE ASSEMBLY IMAGES

3. ESP32 MICROCONTROLLER

4. HC-SR04 ULTRASONIC SENSOR

COMPLETE ASSEMBLED HARDWARE