In this chapter, we are setting up the module for two Hempy buckets based on an Arduino Nano V3 and nRF24L01+ wireless transceiver. Optionally an Arduino RF-Nano could be used, that has the wireless transceiver already integrated.
The module is responsible for:
Measuring the individual bucket weights
Determine when and how long to water based on the bucket weight
Controlling the pumps for watering
Responding to commands from the Main module and reporting back
Gbox420 sketch: Gbox420_Nano_Hempy
SketchUp 3D Warehouse: Gbox420 - ShowRoom - Hempy bucket tab
Or visit the Gbox420 GitHub page and download the entire project.
If you decide to use a different pin layout from what is shown below, update the Settings.h file, look for variables ending with Pin
Arduino RF-Nano has the nRF24L01 wireless transceiver already integrated. Here are a few test scripts you can run to make sure the wireless communication works:
By updating the wireless transmission rate:
Test-WirelessConnection_Nano.ino
Expected test result: 'Data Rate' row should have changed from 1MBPS to 250KBPS
You will need a second RF-Nano or an Arduino board with a nRF24L01+ transceiver for this test. Tests the two-way communication between a Transmitter and a Receiver by exchanging a set of pre-defined stuct (group of different data types) known by both parties. One device will initiate the communication (Transmitter) by passing the commandTemplate struct. When the Receiver gets this command, it returns it to the transmitter with a pre-cached responseTemplate struct. A maximum of 32bytes of data can be exchanged in one transmission.
Transmitter: Test-WirelessTransmitter.ino
Receiver: Test-WirelessReceiver.ino
Expected test result: Both devices printing the exchanged data to their serial outputs.
When you need to transfer data larger than 32 bytes, it must be split into multiple transmissions. The transmitter will send multiple commands in a fixed order containing different pre-defined stucts known by both parties. When the Receiver gets this command it confirms it back to the transmitter with a pre-cached response and based on the current command's SequenceID it loads the next response into the ACK cache. Templates of the data exchanged: WirelessCommands_Test.h
Transmitter: Test-WirelessTransmitter_MultiPackets.ino
Receiver: Test-WirelessReceiver_MultiPackets.ino
Expected test result: Both devices printing the exchanged data to their serial outputs.
Rf-Nano
ATmega328P microcontroller integrated with NRF24L01 transceiverWhen a module starts up or receives a command a piezoelectric buzzer provides audio feedback. To protect the buzzer from excess current make sure to have a minimum 200Ω resistor between the Arduino port and the + side of the buzzer. If you find the volume too loud use a larger resistor. I took a few sound intensity measurements using different resistance values: 220Ω - 71dB, 330Ω - 69dB, 1kΩ - 59dB, 3kΩ and above are inaudible.
+ pin: Arduino 2 (digital output). Connected through a resistor to limit current and volume: 200Ω(loud) - 1kΩ(quiet)
- pin: Arduino GND (Ground)
Expected test result: Plays the Star Wars theme song
Bypass capacitors or decoupling capacitors are added between each power and ground line to filter out noise from the power supply and make the entire circuit more stable. Here is an excellent video from EEVblog that explains bypass capacitors.
Be mindful that electrolytic capacitors are polarized, meaning they can only be connected one way in a circuit. The negative lead is generally marked on the capacitor with a bar or "-" symbol, connect this to Ground (or the more negative line). Do not mix up the polarity as this will heat up and destroy the capacitor in a few seconds. Ceramic capacitors have no polarity, they can be connected in any direction. The capacitance of both capacitors can be changed based on the power needs, as long they support a minimum of 16V voltage.
DC input 12V
2200 uF - 16V Electrolytic capacitor + pin: +12V DC
2200 uF - 16V Electrolytic capacitor - pin: Ground
0.1 uF - 50V Ceramic capacitor pin 1: +12V DC
0.1 uF - 50V Ceramic capacitor pin 2: Ground
DC step down output 7V
1000 uF - 16V Electrolytic capacitor + pin: DC step down Vo+ output
1000 uF - 16V Electrolytic capacitor - pin: Ground
0.1 uF - 50V Ceramic capacitor pin 1: DC step down Vo+ output
0.1 uF - 50V Ceramic capacitor pin 2: Ground
Arduino 5V
470 uF - 16V Electrolytic capacitor + pin: Arduino 5V
470 uF - 16V Electrolytic capacitor - pin: Ground
0.1 uF - 50V Ceramic capacitor pin 1: Arduino 5V
0.1 uF - 50V Ceramic capacitor pin 2: Ground
Arduino 3.3V
10 uF - 16V Electrolytic capacitor + pin: Arduino 3.3V
10 uF - 16V Electrolytic capacitor - pin: Ground
0.1 uF - 50V Ceramic capacitor pin 1: Arduino 3.3V
0.1 uF - 50V Ceramic capacitor pin 2: Ground
To convert the 12V power input and feed the Arduino Nano a DC to DC step down power supply is used. These buck converters are cheap, power-efficient, have a small physical size, and support a wide range of DC input voltages. To adjust the output voltage you will need to have a multimeter tool to monitor the output voltage while changing the adjuster screw. Be careful: The Vin pin does not have a reverse polarity protection diode like the barrel jack, never mix up GND and Vo+ from the power supply!
VO+ pin: Arduino Vin. Adjusted to 7 volts.
GND pin: Arduino GND (Ground) + Power input ground (Common ground)
In+: Positive power input (12V)
EN pin: Not connected
DC-DC Buck Converter
Input voltage: DC 4.5 to 24VOutput voltage: Adjustable DC 0.8 to 17VOutput current: Max 3ATurning off inductive loads like a solenoid, motor or a relay (anything that has a coil that creates a magnetic field) generates a harmful voltage spike. A flyback diode is used to re-circulate the current generated by the collapsing magnetic field through the load until it dissipates, protecting other components on the circuit from a high reverse voltage shock. Here you can find a highly recommended summary video of inductive spiking, explaining why it is crucial to have a flyback diode.
Flyback diodes are connected between the power lines as close to the inductive load as possible. The diode allows current to flow in only one direction indicated with a marking on one of its ends, current can only pass from the unmarked side to the marked side. Connect the marked side to the positive power line and the unmarked to the ground. During normal operation, no current will flow through the diode. When the power to the motor/relay is turned off their magnetic field will start collapsing and this force will continue pushing electrons. This is when the diode will start conducting and route the electrons back to the load, avoiding voltage build-up and sparks. Here is a much better explanation with pictures of the process.
Schottky diodes have low power consumption and support fast switching frequencies making them ideal flyback diodes for PWM- controlled motors. When selecting a diode check the following parameters:
blocking voltage: At least double of the voltage needed by the device it protects (e.g. Load 12V -> Diode 24V )
peak surge current: Higher than the maximum current the device it protects will use (e.g. Load 3A -> Diode 5A)
I have used the 1N5818 diode (30V blocking voltage, 25A peak surge current) between the power lines of the Hempy bucket pumps.
Running motors generate electrical noise, this needs to be filtered using capacitors connected between:
Ground and motor housing
VCC and motor housing
Ground and VCC
Add the filter capacitors to both Hempy pump motors. You can find out more about this technique on Pololu.
Two solid-state MOSFET relays are used to control the speed of the watering pumps. Solid-state switches can be turned on and off very fast, making them ideal to control the motor speed using a PWM signal generated by the Arduino.
This component is optional and can be replaced with a standard relay as long as the Speed and SpeedLowLimit are set to 100 in the Settings.h file to disable PWM.
In+ : Max 24V /10A DC power in
In- : Ground in
Out+ : DC power out
Out- : Ground out
Transistor DC Relay 1
VCC pin: Arduino 5V
GND pin: Arduino GND (Ground)
S pin: Arduino 3 (digital output with PWM support) - Bucket 1 pump
Transistor DC Relay 2
VCC pin: Arduino 5V
GND pin: Arduino GND (Ground)
S pin: Arduino 5 (digital output with PWM support) - Bucket 2 pump
Expected test result: Starting from 0% the motor speed gradually increases to 100%, then decreases back to 0%. Note the point where the motor stalls and starts back again, update the SpeedLowLimit in the Settings.h file to a ~10% higher value to ensure not stalling the motor even at 0% motor speed.
There are a total of four weight sensors in the Hempy module. They build based on the building a Weight platform chapter.
They measure the weight of:
Hempy Bucket 1
Waste Reservoir 1
Hempy Bucket 2
Waste Reservoir 2
Bucket 1 weight sensor
GND pin: Arduino GND (Ground)
DT pin: Arduino 5 (digital input)
SCK pin: Arduino 6 (digital output)
VCC pin: Arduino 5V
Bucket 2 weight sensor
GND pin: Arduino GND (Ground)
DT pin: Arduino 7 (digital input)
SCK pin: Arduino 8 (digital output)
VCC pin: Arduino 5V
Before using the weight platforms they need to be calibrated using the sketch from the bottom of this section.
Test-WeightSensor_HempyBucketPlatforms
Test-WeightSensor_HempyWastePlatforms
The sketch will return two parameters for each weight sensor that needs to be written in the Hempy module's Setting.h file under WeightSensorSettings - Scale and Offset variables.
Offset: The raw reading when no weight is on the scale. The calibration sketch will automatically tare the scale to 0 when it starts up and display the offset value.
Scale: The offset adjusted raw reading is divided by the scale factor to get the weight of the item on the scale in the calibrated units (kg or lbs)
Follow this procedure to calibrate the weight sensors:
Find two objects with known weights and update the WeightSensor1_CalibrationWeight and WeightSensor2_CalibrationWeight variables in the test sketch. For example, I used two 2kg dumbbell weights.
Upload the test sketch
Remove all weights from the scales and press the Reset button on the Arduino. This will restart the sketch and automatically tare the scales to 0.
Place the known weights on the scales and wait for a calibration cycle to run (Runs every 10 seconds).
Once the calibration runs the sensor reading should match the calibration weight. At this point send any Serial input using the Send button on top of the Serial Monitor, I sent "ok" in the test run shown below. The sketch will display the Offset and Scale calibration values for both scales.
In the Hempy module's Setting.h file under WeightSensorSettings update the Scale and Offset variables with the calibrated values:
7. (Optional) You can also update the test sketch Offset and Scale variables and change the CalibrationComplete variable to true. After uploading the sketch it will skip the calibration part and just show the current weight on the scales.
Expected calibration output:
Output with CalibrationComplete variable set to true:
4 set (4x4 cells) Rated to 50kg / 110lbs
Requires soldering!
To relay data between the Main module and all other modules nRF24L01+ wireless transceivers are used. The Main module always acts as a transmitter, all other modules are receivers. When a receiver gets a package from the Main module it sends back a pre-cached Acknowledgement package to report its current status. You can find a great in-depth overview of the wireless module at lastminuteengineers.com.
Specs
Power supply voltage: 1.9V to 3.6V (Use the Arduino's 3.3V pin to power the module, do not connect the VCC pin to 5V! )
I/O pins tolerate 5V logic (Arduino can directly communicate with the module)
Communicates over a 4 pin Serial Peripheral Interface (SPI)
Draws 12 mA during a transmit, 0.026 mA in standby, and 0.0009 mA at power down
Maximum 125 channels
Operates using 2.4 GHz frequency band
Maximum range: 100 meter / 330 feet outdoors with internal antenna, 1000 meter / 3300 feet with external antenna
Supported data rates: 250kbps (Largest range) / 1 Mbps / 2 Mbps (Fastest data transfer speed)
GND pin: Arduino GND (Ground)
VCC pin: Arduino 3.3V
CSN pin: Arduino 9 (digital output)
CE pin: Arduino 10 (digital output)
MOSI pin: Arduino 11 (digital output)
MISO pin: Arduino 12 (digital input)
SCK pin: Arduino 13 (digital output)
Test-WirelessConnection_Nano sketch
This sketch will verify the connectivity between the Arduino and the nRF24L01+ wireless transceiver.
Expected test result: Successful update of the "Data Rate" field
This sketch will verify the nRF24L01+ wireless transceiver communication between an Arduino Mega as the Transmitter, and an Arduino Nano as a Receiver. Requires an Arduino Mega to be set up as a Transmitter, check out the Main module - Test-WirelessTransmitter sketch for more details on setting up the Transmitter.
Expected test result: Printing the received command from the Transmitter on the serial output and sending a response message back.