Power & Source of Big Ideas

Wiring a relay and some sensors

Moderators: chensy, FATechsupport

Hi there,

newbie here - I have a NanoPi NEO Plus2 and would like to wire some (3 or 4) moisture sensor (model YL-69, with HC-38 modules) and then a 4-relay module. I have seen a few similar projects but my questions are:

  • will I be able to read AO (analog output) from these sensors?
  • do I have enough pins on the headers to control 4 relays and receive input from the sensors, or I need some expansion?

Thanks!
gdm85 wrote:
Hi there,

newbie here - I have a NanoPi NEO Plus2 and would like to wire some (3 or 4) moisture sensor (model YL-69, with HC-38 modules) and then a 4-relay module. I have seen a few similar projects but my questions are:

  • will I be able to read AO (analog output) from these sensors?
  • do I have enough pins on the headers to control 4 relays and receive input from the sensors, or I need some expansion?

Thanks!


- directly you can't read AO, but via some i2c module
- My latest project for driving relays https://www.youtube.com/watch?v=HxZ_FD5b5QQ - using nanopi m1 - neo plus 2 is the same, just not so many gpios. Just follow the docs: https://linux-sunxi.org/GPIO
- sensors via i2c. connect them, enable overlay (with armbian = armbian-config -> hardware -> enable i2c0 (or i2c1)

Than look out for libraries to drive those sensors ... some could already be supported directly by the kernel.
Thanks for your reply @igorp

Wow, that project is impressive! Lots of relays. Will watch the video later.

As for the library I was planning to use WiringPI since there's support for my device.

My problem is more on the pinout side: I cannot understand very well the pinout and/or what extra modules I should get.

The pinout is here: http://wiki.friendlyarm.com/wiki/index. ... _NEO_Plus2

All those that mention GPIO can be used as general I/O pins (aside from the other function mentioned)? They are identical for GPIO purposes?
I see 9 on the 24 pin GPIO1 header and 2 on the GPIO2 12 pin row header.

As for I2C: I am not against that approach but I find it inconvenient that the moisture sensors already have the HC-38 module and then I'd have to put another one for I2C.

I wanted to use AO because I think that the digital one will not be very useful/precise, but I have no experience with either.
gdm85 wrote:
Thanks for your reply @igorp

Wow, that project is impressive! Lots of relays. Will watch the video later.


Video is very short - just showing relays in action and the code for driving this is few lines of bash, no library whatsoever. It's usage is to power cycle single board computers that are under testing.

gdm85 wrote:
As for the library I was planning to use WiringPI since there's support for my device.


I would recommend not to use that. GPIO support is build into the kernel. WiringPi is deprecated, nobody will support you in case of troubles and project is long time abandoned by its authors. Support is limited to old demo quality stock kernel. I would not count on that your device is supported since many other things won't work and again - you will not be able to talk with anyone.

gdm85 wrote:
My problem is more on the pinout side: I cannot understand very well the pinout and/or what extra modules I should get.

The pinout is here: http://wiki.friendlyarm.com/wiki/index. ... _NEO_Plus2

All those that mention GPIO can be used as general I/O pins (aside from the other function mentioned)? They are identical for GPIO purposes?
I see 9 on the 24 pin GPIO1 header and 2 on the GPIO2 12 pin row header.


Almost all those (except gnd and vcc) can be used as GPIO since pins are multiplexed. If you don't have enough gpios, i2c gpio exttender exists.

gdm85 wrote:
As for I2C: I am not against that approach but I find it inconvenient that the moisture sensors already have the HC-38 module and then I'd have to put another one for I2C.


You can have more devices on a single i2c bus.
https://www.bluedot.space/tutorials/how ... n-i2c-bus/

gdm85 wrote:
I wanted to use AO because I think that the digital one will not be very useful/precise, but I have no experience with either.


Board doesn't have that capabilities which is why you need to use some analogue sensor that outputs data on i2c. Which is something completely normal. I have one moisture sensor, which is impedance meter in its core, at home that sends data digital way / via i2c ...
Was not aware that WiringPI is in such state, thanks. I am myself comfortable with using the kernel interface directly, had just made some online searches yesterday.

I can use the digital output of the moisture sensors and avoid using I2C, but yes - I am aware that I would need only one for that.

On another topic: will I have problems if I use a 5V relay board? Documentation says: All pins are 3.3V, output current is 5mA
I can power the relay board with 5V but then the control pins would still be at 3.3V

I have read online that some people were successful in using them this way, which is not something I would normally do.

Thanks!
gdm85 wrote:
On another topic: will I have problems if I use a 5V relay board? Documentation says: All pins are 3.3V, output current is 5mA
Thanks!


5V relays can be triggered with 3.3V without a problem. I am using those https://amzn.to/32qoLMk
Everything went okay and I could measure sometimes '1' on the sensor, however now - despite the digital output led of the sensor board being on, I always measure 0 on the GPIO.

A friend of mine suggested to put a pull-up resistor after VCC.

What is going on? I was honestly expecting the digital output to work out of the box when connected to a GPIO.

The GPIO is configured as 'in', no edge and active_low has always been 0.

Who is online

In total there are 6 users online :: 0 registered, 0 hidden and 6 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 6 guests