Recent Posts

Pages: 1 ... 7 8 [9] 10
You've gone and used integer (truncating) division and lost most of the benefit of averaging!

Change this line:
Code: [Select]

  average = total / numReadings;   // calculate the average (of sensor readings)

Code: [Select]

  float average = 1.0 * total / numReadings;   // calculate the average (of sensor readings)

And lose the declaration of average as an int at top level.

In general its usually much clearer to declare variables when you first use them, not all
at the top of the program or function.  Only make a variable global or static if its value
has to persist between function calls.
there is double ss because i tried lower case
Would a more accurate description be: if(lightsOn != LOW)
That's another way to look at it. Given that lightsOn will hold 0 or 1, they mean the same thing.

To me this sounds like something learned from experience
Yes, but that doesn't mean that it is good practice. In fact, it isn't. There is nothing to be gained from skipping typing a few keystrokes. The compiler will generate the same code, but people reading it will have a harder time deciphering what is meant.
Project Guidance / How to measure home water usag...
Last post by poldim - Today at 01:55 am
I'd like to measure flow going into my house.  The water company uses an electronic communicating meter but they do not have any access setup for consumers to access the data in realtime.

Is there an ultrasonic type sensor that would provide flow date (pulse or something) without having to disassemble the plumbing and install a sensor?

I have found a solder in solution:

Problem is it's 3/4" while my plumbing is 1".
MarkT - I am already using AccelStepper library.

Currently I have slowed down the speed of it for troubleshooting sake. So im not sure that speed is the issue at hand.
Does it still miss steps at lower speed?

Have you lowered the acceleration too - you need to experiment to find the maximum speed and maximum
acceleration your setup (under mechanical load) can actually attain.  You then back off both a bit for reliability.

Not using microsteps will usually increase the probability of mis-stepping - unless the motor is well
damped mechnically.  Resonance is the bane of stepper motors.
I'm a newer arduino user and I'm probably trying to walk before I learn to fully crawl....but its still an extension to my 'crawling' lesson.

I made a TMP36 temperature sensor as described in the basic tutorials but I noticed that it would occasionally get a noisy signal and read +/- 1 degreeF (most of the noise is consistently reading +/- exactly 0.7 degreeF).  I wanted to take my learning the next step and try to learn how to smooth the readings because I would eventually like to graph the data without having to manually remove 'outliers' before plotting them.  Looking online, I found some smoothing examples but I still seem to get similar results whether or not I run the 'smoothed' or just normal 'read the sensor and print temp' sketch.  This last run that I did with the smoothed sketch (below) had noise that was exactly +/- 0.5 degreeF (see attached excel plot).  Is there any way to get rid of that noise though code?  Or, is there a mistake in my sketch that might actually be 'smoothing' the sensor readings?  Again, I'm still not extremely well versed in the language so any helpful steps/explanations are welcome! 

Code: [Select]



  Reads repeatedly from an analog input, calculating a running average
  and printing it to the computer.  Keeps ten readings in an array and
  continually averages them.

  The circuit:
    * Analog sensor (potentiometer will do) attached to analog input 0

  Created 22 April 2007
  By David A. Mellis  <>
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.


// Define the number of samples to keep track of.  The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input.  Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 20;

int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPin = A0;

float degreesC, degreesF; //added to tutorial

void setup() {
  analogReference(EXTERNAL);    //Set AREF to external since using 3.3v: Added to tutorial
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;

void loop() {
  total = total - readings[readIndex];   // subtract the last reading:
  readings[readIndex] = analogRead(inputPin);  // read from the sensor:
  total = total + readings[readIndex];   // add the reading to the total:
  readIndex = readIndex + 1;   // advance to the next position in the array:

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
      readIndex = 0;    // ...wrap around to the beginning:

  average = total / numReadings;   // calculate the average (of sensor readings)

  float avgVoltage = average * 0.00322265625;  //Added to tutorial
  degreesC = (avgVoltage - 0.5) * 100.0; //Added to tutorial
  degreesF = degreesC * (9.0/5.0) + 32.0; //Added to tutorial

  Serial.print("DegreesC: ");  //Added to tutorial
  Serial.print(degreesC);  //Added to tutorial
  Serial.print("DegreesF: "); //Added to tutorial
  Serial.println(degreesF);  //Added to tutorial
Thanks Delta_G & BulldogLowell! I'm marking this thread as [SOLVED]

Microcontrollers / Re: IDE compiling from source
Last post by westfw - Today at 01:50 am
I don't know what to tell you; you're looking for help from a vanishingly small subset of Arduino users: developers who work on the IDE in Eclipse.  Perhaps there are NONE (there used to be an XCode project for compiling the IDE on Macs, but it disappeared in favor of ant a long time ago; I wouldn't expect to find any help at all for compiling the current IDE under XCode.)

It looks like there are a total of two IDE .project files in the source, one in the top level directory that defines processing-head, and one in arduino-core/ that defines arduino-core.  They're pretty empty files, not containing much more info than "this is the arduino-core project"; I don't know how (or if) Eclipse would be incorporating additional info about how to do the actual build.
Project Guidance / Re: Transfer simple server to ...
Last post by zoomkat - Today at 01:49 am
One thing to remember is that once a client browser receives a web page from a server, the server is done and the page now exist on the client browser. There no more interaction with server unless the browser makes another request to the server(s). The downloaded web page can have request/control links for the arduino server. It is probably more practical for the web page loaded in the client browser to interact directly with the arduino supplying status info or performing control functions to the web page loaded in the browser.
Are you wetting the sponge with water ?
Pages: 1 ... 7 8 [9] 10

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131