Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20623 Discussions

implementing distance sensor in my code

Altera_Forum
Honored Contributor II
1,644 Views

Hello all, 

I really need your help, i'm kind of in the dark here 

 

i want to implement 'Sharp's' Distance sensor {DataSheet attached} in my project 

and i honestly don't know where to begin coding. 

 

If to look at the great picture - i want to be able to know when the object is 20 CM from the sensor and then perform an action( turning LED or anything else). 

 

can anyone please guide me? or giving me something to read? any video i can watch? 

it will be highly appriciated! 

 

i'm using DE2-115, BTW.
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
462 Views

I hope you're intending to use the digital version of the sensor - which does all the work for you. Connect 'Vo' to a spare I/O on your DE2 board. In the FPGA you can drive an LED directly from this signal. 

 

Cheers, 

Alex
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

Hi Alex, 

can you ellaborate?  

what do you mean the digital version?
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

Hi Alex, 

can you ellaborate?  

what do you mean the digital version?  

like when the output is digital? 

like this - https://media.digikey.com/pdf/data%20sheets/sharp%20pdfs/gp2y0d21yk.pdf
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

Exactly. Connecting the analogue version to the DE2-115 won't be easy as the board doesn't have any ADC's on it. Assuming you have the choice, use the digital version. 

 

Cheers, 

Alex
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

Hi Alex, 

just ordered the digital version of the sensor, 

what's next ?  

:) 

how can i get indication of how distant is the object?
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

 

--- Quote Start ---  

Hi Alex, 

just ordered the digital version of the sensor, 

what's next ?  

:) 

how can i get indication of how distant is the object? 

--- Quote End ---  

 

 

The digital version has only a single on/off output which switches at 24% of the 80 cm, see page 4 of the .pdf: https://media.digikey.com/pdf/data%20sheets/sharp%20pdfs/gp2y0d21yk.pdf
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

Thank you alex! 

if i understood you correctly, it will trigger a led light as it 24 cm far from an object. 

but would i be able to drive an output on my FPGA board when i realize an object is exactly at, let's say 20 cm? 

i dont really understand how to monitor the incoming signals and process them.
0 Kudos
Altera_Forum
Honored Contributor II
462 Views

With the digital version you're limited by the sensor - it will only give you an edge when it's a specified distance away (see the datasheet). 

 

To measure the distance of the object you need the analogue version and to use the Vo signal from that you need an ADC, which the DE2 board doesn't have. You would have to add an external ADC to that board or use another development board with an ADC. 

 

Cheers, 

Alex
0 Kudos
Reply