iugmoh
Posts: 5
Joined: Tue Oct 06, 2015 7:57 pm

using PC817 for switching

Tue Oct 06, 2015 8:19 pm

I want to ask if it's possible to switch a pulse signal from sensor HS1101 with 12V level and frequency 5-7kHz to the input of optocoupler PC817 to get the same frequency with level of 3.3V suitable for Raspberry Pi. So after that I can measure the frequency. The big challange here is the hardware circuit not the programm.
Any suggestions for the circuit ?

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: using PC817 for switching

Thu Oct 08, 2015 4:36 pm

What you want to do seems feasible.

I had a look at the data sheet for the sensor, and it includes a circuit, using a 555 timer, which seems to be what you're considering:
xyz.png
xyz.png (11.98 KiB) Viewed 2515 times
You could feed the output into the photocoupler, the 1k will result in ~10mA through its led. The photodiode would then pull down your chosen GPIO, to which you can connect a pull-up resistor in the region of 1k to 10k, up to 3v3.

Alternatively, you could dispense with the photocoupler if you feed the 555 timer output direct to your GPIO, with a 360Ω from there to ground (connecting also the timer's ground to the same point, of course) The 1k resistor and the 360Ω resistor form a potential devider to reduce the 12v to 3v3 for the GPIO.

iugmoh
Posts: 5
Joined: Tue Oct 06, 2015 7:57 pm

Re: using PC817 for switching

Sat Oct 10, 2015 9:06 am

Thanks a lot , It's now working I have a problem with the loading resistor between Vcc and collector which it's 100 ohm , now I increase it and the waveform is fine.

Any one can help me for a python code can measure the frequency accurately ?

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: using PC817 for switching

Sat Oct 10, 2015 12:09 pm

At 5-7kHz the most accurate is likely to be pigpio callbacks. The simplest would be a default callback on the GPIO and use tally() every second to see the count.

Return to “General discussion”