Address

Author Topic: I need to borrow(rent) an arduino aware guru  (Read 2324 times)

Les

  • FamiLAB Member
  • Jr. Member
  • *
  • Posts: 64
    • View Profile
I need to borrow(rent) an arduino aware guru
« on: July 23, 2014, 11:52:28 AM »
HELLLP!
I need to work with someone on some Arduino code and am too dumb to even know who to engage. it isn't too crazy want to read several sensors and a real time clock and store values to an sd card and pump them to a web db.

Time is an issue and I need to have this finished. I am using a TC74a i2c temp sensor, a Phidgets 1133 sound sensor, and ultimately will have a UV sensor. I have a 1307 RTC using the new library and NVR and several options for wifi access.

I even have code for some individual functions but need help combining them all and posting.

Is there anyone with an hour or two to help me out with this project?

Iggy

  • FamiLAB Member
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #1 on: July 23, 2014, 05:30:04 PM »
No a guru but happy to help.  Do you want to share your code here?

Les

  • FamiLAB Member
  • Jr. Member
  • *
  • Posts: 64
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #2 on: July 24, 2014, 12:27:09 AM »
this is the sound level code

/*
   Written by Tihomir Nedev (mail@tnedev.com)
   April 2014
   V 1.0
   Function measuring the db noise level with the 1133_0 Phidgets Sound Sensor
   Available at: http://www.active-robots.com/shop-by-brand/phidgets/sensors/light-sound/sound-sensor.html   
   
*/

#include <math.h>

byte mic_pin = A0; // Sound sensor's signal to pin A0
byte sensitivity = 8; // |From 0 to 10 | Set the sensitivity of the sensor. 10 is the highest sensitivity.

void setup() {
   Serial.begin(9600);
}

void loop() {

 
 
   Serial.println(measure_noise(),4); // Print the db level on the screen
}

double measure_noise()
{
   double analog_step=0.00488; // Voltage step for the ADC. 5 volts / 1024 steps
   int raw ;                   // value to store raw adc input
   double rms=0.0;            // value to store the RMS value for the readings
   double vin_value = 0.0;      // Value to store the voltage input from the microphone. It is the raw converted to voltage
   double output = 0.0 ;      // output in db
   double addition = 0.0;      // value to store addition for the rms
   double matrix[100];         // array to store the elemets for the rms

   for (int i=0;i<100;i++)   // Take 100 readings to calculate RMS value
   {
      raw = analogRead(mic_pin); // Read the sensor
      vin_value = (raw*analog_step); // Convert ADC signal to voltage
      matrix=vin_value;         // Assign the voltage to the matrix
      matrix=matrix*matrix;   // Calculate the square of the value. Pre RMS calculation
      addition += matrix;          // Add all squares to this variable
      delay((10-sensitivity));
   }   
   addition = addition/100.0; // Take the avarage
   rms = sqrt(addition);      // Take the squate root
   output = (1f*(168.01 * log(rms*200)/10)+9.87); // Formula for the db level according to the documentation of the sound sensor
   //first decimal is calibration factor I have added but needs to be verified as a valid method and if so then needs to be attached to a potentiometer so that I can adjust physiclly rather than code
   return output; // return the value

}

This is the temp code

                               

#include "Wire.h"
 
    //wire library
    #define address 0x4f

    #define baudrate 9600
    //baudrate for communication
    byte val = 0;
    void setup()

   
    {
    Wire.begin();
    Serial.begin(baudrate);
    }

    void loop()
    {
   

    int temperature;
    //temperature in a byte
int Temp;
    Wire.beginTransmission(address);
    //start the transmission

    Wire.write(val);

    Wire.requestFrom(address, 1);
    if (Wire.available()) {
    Temp = Wire.read();
    temperature=(Temp * 9.0)/ 5.0 + 26.0;
  Serial.print(" Outside ");   
    Serial.println(temperature);
    }

    else {
    Serial.println("---");
    }
    delay(5000);
    }
but I don'thae any working code at this point to store the values or timestamp them

Iggy

  • FamiLAB Member
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #3 on: July 24, 2014, 09:29:25 AM »
I took the code snipets you posted and combined them together and added basic RTC support. I did my best to avoid premature optimization but I had to make some changes to get the code to compile so I fixed some things that bugged me. This is by no means complete but at this point, you could write the messages to an SD card or better yet... you could just have the Arduino make INSERTs into your MySQL database directly. Either way, to go further we'd need to know what Ethernet and SD devices you intend to use and additionally how you plan on getting the data from the Arduino to the database.


Here's the result:
/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <math.h>
#include "Wire.h"
#include "RTClib.h"

// wire library
#define wire_address 0x4f
#define wire_val 0

//baudrate for communication
#define baudrate 9600

// Sound configuration
#define mic_pin A0
#define mic_sensitivity 8

// Real Time Clock
RTC_DS1307 RTC;

void setup()
{
  Wire.begin();
  Serial.begin(baudrate);
  RTC.begin();
}

void loop()
{
  Serial.println(get_time_string());
  Serial.println(measure_noise(),4);    // Print the db level on the screen
  Serial.println(measure_temp());
 
  delay(3000);
}

String get_time_string()
{
  String dateTimeString = "07-24-2014 09:21:00";
  if (RTC.isrunning())
  {
    DateTime now = RTC.now();
    dateTimeString = now.month() + String("-") + now.day() + String("-") + now.year() + " " + now.hour() + ":" + now.minute() + ":" + now.second();
  }
 
  return dateTimeString;
}

double measure_noise()
{
  double analog_step = 0.00488;        // Voltage step for the ADC. 5 volts / 1024 steps
  int raw;                             // value to store raw adc input
  double rms = 0.0;                    // value to store the RMS value for the readings
  double vin_value = 0.0;              // Value to store the voltage input from the microphone. It is the raw converted to voltage
  double addition = 0.0;               // value to store addition for the rms
  double matrix[100];                  // array to store the elements for the rms
 
  for (int i = 0; i < 100; i++)        // Take 100 readings to calculate RMS value
  {
    raw = analogRead(mic_pin);         // Read the sensor
    vin_value = (raw * analog_step);   // Convert ADC signal to voltage
    matrix = vin_value;             // Assign the voltage to the matrix
    matrix = matrix * matrix; // Calculate the square of the value. Pre RMS calculation
    addition += matrix;             // Add all squares to this variable
    delay(10 - mic_sensitivity);
  }
  addition = addition / 100.0;          // Take the average
  rms = sqrt(addition);                 // Take the square root
 
  // Formula for the db level according to the documentation of the sound sensor
  // first decimal is calibration factor I have added but needs to be verified as a valid method and if so then needs to be
  // attached to a potentiometer so that I can adjust physiclly rather than code
  return (1.0f * (168.01 * log(rms*200) / 10) + 9.87);
}

int measure_temp()
{
  int temperature = 0; //temperature in a byte
 
  Wire.beginTransmission(wire_address); //start the transmission
  Wire.write(wire_val);
  Wire.requestFrom(wire_address, 1);
  if (Wire.available())
  {
    int Temp = Wire.read();
    temperature = (Temp * 9.0) / 5.0 + 26.0;
  }
 
  return temperature;
}

Les

  • FamiLAB Member
  • Jr. Member
  • *
  • Posts: 64
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #4 on: July 24, 2014, 09:51:38 AM »
Already progress. I got a compile error first time around but noticed that the associated with the matrix was absent. restoring it allowed it to compile. I am having a bit of an issue with the temp not reading but suspect a wire issue and will explore that right away.


I have a couple of options on wifi. I have Electric Imps http://electricimp.com/ and I have a Spark https://www.spark.io/ and am willing to consider any better option you might suggest. Both of those devices are a cloud server intermediary.


I have one Yun and will get the other two if that is the best answer. I could go with any number of wifi shields if you have something you would suggest.


I will create net access via cellular hotspot. Ultimately at one test site I will be deploying 3 units like this one and another system to measure current usage.


Essentially we are putting them in adjacent hotel rooms and comparing results and monitoring the current usage for each AC unit.




Iggy

  • FamiLAB Member
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #5 on: July 24, 2014, 10:31:40 AM »
The code I posted above compiles in Arduino 1.0.5-r2 targeting a MEGA 2560 without modification. I forgot to mention that you have to manually install the RTClib (I used the Adafruit version but the JeeLabs version should work too). I wasn't able to upload and test though so maybe a bug slipped by?

EDIT - Looks like the forum software chopped off the square brackets off of the matrix variable. I was wondering how your sample code worked :)


For some reason, I assumed you'd be using an Ethernet (or WiFi) Shield for an Arduino. I should've confirmed before asking for code because after I had a look at the two solutions you linked above, I think you should go another way. Instead of using an Arduino, consider just using the Imp like in this Instructable; looks like you have a total of 9 pins to use for sensors. One big problem with this approach is that it requires a constant internet connection which might be costly with your cellphone hotspot solution. The obvious solution is to queue the measurements on the sampling device and send them to a remote server in bursts but this add a layer of complexity in that the Arduino must somehow keep track of the measurements that have been successfully transmitted. Before solving this problem in code, it makes sense to ask "Why can't you just collect the SD cards manually at some interval and then process the data?"



« Last Edit: July 24, 2014, 10:36:39 AM by Iggy »

Les

  • FamiLAB Member
  • Jr. Member
  • *
  • Posts: 64
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #6 on: July 24, 2014, 11:39:40 AM »
I can and certainly will for the moment. This device will replace my current solution which is a temp datalogger and a soundlevel datalogger which requires new batteries every 3 days and will only hold 2.5 days of data in any case. I often have to go to site 3-4 times in a test period to download and service and this will allow me to place and ignore for hopefuly up to a week but the downside is that it is costly for the hotel to sacrifice the rooms and if something goes wrong and I don't know for a week it is a real bummer.

If I can also monitor it from the web it is best and I suppose I can even program an alarm to my cell alerting me to the fact that it is no longer receiving data.

Taking it piece by piece my current issue is getting the RTC working (not the case at the moment). That said, I have made more progress since you responded thanI hve in the last week.

Iggy

  • FamiLAB Member
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #7 on: July 24, 2014, 12:00:20 PM »
Which RTC device and library are you using?  The code I wrote above was a quick mockup based on the AdaFruit (first Google hit for me) sample and library. What's not working?

I have production code based on the Arduino time library. I can share that code if you're using the library from here http://playground.arduino.cc/Code/Time


Les

  • FamiLAB Member
  • Jr. Member
  • *
  • Posts: 64
    • View Profile
Re: I need to borrow(rent) an arduino aware guru
« Reply #8 on: July 24, 2014, 01:44:27 PM »

I have been using 1.5.5 because of the possibility of using a Due or Yun. the rtc is http://www.oddwires.com/ds1307-real-time-clock-module-for-arduino-with-i2c-interface/ and calls for the ds1307new library