Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to swap LDR sensor module? #13

Open
tstack77 opened this issue May 1, 2017 · 11 comments
Open

Possible to swap LDR sensor module? #13

tstack77 opened this issue May 1, 2017 · 11 comments

Comments

@tstack77
Copy link

tstack77 commented May 1, 2017

Thanks for this! I have this built and it definitely works, but I'm still getting false alarms after lots of adjustments to both the ini and the board sensitivity. My washer has a bunch of different modes (autosoak etc) that makes measuring the vibration a bit hit or miss. I would love to use an LDR sensor module and sugru the sensor over the power led on my machines. It seems that I wouldn't need to do anything hardware wise, but I'm a bit unsure about the differences to the python script. I'm not finding a lot of documentation on the 801s, does it simply give a true/false digital reading to the rpi, or is the output not binary?

Thanks again

@Shmoopty
Copy link
Owner

Shmoopty commented May 1, 2017

That is a really interesting idea... I like it.

The hardware you link to should work. Same as with the 801s in my photographs, you'll want to use the DO pin and ignore the AO pin.

You're correct that the 801s gives a binary true/false output, although it turns on and then off with every wiggle. Because of that, some minor changes to the python script would be needed. I think it would be easy for me to modify the script so it would work with either a vibration sensor or a light sensor.

Here's the current logic:

  • Trigger "appliance turned on" if the sensor has switched from "off" to "on" during every second, for the last x seconds.
  • Trigger "appliance turned off" if the sensor has not switched from "off" to "on" during any second, for the last x seconds.

The python script should be able to handle both vibration and light sensors if the logic were changed to:

  • Trigger "appliance turned on" if the sensor has experienced the "on" state during every second, for the last x seconds.
  • Trigger "appliance turned off" if the sensor has not experienced the "on" state during any second, for the last x seconds.

If you let me know that you've ordered that part, I'll revise the script for you. Deal?

Shmoopty

@tstack77
Copy link
Author

tstack77 commented May 1, 2017

Deal!

I ordered a 4-pack of the sensors last night. Figured worst case I would try my hand at actually learning python (and by learning I mean hacking up your script).

The logic is exactly what I was thinking too, figured it was close enough to your original script to attempt modification.

@Shmoopty
Copy link
Owner

Shmoopty commented May 8, 2017

Update -

I've modified the script. It still works with sensors that turn on and off frequently during an appliance cycle, but it should also work if the sensor stays on, like an operational light sensor would.

Do me a favor, please? Let me know if this script works for your light sensor project? Good luck!

@tstack77
Copy link
Author

tstack77 commented May 8, 2017

Will do! I ordered the sensors from China ($2 for 4 including shipping) and expect them around the 20th. I'll update with some pics.

Thanks again for the modification

@tstack77
Copy link
Author

tstack77 commented May 16, 2017

Good news, the LDR sensor works perfectly for triggering light from an led! I didn't even need sugru to create a light shroud, simpy used 1mm thick 3m double sided tape.
Bad news, endless stream of notifications sent when the cycle is finished.

My settings:
sensor_pin = 23
seconds_to_start = 20
seconds_to_end = 10
end_message =Dryer Completed
Notifications sent via ifttt.

ldr2
ldr1

@Shmoopty
Copy link
Owner

I'll take a look at the code and see if something smells funny. Thanks for getting back.

@tstack77
Copy link
Author

Thanks Shmoopty, I really appreciate you looking into this.

Over the past few days I've been trying on my own to add Pushover support to your script, but my python skills are proving to be quite insufficient. I've tried the below additions but it's still not firing. I hate to ask for any more of your time but I'm hoping there's something obvious that you can see and I'm missing.

Added to vibration.py:
From https://pushover.net/faq#library:

def pushover(msg):
    try:
        import httplib, urllib
		conn = httplib.HTTPSConnection("api.pushover.net:443")
		conn.request("POST", "/1/messages.json",
		  urllib.urlencode({
		    "token": "pushover_app_token",
		    "user": "pushover_user_key",
		    "message": "msg",
		    "device": "pushover_device",
		  }), { "Content-type": "application/x-www-form-urlencoded" })
		conn.getresponse()
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass
        if len(pushover_app_token) > 0:
            pushover(pushover_app_token, message)

pushover_app_token = config.get('pushover', 'APP_TOKEN')
pushover_user_key = config.get('pushover', 'USER_KEY')
pushover_device = config.get('pushover', 'DEVICE')

Added to vibration_settings.ini:

[pushover]
app_token = ##########
user_key = ##########
device = Galaxy

@Shmoopty
Copy link
Owner

Regarding "endless stream of notifications", which notifications are they? Start, end or both?

Are they really endless, or do they stop eventually?

Fork this project with your pushover mods and I think I'll have time to take a look. Then you'll get credit in the project too.

@tstack77
Copy link
Author

Project forked and modified script uploaded.

I never really tested if the end-notifications ever stopped on their own. I could try to run it in a terminal without sending the notification if an answer isn't apparent from the uploaded script.

@HIT2022
Copy link

HIT2022 commented Jan 3, 2020

@tstack77 Were you able to get past the endless notifications? My washer is giving me a similar level of difficulty so I'm considering the LDR switch.

@tstack77
Copy link
Author

tstack77 commented Jan 5, 2020

@tstack77 Were you able to get past the endless notifications? My washer is giving me a similar level of difficulty so I'm considering the LDR switch.

I was, but it took a bit of a rewrite and I can't remember exactly the solve (two years ago and such). The LDR sensor approach has been rock solid and it's been run since without issue. If you have a light on your machines I definitely recommend it.

Edit: I did end up making a sugru cover over the sensor to stop any random light source triggering a notification. Give it a go and I'll respond if you run into issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants