Can i connect any Sensor with raspberry pi? For example, I have a water flow sensor like this one, and an ultrasonic sensor like this one.

Is it possible to connect it to a Raspberry Pi? Or I'll need libraries to connect it to Raspberry Pi? And what exactly are these libraries? What if these sensors are chinese? Would that work, or will I need an Ardiuno board? What will I have to do to make it work without a microcontroller ?

Sorry for stupid question but I'm new to all this.

  • Your sensor are going to need a level shifter or a voltage divider since they work on 5v and the Pi GPIO can not accept 5v logic. There is a good tutorial on the ultrasonic sensor here modmypi.com/blog/…. This question raspberrypi.stackexchange.com/questions/34480/… should get you started with the water flow sensor. Both of the links use the RPi.GPIO library which is either easily installed or already on your Pi. The linked posts will have more details, – Steve Robillard Jan 12 '16 at 18:51
  • But isn't that library only for that sensor ? what if i have a chinese sensor ? which is available in like 3$ . ? then i would have to use ardiuno board right ? – B.Joshi Jan 12 '16 at 18:55
  • You do not need an arduino. What makes a Chinese sensor different. The RPi>GPIO Library is a python library to control the GPIO pins it is not specific to the sensor. – Steve Robillard Jan 12 '16 at 18:55
  • No, but most of the cheap sensors operate the same and are made in China. The ultrasonic sensor is specific because it purports to be an HC_SRO4 which the linked utorial also specifically mentions. The water flow sensor does not mention exactly how it works, a model number , nor does it include sample code, but it will likely work just like the one in the linked question.. – Steve Robillard Jan 12 '16 at 19:04
  • thank you steve... i appreciate your time and effort . I am a complete noob in this thing with almost 0% experience. thank you – B.Joshi Jan 12 '16 at 19:06

Asking if you can connect any sensor with/without libraries is so broad no one could answer it and the library(ies) needed would depend on the sensor.

The sensors you mention are going to need a level shifter (like this one from Adafruit) or a voltage divider (as discussed in the links below) since they work on 5v and the Pi GPIO can not accept 5v logic. ModMyPi has a good tutorial on the ultrasonic sensor. This question covers the usage of a waterflow sensor.

Both of the links use the RPi.GPIO library which is either easily installed or already on your Pi. If not already installed you can do so with the following command:

sudo apt-get install python-dev python-rpi.gpio

You do not need an arduino. You can connect the sensors to the GPIO pins (with the caution that you will need a voltage divider or level shifter between the sensor and the GPIO pins).

Give your experience level you may want to pick up either Make Sensors or Getting Started with Raspberry Pi. I have read both and they are a great introduction. They will easily payback their price by keeping you from damaging your Pi and include source code that will make your projects easier.

Also, buying parts from China, ebay etc. may seem like a good idea since they are cheaper, but especially for someone just starting out I would suggest spending a little more money and purchase from Adafruit or a similar reseller. This has several advantages:

  • They provide support for their products.
  • They often have complete tutorials including libraries and sample code. They also regularly update these as required over time.
  • They ship fast. depending on where you are in the world, you are likely to receive your parts much faster. It can take a month or more to get parts from China to my home in CT. With that long a wait it is easy to loose interest in a project, or to even have to relearn some of what you know.

In the end the extra cost for the parts is well worth it until you have some experience under your belt.

  • thank you . Does the library work for "water flow sensor " out there ? like the one i linked in the question ? iam completely new to this thing. – B.Joshi Jan 12 '16 at 19:03
  • Without more info, a specific part number no can tell. But likely yes. May I suggest instead of peppering me with questions, you read the linked content thoroughly first. – Steve Robillard Jan 12 '16 at 19:05
  • i've been through that question before i asked my question .. hehe . iam totally fuc*** up . sorry . – B.Joshi Jan 12 '16 at 19:07
  • @B.Joshi If you have read through the question feel free to ask a new question on the parts you don't understand. – Steve Robillard Jan 12 '16 at 19:13
  • @B.Joshi I have made some edits and added a few suggestions that I hope will help you out. – Steve Robillard Jan 12 '16 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.