terça-feira, 11 de novembro de 2014

Octopus Soil Moisture Sensor Brick


An important variable to be monitored and controlled in your garden is the soil moisture level. I decided to use the Octopus Soil Moisture Sensor Brick, that can be found at http://www.elecfreaks.com/ for about U$ 5,00.


Octopus Soil Moisture Sensor Brick - Image Source www.elecfreaks.com

I have a very strict control over soil moisture in the environment of the test, and after 36 hours of usage, the data acquired was not reflecting reality, as shown at the graphic below:


Only five days after installed the data dropped to 0, and the sensor was completly wasted:



The problem was related to the sensor waste:



I do not recomend the usage of this sensor in continuous mode. A very good article (in Portuguese), that show how you can build your own soil moisture sensor, can be found at https://ncaio.wordpress.com/

segunda-feira, 10 de novembro de 2014

Creating a digital filter - Smoothing analog input values

If you wanna eliminate noise from your analog inputs, or have smooth variation in reads, you can implement a digital filter following this example:

 int ldrSensor = 2;  
 float rawValue = 0;  
 float withFilter = 0;  
 float variation = 0;  
 float smoothCoeficient = 0.1;  
 void setup()  
 {  
  Serial.begin(9600);  
  rawValue = analogRead(ldrSensor);  
  withFilter = rawValue;  
 }  
 void loop()  
 {  
  rawValue = analogRead(ldrSensor);  
  variation = rawValue - withFilter ;  
  withFilter = withFilter + variation * smoothCoeficient ;  
  Serial.print(int(rawValue));  
  Serial.print(" ");  
  Serial.println(int(withFilter));  
 delay(50);  
 }  

If you set lower smoothCoeficient value, slower will be the changes in your filtered values.

Data output example:

 656 656  
 656 656  
 657 656  
 657 656  
 656 656  
 657 656  
 657 656  
 656 656  
 656 656  
 657 656  
 656 656  
 657 656  
 656 656  
 657 656  

When you have a smoothCoeficient of 0.1, means that only 10% of the last variation will be inserted into filtered value. You may need to change this value to fit your needs.

Making your arduino sketch support multiple languages

So you have an LCD attached to your arduino, and want to support multiple languages?

Let me show you how i solved this problem:

Inside your library folder, create a folder called languages. Inside this folder, save the file below as languages.h

 typedef enum Language  
 {  
    pt_br,  
    en_en  
 };  
 typedef enum Sentences  
 {  
    HELLO,  
    GOODBYE  
 };  

And the following code as languages.c

 char* pt_br[] = {"Olá","Tchau"};  
 char* en_en[] = {"Hello","Goodbye"};  
 char** languages[2] = {pt_br,en_en};  

This code shows you how to use the library


 #include <languages.h>  
 Language current_language;  
 extern char** languages[2];  
 void setup()   
 {  
  Serial.begin(9600);  
  current_language=pt_br; //pt_br, en_en  
 }  
 void loop()   
 {  
  Serial.println(languages[current_language][HELLO]);  
  Serial.println(languages[current_language][GOODBYE]);  
  if (current_language == pt_br)  
  {  
   current_language = en_en;  
  }  
  else  
  {  
   current_language = pt_br;  
  }  
  delay(1000);  
 }  

Let me know if you have suggestions on how to improve this.