4

members

Easy Basics: Project 036b Soil Moisture Sensor YL-69, FC-28 or HL-69, SD Card or Micro SD Card Module

of Acoptex.com in UNO

Basics: Project 036b

 Project name: Moisture Sensor YL-69, FC-28 or HL-69,  SD Card or Micro SD Card Module

Tags: Arduino,  SD Card or Micro SD Card Module, Soil Moisture Sensor YL-69, FC-28 or HL-69

Attachments: sketch

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Arduino IDE ( you can download it from here  )

3.Jumper cables

4. Soil Moisture Sensor YL-69, FC-28 or HL-69 1 pc

5. Micro SD card with adapter 1 pc

6. SD card module 1 pc

General

The moisture sensor allows to monitor the water content in the soil. This is useful if you want to build an automatic watering system. You can also use it to just monitor your plants soil moisture.

We will learn how to connect soil moisture sensor YL-69, FC-28 or HL-69 and SD card module to Arduino board and log soil moisture data on SD card.

Understanding the SD card module

Note: whenever referring to the SD card, it means SD and microSD sizes, as well as SD and SDHD formats.

In some Arduino applications, it is advantageous to be able to store and retrieve information locally. You can do this with a Secure Digital, or SD, card. An SD card is a non-volatile memory card used extensively in portable devices, such as mobile phones, digital cameras, GPS navigation devices, handheld consoles, and tablet computers. Another type of SD Card is the Micro SD card. Measuring only 15 mm x 11 mm x 1 mm, it is the smallest memory card available. It is about one-quarter the size of a normal-sized SD card, or about the size of a fingernail.

The SD card module is specially useful for projects that require data logging.

The Arduino board can create a file in an SD card to write and save data using the SD library. Some modules work with micro SD card.

There's an onboard ultra-low dropout regulator that will convert voltages from 3.3V-6v down to ~3.3V (IC2). There's also a level shifter that will convert the interface logic from 3.3V-5V to 3.3V. That means you can use this board to interact with a 3.3V or 5V microcontrollers.

There are different models from different suppliers, but they all work in a similar way, using the SPI communication protocol. Because SD cards require a lot of data transfer, they will give the best performance when connected up to the hardware SPI pins on a microcontroller. The hardware SPI pins are much faster than 'bit-banging' the interface code using another set of pins.

As shown in the figure below, a micro SD card has 8 pins. The table describes the function of each pin.

Pin   Name     Description

1     NC       not connected

2     CS       Chip Select/Slave Select (SS)

3     DI         Master Out/Slave In (MOSI)

4     VDD      Supply voltage

5     CLK      Clock (SCK)

6     VSS      Supply voltage ground

7     DO       Master In/Slave Out (MISO)

8     RSV      Reserved

If you were to try interfacing this SD card yourself, you would have to ensure that you connected the pins of the SD card to the appropriate pins of the Arduino. Since we are using a commercially-available shield, this is not an issue.

SD card module features:

- Support card type: Micro SD ( <= 2G ), Micro SDHC ( <= 32G )

- Operating voltage: 3.2V - 5.5V (Onboard 3.3v LDO Regulator)

- Interface logic voltage: 3.3V / 5V compatible(Onboard level shift circuit)

- Logic Interface Type: Standard SPI port.

- Working mode: SPI mode.

- Applications: DIY projects with breadboard, Storage module, MP3 player memory.

- Compatibility: can be directly connected to Arduino board or Raspberry Pi

See the more information about SD card here.

Signals and connections of the SD card module


Note: depending on the module you’re using, the pins may be in a different order.

VCC (5V)  - connect to 5V pin Arduino Uno. If it is just VCC pin and no 3V3 pin connect VCC to 3.3V pin of Arduino Board

3V3 (or 3.3V) - connect to 3.3V pin Arduino Uno

CS (or SS or D3) (Chip Select or Slave Select) - the pin on each device that the master can use to enable and disable specific devices

MOSI (or DI or SI OR CMD) (Master Out Slave In) - The Master line for sending data to the peripherals

CLK (or SCK) (Serial Clock) - The clock pulses which synchronize data transmission generated by the master

MISO (or DO or SO) (Master In Slave Out) - The Slave line for sending data to the master

GND (or G) - ground

CD - this is the Card Detect pin. It shorts to ground when a card is inserted. You should connect a pull up resistor (10K or so) and wire this to another pin if you want to detect when a card is inserted. 

Understanding the soil moisture sensor YL-69, FC-28 or HL-69

You can read more about it here.

Signals and connections of the soil moisture sensor YL-69, FC-28 or HL-69

VCC (5V)  - connect to 5V pin of Arduino board. 

GND (or G) - ground pin of Arduino board

D0 - Digital output to Arduino board

A0 - Analog output to Arduino board

SIG - an analog signal out that can be attached to the ADC pin on any microcontroller. The value read on SIG will vary depending on the voltage with which you power the sensor

The "A0", is a serial signal 0-5 volts that when fully dry it outputs 5 volts, when fully wet, 0 volts. The "D0", is configured with the trim pot and is brought high when the moisture level reaches a desired point.

Build the circuit

SD card module -> Arduino Uno

VCC -> 3.3V or 5V (check module’s datasheet)

CS   -> 4 This can be the hardware SS pin - pin 10 (on most Arduino boards) or pin 53 (on the Mega) - or another pin specified in the call to SD.begin(). Note that even if you don't use the hardware SS pin, it must be left as an output or the SD library won't work. Different boards use different pins for this functionality, so be sure you’ve selected the correct pin in SD.begin().

MOSI -> 11

CLK   -> 13

MISO -> 12

GND  -> GND

Note: different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino SPI documentation.

The following picture shows the needed connections with the Arduino Uno 

Code

The output can be a analog signal and so you’ll get a value between 0 and 1023.

In this code we create a loggingMoisture() function function that we call in the loop() to log the moisture to the DATA.txt file in the SD card.

File Naming

FAT file systems have a limitation when it comes to naming conventions. You must use the 8.3 format, so that file names look like “NAME001.EXT”, where “NAME001” is an 8 character or fewer string, and “EXT” is a 3 character extension. People commonly use the extensions .TXT and .LOG. It is possible to have a shorter file name (for example, mydata.txt, or time.log), but you cannot use longer file names

Step by Step instruction

  1. Most SD cards work right out of the box, but it's possible you have one that was used in a computer or camera and it cannot be read by the SD library. Formatting the card will create a file system that the Arduino can read and write to. It's not desirable to format SD cards frequently, as it shortens their life span. You’ll need a SD reader and computer to format your card. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. See additional info here.
  2. Format the SD card as FAT16 or FAT32. Insert the SD card in your computer. Go to My Computer and right click on the SD card. Select Format...  
  3. A new window pops up. Select FAT32, press Start to initialize the formatting process and follow the onscreen instructions.
  4. Insert the formatted SD card in the SD card module.
  5. Connect the SD card module and soil moisture sensor to the Arduino Uno board.
  6. Open Arduino IDE.
  7. Plug your Adruino Uno board into your PC and select the correct board and com port
  8. Open up serial monitor and set your baud to 9600 baud
  9. Insert the soil moisture sensor probe to the soil.
  10. Verify and upload the the sketch to your Adruino Uno board.
  11. Open the Serial Monitor and check if everything is working properly.
  12. Let this project run for a few hours to gather a decent amount of data, and when you’re happy with the data logging period, shut down the Arduino and remove the SD from the SD card module.
  13. Insert the SD card to a SD card reader connected to your computer (PC), open it, and you should have a DATA.txt file with the collected data.
  14. You can open the data with a text editor, or use a spreadsheet to analyse and process your data.

Summary

We have learnt how to connect soil moisture sensor YL-69, FC-28 or HL-69 and SD card module to Arduino board and log soil moisture data on SD card.

Library:

SD library included in Arduino IDE

SPI library included in Arduino IDE

 

 

 

  • SD library included in Arduino IDE
  • SPI library included in Arduino IDE

 

Sketch:

  • See attachments on the begining of this project description. 


Other projects of Acoptex.com

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 20-10-2017
Viewed: 1886 times