Alcohol sensor for raspberry pi

Hi,

I have alcohol sensor of Grove pi. I didn’t find python sample program in grove pi libraries in Raspberry pi. will you provide sample code for it?

Thanking you,
Amol Desai

if you look here the code is pretty basic and should be easy to convert.

I don’t have the sensor, but it would be something like

from time import sleep
import grovepi

analogInDatPin = 0
heaterSelPin = 15
sensorValue = 0
grovepi.pinMode(heaterSelPin,"OUTPUT")
grovepi.digitalWrite(heaterSelPin, 1)

while True:
    grovepi.DigitalWrite(heaterSelPin,0)
    sensorValue = grovepi.AnalogRead(analogInDatPin)
    result = 1023 - sensorValue
    sleep(0.1) # Time in seconds.

Note: I have not tested this as I don’t have the sensor and currently working with Microsoft IoT with c#.

Let me know if this works for you

Hey Exadon,
Thanks for hopping in, the code indeed look right and should work for the Alcohol sensor.

@amol: do let us know if this works, and if it does work well we’ll be glad to merge it in the GrovePi repo.

-Karan

Thanks for this example code. I had to modify what @exadon wrote a bit for spelling reasons but I cannot get it to work.

My setup is RPi 3B+ with GrovePi+ hat with Alcohol Sensor v1.2. Please can you help to get the code to work? It hangs on line 12 (sensorValue = grovepi.analogRead(analogInDatPin) line).

from time import sleep
import grovepi

analogInDatPin = 0
heaterSelPin = 15
sensorValue = 0
grovepi.pinMode(heaterSelPin, "OUTPUT")
grovepi.digitalWrite(heaterSelPin, 0)

while True:
    grovepi.digitalWrite(heaterSelPin,0)
    sensorValue = grovepi.analogRead(analogInDatPin)
    result = 1023 - sensorValue
    print(result)
    sleep(0.1) # Time in seconds.

Thank you