wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

What's the best way to phyiscally connect sensors to your Pi

Fri Jan 02, 2015 8:27 pm

I am building a wine cabinet monitor as a RPi project. It uses a 1-wire temperature sensor to log temperatures (and will email me if the temp gets too high) and some magnetic door sensors to log/alarm when the cabinet is opened. Right now this project is on a breadboard but I will eventually solder it all together on something like a perma-proto board. I will have either 4 or 5 wires to connect to my Pi - three wires from the DS18B20 and one or two (depending on if I share ground with the DS18B20) from my door sensor.

What is the best way to connect these sensors to my Pi's project board? I could solder them but that makes it permanent and a pain to make changes. Should I use some sort of a screw terminal to screw the wires onto connectors on the project board? Or should I put something like an RJ-45 terminal on my project case and then wire all of my sensor to different wires in a cable that connects into the RJ-45 connector? Or are there other, better ways?

How do other people do this?

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: What's the best way to phyiscally connect sensors to you

Fri Jan 02, 2015 8:44 pm

I like this style of removable screw terminal, very easy to unplug when needed.
Doug.
Building Management Systems Engineer.

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Fri Jan 02, 2015 8:56 pm

Ok, that looks useful.

Do I have this correct - you solder the "female" part to the project board and then you screw the wires into the male terminals and then you can plug and unplug as you desire?

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: What's the best way to phyiscally connect sensors to you

Fri Jan 02, 2015 9:05 pm

I just hooked up a bunch of DS18B20 sensors to my Pi. I connected 3 wires to the GPIO pins for the one-wire bus. These wires go out of the Pi to an RJ45 socket (about 15cm total length).

Each one-wire sensor is soldered onto a 50cm length of phone cable with an RJ11 plug crimped on the end. The sensors are daisy-chained around the hot-water system using RJ11 couplers and more phone cable, then the last one is wired back to the socket on the Pi with a 5m Cat5e patch lead.

If your Pi is not being installed in your cabinet then I suggest you use RJ45 sockets and Ethernet patch leads. Allocate three (or two) pins for the one-wire sensor, and one other for the switch.

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Fri Jan 02, 2015 9:22 pm

Thanks, I wasn't going to put the Pi in the cabinet - I was likely going to run something like a flat ribbon cable from inside the cabinet so that it doesn't let too much cold air escape. The other option is to drill a hole in the cabinet and run a cable and then seal up the hole with silicone.

ame - A couple of questions for you since it seems you are doing a similar project.

Question 1
I am using a four conductor phone wire to carry the signal from the DS18B20 sensor and I am also wiring one end of my magnetic door sensor to ground - so the ground connection is shared at the far end of the pi. The fourth wire is connected to the other wire of my door sensor. Note that the door sensor is "closed" when the door is closed. When I try to use the GPIO.falling or GPIO.rising commands I seem to get false positive results but when I just sense the state of the GPIO pin connected to the door sensor then everything works properly. Any idea if this could be caused by "noise" from sharing the ground pin? Anyone know if I can eliminate this noise by using something like a capacitor between the two wires of the door sensor?

Question 2
Similar to your water heater - I have passive solar heating panels for my swimming pool. I want to put DS18B20 sensors on to both the input and output hoses to measure the temperature before and after the solar panels. How did you connect your sensor to your water heater. The best idea I have been able to come up with is to tape the waterproof versions of the sensors to the 1" black pipe that carries the water. I am not overly concerned about the absolute temperature of the water in this instance, I am more interested in the difference between the two pipes to know when the water is being heated and by how much.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: What's the best way to phyiscally connect sensors to you

Fri Jan 02, 2015 9:32 pm

Hi there,

Your switch problem could be electrical noise or contact bounce. If you poll the switch instead of using interrupts then you can avoid bounce.

Regarding attaching the sensors to the pipes: I am using the regular TO92 packaged devices. I solder the wires from 4-core flat phone cable onto the legs of the device and use tiny heatshrink on each leg, then bigger heatshrink on all legs and the sheath of the cable. I did not extend the heatshrink onto the package.

The hot water system has copper pipes with foam tube insulation. I removed the insulation and used a tie-wrap to clamp the sensor to the pipe (flat face against the pipe). Then I replaced the insulation. It's not perfect, but the sensor readings are definitely representative.

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Fri Jan 02, 2015 9:42 pm

I think you are right about the bounce. I tried adding a debounce parameter but it doesn't seem to work.

Thanks for your other advice regarding the pipe sensor. I think I will get the waterproof versions and use black electrical tape to tape the sensors to the black plastic pipe.

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: What's the best way to phyiscally connect sensors to you

Sat Jan 03, 2015 10:56 pm

wayner wrote:Ok, that looks useful.

Do I have this correct - you solder the "female" part to the project board and then you screw the wires into the male terminals and then you can plug and unplug as you desire?
Yes, that's correct.

These plugs may be overkill for your project and you might prefer the RJ45 approach. The terminals are fairly large in comparison to telephone wire.
Doug.
Building Management Systems Engineer.

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 8:52 am

I was testing modular 4P4C connectors recently. They seem to work ok for slow speed two wire I2C and have been used on one wire for long time already. Here is a photo

https://github.com/oh7bf/I2C-modular-co ... pters/wiki

The only inconvenience is that you need a custom made printed circuit board since they do not fit on a standard strip board for prototyping.

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 9:53 am

wayner wrote:... I will have either 4 or 5 wires to connect to my Pi - three wires from the DS18B20 and one or two (depending on if I share ground with the DS18B20) from my door sensor.

What is the best way to connect these sensors to my Pi's project board? ...
Use 3 wires for the DS18B20 sensors + 2 wires for the door sensors. Door sensor operation may 'modulate' the temp sensor lines. A small capacitor (maybe 0.01uF) across the door sensor may also reduce any noise.

For my bird box I'm using a small copper strip board, a 26w long pin header, and miniature pcb screw terminals. This gives me reliable incoming connections, no need to solder connections on the RPi, and I can still break the whole system down if necessary:-
http://captainbodgit.blogspot.co.uk/201 ... del-a.html

Monitor the door sensor by polling the input every (say) 5 seconds, as this does not appear to be a time/speed critical application.

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 4:02 pm

How would you poll every 5 seconds and why poll rather than using GPIO interrupts? I am polling right now but it hammers the CPU at 100%. I am currently using Python code like this:

Code: Select all

	while True:
		if io.input(door_pin):
Even if I put in a wait 5 seconds at the end of my while loop isn't it going to still using up CPU resources? Currently my code seems to work fine - I am using a cron job to log the temperature to a SQLite database every fifteen minutes and I am polling the door continuously and logging any activity. I will also add alarm emails for high temperature and door events. The only issue is the 100% CPU usage - in my X-Windows screen I get a solid bright green rectangle indicating the CPU is always at 100%.

If I can get it working reliably shouldn't I use falling and rising edge detection interrupts since that is much easier on the CPU? I won't be using this Pi for too much else but it just seems like sloppy coding to leave it like this.

Your birdhouse monitor looks very interesting. Do you power it with solar, batteries or both? How much power consumption is there with a Model A+ with wifi active? I will soon be starting another projectwhich will require a waterproof battery/solar powered setup.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 4:54 pm

Cheap way - solder the sensors to lumps of this http://www.ebay.co.uk/itm/DK-New-10-Pcs ... 3393746028

Its dead easy to cut to whatever length you require - it doesn't need to be the full length of the GPIO socket, makes a good solid connection and doesn't involve soldering on the Pi itself. Its what I use for sensors.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 6:38 pm

wayner wrote:How would you poll every 5 seconds and why poll rather than using GPIO interrupts? ....
Nothing wrong with interrupts, I just thought you said you had problem getting it to work.

Tight loops in Python will hammer your cpu. But if you "import time" and add "time.sleep(5)" within your loop, I'd expect cpu% to drop from 100% to less than 10%.

5 seconds was just a suggestion. If you think your teenage son is stealing your hooch, you may need to drop this to 1 second or less (...and fit a video camera!)
wayner wrote: Your birdhouse monitor looks very interesting. Do you power it with solar, batteries or both? How much power consumption is there with a Model A+ with wifi active? I will soon be starting another projectwhich will require a waterproof battery/solar powered setup.
My RaspberryPi bird box system runs from a 12Volt, 12Ahour "mobility" lead-acid battery (like this one: http://www.amazon.co.uk/Mobility-Scoote ... ttery+12Ah) ....so not great for your swimming pool project.

I think my 2014 system ran between 150 - 200mA, but that was with a model A + wifi + PiCam + 3 leds (http://captainbodgit.blogspot.co.uk/201 ... aging.html).

I did some comparisons between models (http://captainbodgit.blogspot.co.uk/201 ... del-a.html) which lead me to believe the 2015 system might run between 100 -150mA.

I hope this helps.

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 7:45 pm

That sleep command works beautifully. Even using sleep(1) the solid green block turns into a black rectangle with a nice green lawn along the very bottom. I am having problems with the interrupt but I want to try to solve this. This current setup is only using 4 wires (sharing a ground between the DS18B20 and the door switch) and with about 5m of 22AWG telephone-type wire.

Not worried about the teenage son (don't have one) this is just a fun educational project for now.

The lead acid battery might work ok for my pool pi. Size and weight don't matter too much - I could just use a smaller lead acid battery, or two to allow better balancing - as I need a lot of surface area on the box for the solar panels.

If your 2004 system used 150-200mA and the battery was 12Ah then you should get at least 60 hours. Is that how long the battery actually lasted? And how did you recharge the battery (or did you just swap batteries every few days)? Any reason that you don't use solar?

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 8:25 pm

wayner wrote:...If your 2004 system used 150-200mA and the battery was 12Ah then you should get at least 60 hours. Is that how long the battery actually lasted? And how did you recharge the battery (or did you just swap batteries every few days)? Any reason that you don't use solar?
Here are some notes taken from 2014:-
Run time (hr) : terminal volts
4 : 12.8
20 : 12.3
37 : 12.15
63 : 11.5
65 : 10.5

...so it looks like the battery starts to collapse after about 60hrs as you predicted. However, you are not supposed to discharge (most) lead-acid batteries below a certain percentage of charge (maybe 40% but can't remember). So I was generally swapping batteries after about 50hrs.

I can't justify solar cells. The nest box season is quite short (http://captainbodgit.blogspot.co.uk/201 ... ilent.html). So these boxes are put out beginning of March and taken down again at the end of June. And I can't be sure I'll get any birds to nest in them.

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 8:29 pm

I guess that makes sense then. But I don't think the panels are that expensive - I haven't figured out exactly what I want but I would think that $50-$75 would do it.

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 9:07 pm

wayner wrote:... I don't think the panels are that expensive...
$75 Canadian is about £42. Maybe I'll look at this again, if I can find a 2nd use for it (July to March).
I guess it would need some kind of charging control circuit.

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Sun Jan 04, 2015 9:49 pm

And in the spring/summer when days are long, you wouldn't need a huge solar panel. You could also get away with a much smaller battery.

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: What's the best way to phyiscally connect sensors to you

Mon Jan 05, 2015 12:15 pm

wayner wrote:And in the spring/summer when days are long, you wouldn't need a huge solar panel. You could also get away with a much smaller battery.
Don't be fooled by Steve's location data, Sunny Southern England only exists for a few days each year.

Steve, Canadian panle prices seem much higher than UK ones, For £20.38 sunstore sell a "weatherproof" 12v 10W panel (their 5w panel is only £12)
Small, compact, all weather and built to high standards. An ideal panel for steady battery charging and maintenance or your small off grid lighting project. This high quality 10w monocrystalline 12v solar panel works in both sunny and overcast conditions and is fully weatherproof. Comes supplied with 2 meters of cable, a blocking diode to prevent reverse charging and crocodile clips for easy battery connection

UK Summer generation conditions this panel will create approx 7ah per day
Some concerns: 7ah in summer is a nice quote but will it hold up? Panel placement will be key, would you be able to locate the panel where it will be able to maximise daylight without the cable being at risk? I'm thinking that ideal nesting conditions are quite different from ideal solar panel placement options and (of course) March isn't Summer giving less daylight hours.
Doug.
Building Management Systems Engineer.

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: What's the best way to phyiscally connect sensors to you

Mon Jan 05, 2015 5:39 pm

BMS Doug wrote:[...Don't be fooled by Steve's location data, Sunny Southern England only exists for a few days each year.
How very dare you?

I saw the sun just 3.5 months ago....briefly.
BMS Doug wrote: ...Panel placement will be key...ideal nesting conditions are quite different from ideal solar panel placement options...
Yeah, it would look ugly in either of my chosen locations for this seasons bird boxes. I currently hide the battery in the flower bed, underneath a pot to keep the rain out.

Although run time between charges is 50-60 hours, the whole point of my controller is to switch the system off when there is nothing happening. So in the early days (March till mid-April) the battery will last a week of more.

However, I want to put a night camera near our compost heap. The battery could sit inside a remote garden shed (no mains power), and be charged during the day via a solar panel on the shed roof. But I won't be starting this project for while (maybe April).

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: What's the best way to phyiscally connect sensors to you

Mon Jan 05, 2015 5:45 pm

I think I did way overestimate the cost of a solar panel. Here is a 15V - 5W unit that costs US$35. That should be the right Voltage level to charge a 12V battery and it should be outputting about 300mA so that should be good even during the day - 150mA to drive the Model A+ and another 150mA to charge the battery. If you need more you could hook up another panel in parallel and double the current.

Return to “Automation, sensing and robotics”