0 Replies Latest reply: Nov 7, 2013 5:01 PM by intel_jorge RSS

    Creating a soil moisture sensors using nails and Intel Galileo

    intel_jorge
      Note: This project is posted with permission of the maker at BytesThink.com
      ----------
      Believe or not, I worked in a project with hardware and software created in 8 weeks only. I am talking about Intel Galileo ! The first intel board compatible with Arduino API plus some new and cool features.
      IntelGalileo_fabD_Front_450px
      Before to talk about how to create a very affordable moisture sensor system, let me explain what is Intel Galileo.
      About the Intel Galileo Board – Hardware
      Intel Galileo is a board with new processor called Quark SoC X1000, x86 based, 32 bits, single-core/single thread processor full compliance with ACPI and support RTC. Do you remember pentium ? Yes, chipset instruction compatible but smaller, affordable, ACPI enabled and very simple to use.
      The board contains also contains:
      • ethernet connector
      • pci-e bus (mini PCI)
      • sdcard slot up to 32Gb
      • the regular arduino Uno pins for digital and analog IO’s and an IO expander able to generate 8 PWN channels
      • 1 USB port as host (2.0) and accepts up to 128 devices
      • 1 USB port for programming (2.0)
      • contains 512Mb flash and 216Mb RAM
      • reset button for the processor, reset button for the sketches
      • 10 pin jtag-connector
      • The board can operated in 5V or 3.5V (jumper configurable)
      • 11kb EEPROM available (yeah.. we have a API for this.. click here)
      The schematics are available.
      About the Intel Galileo Board – Software
      Intel Galileo uses Linux as OS and you can boot from flash SD card.  The cool thing on this board you have the Arduino APIs available that means you have the IDE for Linux, Windows and Macs in 32 and 64 bits.
      Only Arduino API experience ? NO!!!! We expanded the experience.. you have new components in the board so new APIs were created like RTC, EEPROM, Web client, etc. Another details is, the servo API is a new methods added that can allow your servos working with 188Hz (for more precision) or 50Hz.
      Considering we are running linux, when you install the IDE all the crosscompilers are installed also (toolchain). It means you can develop using native C/C++ ANSI and using the linux libraries. Arduino IDE on this case will be optional to you because you can develop your code natively and transfer using ftp for instance.
      When Intel Galileo will be releases and how much will cost ? And does it worth ?
      The official date is Nov, 29/2013. The cost will be around US$ 50 to US$60 bucks! I do not have the details yet..
      Intel Galileo has an ethernet connector and a pci-e bus. If you are developing anything with Arduino and requires internet connection you will be forced to buy an expensive wifi/ethernet shield that costs US$ 65 bucks! If you are using Galileo you can use the embedded ethernet connector or you can buy a simple Wifi and Bluetooth module pci-e compatible in amazon for only US$ 8.00.
      The same if you need a video card!
      Another plus is the RTC.. You do not need another shield with RTC.. The same with SD card, you do not need another shield for data logging because you can use the APIs and store your data up to 32Gb sd card using the slot already present.
      These will save a lot of money and you give you a powerful board for your project.
      How do I start ?
      If you are Arduino developer you will realize the IDE is mostly the same excepted by the new APIS added and the option to update the board firmware.
      You can take a look in the “Getting Start Guide” and download the IDE and you can choose Windows, Linux or Mac for IDE.
      This IDE a feature very special that allow us to update the Linux OS in your board (flash or SD card). Take a look in the Start Guide for more information.
      The Soil Moisture System using Nails
      Now you already have an introduction about what is Intel Galileo Board. Let’s talk about this very simple project.
      First of all, I created this project in 2 hours and I used this project as a demo in Maker Fair in Rome/Italy.
      20131002_174008
      People, did not understand (at glance) what two coups with soil and wires were doing over the table in an electronic fair but when they realized they loved (including the intel CEO Brian Krzanich).
      20131003_125743
      The system is based in two sensors. Each sensor is built using galvanized nails connected to an analog port and making a resistor division with another resistor. The sensors also keeps the nail separated in a distance equivalent of 1.5 inches using pieces of foam that I found in the trash. Yes! the system is simple, cheap and you can monitor your soil only using nails. I choose galvanized for obvious reasons.. I do not want to see the nails rusted in a short period of time.
      20131015_091033
      circ2
      This is more than enough to check if soil has water in good amount to the plants or not. Considering was a fair, I build a LED matrix in order to show a happy or sad face. This face has a push button as well.
      If “one eye” is on, means sensor number ONE. Two “eyes” means sensor number TWO. The sensor selection was done using the push button. On this way, you could see “one” or “two” eyes being switched by the users. In the fair, I had two coups each of them with soil but one of them with a little bit of water and each coup connected to a sensor.
      circ0
      circ1
      Then, each sensor is connected to a respective analog port (A0 – sensor 1 and A1 – sensor 2) and periodically the sensor select by the push button and represented by the “eyes” were measured. If is lower then certain amount (see the code) the soil was dry and the plants need water and consequently you could see a “sad” face in the LED matrix. Otherwise, the soil was good and a happy face could see in the LED’s matrix.
      Take a look in the pictures below. The first picture is sensor number 2 (two eyes) and the plant is happy, it means, has water enough in the first coup with soil. The second pictures (one eye) means sensor number 1 and the flower is sad, it means, the plant needs water.
      20131003_125708
      20131003_125729
      Then the sad face, could tweet you asking for water! Of course it was a fair and I did not connect any eletric water valve because would be a mess and I would need to change the soil all the time. Another point is, if you want to create this system in your house, you do not need the LED matrix to draw the flower sad or happy face, you only need the nails connected to your analog ports and let your software make the decision, for example, turn on your sprinklers.
      The code:
      On this post I am adding the code to how the sensors are read and how the LED matrix is changed after reading the push button state. I will add a different post how to tweet using our ethernet connector or wifi pci-e module.
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      100
      101
      102
      103
      104
      105
      106
      107
      108
      109
      110
      111
      112
      113
      114
      115
      116
      117
      118
      119
      120
      121
      122
      123
      124
      125
      126
      127
      128
      129
      130
      131
      132
      133
      134
      135
      136
      137
      138
      139
      140
      141
      142
      143
      144
      145
      146
      147
      148
      149
      150
      151
      152
      153
      154
      155
      156
      157
      158
      159
      160
      161
      162
      163
      164
      165
      166
      167
      168
      169
      170
      171
      172
      173
      174
      175
      176
      177
      178
      179
      180
      181
      182
      183
      184
      185
      186
      187
      188
      189
      190
      191
      192
      193
      194
      195
      196
      197
      198
      199
      200
      201
      202
      203
      204
      205
      206
      207
      208
      209
      210
      211
      212
      213
      214
      215
      216
      </pre>
      // Author: Manoel Carlos Ramon
      #define DEBUG 0
      /* Pins that define if system is ON */
      #define PIN_LEFT_EYE 10
      #define PIN_RIGHT_EYE 11
      /* Sensor switch button */
      #define PIN_SWITCH_SYSTEM 13
      int sensor_value = 0;
      /* Moisture sensor - Analog Input */
      #define ANALOG_MOISTURE_SENSOR_1 A0
      #define ANALOG_MOISTURE_SENSOR_2 A1
      /* The analog reading boundary when soil is good */
      #define SOIL_IS_GOOD 350
      /* some prototypes*/
      void clear();
      int current_system = 0;
      int button_state = 0;
      int last_button_state = 0;
      int array_happy_face[2][4] = {{1, 0, 0, 1}, /* line 1 */
      {0, 1, 1, 0}}; /* line 0 */
      int array_sad_face[2][4] = {{0, 1, 1, 0}, /* line 1 */
      {1, 0, 0, 1}}; /* line 0 */
      /*
      _____________ led 0 - pin 6
      | __________ led 1 = pin 7
      | | _______ led 2 = pin 8
      | | | ______ led 3 = pin 9
      | | | |
      */
      int array_serious_face[2][4] = {{1, 1, 1, 1}, /* line 1 */
      {1, 1, 1, 1}}; /* line 0 */
      /*
      ^ ^ ^ ^
      | | | |__ led 3 = pin 5
      | | |______ led 2 = pin 4
      | |________ led 1 = pin 3
      |____________ led 0 = pin 2
      */
      /* LED MAD */
      /*
      How the pins will work
      pin 0 - Selects the common anode line 0
      pin 1 - Selects the common anode line 1
      */
      int lastButtonState = LOW; // the previous reading from the input pin
      long lastDebounceTime = 0; // the last time the output pin was toggled
      long debounceDelay = 50; // the debounce time; increase if the output flickers
      void setup() {
      if (DEBUG) Serial.begin(9600);
      // put your setup code here, to run once:
      int pin = 0;
      for (pin = 0; pin < 12; pin++)
      {
      pinMode(pin, OUTPUT);
      delay(10);
      }
      // switch button
      pinMode(PIN_SWITCH_SYSTEM, INPUT);
      // clear();
      }
      void clear()
      {
      int pin = 0;
      for (pin = 0; pin < 12; pin++)
      {
      digitalWrite(pin, LOW);
      }
      }
      void drawMatrix(int array[2][4])
      {
      int line = 0;
      int pin = 2;
      int c = 0;
      int level = LOW;
      while (line < 2)
      {
      digitalWrite(line, LOW);
      while (c <= 3)
      {
      level = array[line]1;
      if (DEBUG)
      {
      Serial.print(line);
      Serial.print(",");
      Serial.print(c);
      Serial.print(":");
      Serial.print(pin);
      Serial.print("(");
      Serial.print(level);
      Serial.print("}");
      }
      digitalWrite(pin, level);
      c++;pin++;
      }
      c=0;
      /* if (DEBUG)
      {
      Serial.println("ok");
      Serial.println();
      }*/
      line++;
      delay(10);
      }
      digitalWrite(PIN_LEFT_EYE, HIGH);
      if (current_system != 0) digitalWrite(PIN_RIGHT_EYE, HIGH);
      }
      int checkButtonState()
      {
      // read the state of the switch into a local variable:
      int reading = digitalRead(PIN_SWITCH_SYSTEM);
      // check to see if you just pressed the button
      // (i.e. the input went from LOW to HIGH), and you've waited
      // long enough since the last press to ignore any noise:
      // If the switch changed, due to noise or pressing:
      if (reading != lastButtonState) {
      // reset the debouncing timer
      lastDebounceTime = millis();
      }
      if ((millis() - lastDebounceTime) > debounceDelay) {
      // whatever the reading is at, it's been there for longer
      // than the debounce delay, so take it as the actual current state:
      // if the button state has changed:
      if (reading != button_state) {
      button_state = reading;
      }
      }
      return button_state;
      }
      void loop() {
      digitalWrite(0, LOW);
      digitalWrite(1, LOW);
      // reading the sensor
      switch (current_system)
      {
      case 0:
      sensor_value = analogRead(ANALOG_MOISTURE_SENSOR_1);
      break;
      case 1:
      sensor_value = analogRead(ANALOG_MOISTURE_SENSOR_2);
      break;
      }
      if (DEBUG)
      {
      Serial.print("current_system:");
      Serial.println(current_system);
      Serial.print(" sensor_value:");
      Serial.println(sensor_value);
      }
      if (sensor_value >= SOIL_IS_GOOD)
      {
      drawMatrix(array_happy_face);
      }
      else
      {
      drawMatrix(array_sad_face);
      }
      // reading the button state
      button_state = digitalRead(PIN_SWITCH_SYSTEM);
      checkButtonState();
      if( button_state == HIGH)
      {
      // button pressed
      current_system++;
      if (current_system > 1) current_system = 0;
      }
      if (current_system == 0)
      digitalWrite(PIN_RIGHT_EYE, LOW);
      delay(100);
      }
      <pre>
      Download
      The format is not so good but I am letting the code available to download here as well.
      Next part I will post how to make the plants tweet you when they need water allowing them to communicate with you.
      Note: This project is posted with permission from the maker of this project at: BytesThink.com