My first project

I am a complete Noob and thanks a lot of reading on this forum I have just finished my first Adrdiuno project :slight_smile:

I am using a 26PCBFA6D pressure sensor to test the depth of a river and then post the value to a mysql db on my website using a wavecom GPRS Modem and php script.

As the whole unit will be installed in a remote location I am powering the arduino with a 12v lead acid battery connected to a 12w solar panel. Thanks to the nightingale code I am able to put the arduino in and out of sleep mode for about 30 minutes until I read the sensor and post the data.

Thanks again for all the help.

Stuart

#include <avr/sleep.h>
#include <avr/wdt.h>
#include <SoftwareSerial.h>
#ifndef cbi                                            //copied from nightingale:
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))    
#endif                                                 
#ifndef sbi                                           
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))     
#endif                                                 
volatile boolean f_wdt=1;              
int count = 191;        //Set count high so dotest on startup
int pressureSignal = 0; // Pressure signal pin ANALOG-0
int val1 = 0;           // Pressure value 1
int val2 = 0;           // Pressure value 2 
int val3 = 0;           // Pressure value 3
float pressureValue = 0;   // Average Pressure
int relayPin = 13;       // 5v relay connected to DIGITAL-13

void setup()                    // copied from nightingale:
{     
  Serial.begin(9600);  
  
  cbi( SMCR,SE );      // sleep enable, power down mode
  cbi( SMCR,SM0 );     // power down mode
  sbi( SMCR,SM1 );     // power down mode
  cbi( SMCR,SM2 );     // power down mode
  setup_watchdog(9);
}

void loop()                    
{
  if (f_wdt==1) {      //copied from nightingale:
   f_wdt=0; 
  if (count > 190) {   //When count gets to 191 do pressure test
  dotest();
}
  else {
  count++;              //count +1
  }
  } 
  
    system_sleep();
  
}

void dotest() {
  Serial.begin(9600);
  digitalWrite(relayPin, HIGH);   // Sets the relay on, switches on modem and pressure sensor
  delay(12000);
  val1 = 0;
  val2 = 0;
  val3 = 0;
  pressureValue = 0;
  pinMode(pressureSignal, INPUT);      // Sets Analog pin to input
  delay(900);
  val1 = analogRead(pressureSignal);   // Get value 1
  delay(800);
  val2 = analogRead(pressureSignal);   // Get value 2 
  delay(700);
  val3 = analogRead(pressureSignal);   // Get value 3 
  delay(500);
  pressureValue = ((val1+val2+val3)/3);    // Get average value  
  Serial.print("AT+cpin=####\r\n");      // Input SIM pin   
  delay(3000); 
  Serial.print("at+wipcfg=1\r\n");    //start IP stack
  delay(1000); 
  Serial.print("at+wipbr=1,6\r\n");    //open GPRS bearer
  delay(1000); 
  Serial.print("at+wipbr=2,6,11,\"internet\"\r\n");      //set APN name of GPRS bearer
  delay(1000); 
  Serial.print("at+wipbr=4,6,0\r\n");     //start GPRS bearer
  delay(5000); 
  Serial.print("at+wipcreate=5,1,\"yourwebsite.com\",80,\"user\",\"password\"\r\n");  //connect to remote HTTP proxy server port 80 with authentication and some header fields
  delay(5000); 
  Serial.print("at+wipopt=5,1,1,51\r\n");     //get size of the TCP send buffer size
  delay(1000); 
  Serial.print("at+wipopt=5,1,2,53,6\r\n");     //set maximum number of redirects
  delay(1000);  
  Serial.print("at+wipfile=5,1,1,\"http://yourwebsite.com/insertscript.php?data=");
  Serial.print(pressureValue);
  Serial.print("\"\r\n");   //HTTP GET method(not really what I should be using but it works:-) )
  delay(5000);
  digitalWrite(relayPin, LOW);   // sets the relay off
  count = 0;                     //set count to 0 to restart sleep loop

} 


void system_sleep() {                  //copied from nightingale:
  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();
  sleep_mode();                        // System sleeps here
    sleep_disable();                     // System continues execution here when watchdog timed out 
    sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
}

void setup_watchdog(int ii) {          //copied from nightingale:

  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;
  Serial.println(ww);
  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCSR = bb;
  WDTCSR |= _BV(WDIE);
}

ISR(WDT_vect) {
  f_wdt=1;  // set global flag
}

Sounds interesting, got any pictures of the setup?

No pics unfortunately :-[

sounds nice, which module of wavecom are you choose,Q2686?

I used a Q2406 with Wipsoft activated.

Very interesting. It would be nice to see the website page, too.

http://www.cwwc.co.za/palmiettest1.php

We have done some maths server side to show levels relevant to weir markings.

Nice!

Especially interesting is the use of uP sleep mode to save battery IMHO.

I am trying to do something similar but on my Q2406's all the AT+WIPXXX commands just return a ERROR message.

How did you activate the WIPSOFT command set?

Thanks,

Augusto