Show Posts
Pages: [1] 2
1  Using Arduino / Sensors / Re: Finding min and max values from 5 readings of a sensor on: July 15, 2013, 06:00:40 am
Here it is, I hope this is what you wanted.
Code:
int cal_zero_min=1023, cal_zero_max=0;

void setup() {
  Serial.begin(9600);
  pinMode(10, OUTPUT);   //led for UP
  pinMode(11, OUTPUT);   //led for DOWN
  calibrate();
}

void calibrate() {
  for(int i=0; i<20; i++)
  {
    int value = analogRead(A0);
    if(value < cal_zero_min)
      cal_zero_min = value;
    if(value > cal_zero_max)
      cal_zero_max = value;
    delay(50);
  }
}

void loop()
{
  int value;
  for(int i=0; i<5; i++)
    value += analogRead(A0);
  value /= 5;
  if(value >= cal_zero_min && value <= cal_zero_max)
  {
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
  }
  else if( value < cal_zero_min)
  {
    digitalWrite(10, LOW);
    digitalWrite(11, HIGH);
  }
  else
  {
    digitalWrite(10, HIGH);
    digitalWrite(11, LOW);
  }
}

edit: maybe you want to add a dead zone around the neutral position of the sensor, in this case, just add this to the end of the calibrate function:
Code:
int threshold = 20; // adjust this value as you like
if(cal_zero_min - threshold >= 0)
  cal_zero_min = cal_zero_min - threshold;
else
  cal_zero_min = 0;
if(cal_zero_max + threshold <=1023)
  cal_zero_max = cal_zero_max + threshold;
else
  cal_zero_max = 1023;
2  Using Arduino / Sensors / Re: Finding min and max values from 5 readings of a sensor on: July 15, 2013, 05:47:28 am
Oh OK, I think I guess what you want to do, but your code is full of nonsense :p

Please give me a few minutes, I'll give you a proper program smiley-wink
3  Using Arduino / Sensors / Re: Finding min and max values from 5 readings of a sensor on: July 15, 2013, 05:30:55 am
I'm sorry but I don't understand you very well smiley-confuse

Could you post an actual sample of your code, and explain what you want it to do exactly please ?
4  Using Arduino / Sensors / Re: Finding min and max values from 5 readings of a sensor on: July 11, 2013, 06:02:19 pm
Code:
int min=0,max=0;
int readings[5];
for(int index=0; index<5; index++)
{
  readings[index] = analogRead(A0);
  if(readings[index]<min)
    min = readings[index];
  else if(readings[index]>max)
    max = readings[index];
}
You now have your maximum and minimum values in "max" and "min" variables.
5  Using Arduino / Sensors / Re: Arduino + PH probe in Aquarium. Ground Loop. Please help. on: July 11, 2013, 05:21:03 pm
I had it working perfectly for one week, but now the reading is off and jittery again:

(started going "mad" again on 7.Jul)
It now reports 4.10Ph when I know the real value is 6.4 ...

I've to find what's wrong in my environment.
6  Using Arduino / Sensors / Re: Arduino + PH probe in Aquarium. Ground Loop. Please help. on: June 16, 2013, 11:06:54 am
Hi, has the circuit been removed from reply #15, I can't see it ?

I'm currently having the same issue (well, I guess) with Atlas Scientific Ph & Ec probes & stamps.

Readings are fine in calibration solutions but goes all the way when in the tank.

edit: looks like the problem comes from the Ec stamp or probe, if I remove it from the tank the Ph reading is spot on...
7  International / Français / Re: lire une image sur une carte sd d'un ethernet shield on: August 29, 2012, 01:27:10 pm
Pour les sketch il suffit de renommer les .pde en .ino
Pour les libs en general il suffit de trouver le .h principal de la lib et remplacer:
Code:
#include <WProgram.h>
par
Code:
#if (ARDUINO >= 100)
        #include <Arduino.h>
#else
        #include <WProgram.h>
#endif
8  Using Arduino / Storage / Re: SPI conflict between Ethernet/SD card and LCD on: February 15, 2012, 06:39:18 am
Yes you can, there should be a CS (chip select) pin on your SPI devices, connect this pin to ground when you want to use this particular device.
Note that only 1 device should have its CS pin tied to ground at one time.
9  International / Français / Re: Un câble de programmation USB à moins de 3 euros on: September 25, 2011, 08:25:31 am
Elles sont vraiment excellentes ces petites clés noires, et solide en plus:
Hier j'ai par inadvertance relié le +3.3v à la masse et j'ai bien mis 30 secondes avant de me rendre compte de mon erreur  smiley-eek.
Quand j'ai débranché le chip était brulant, je pensais avoir tout cramé, ou bien au moins la sortie +3.3... et bien non, tout fonctionne encore comme il faut !
10  Using Arduino / Installation & Troubleshooting / Re: Not all Arduino [clones] are created equal on: June 08, 2011, 07:29:18 am
Well, the only problem I had was with a "genuine" arduino UNO smd included in an inventor's kit from Sparkfun, from which the bootloader was not properly burned and wouldn't keep its program after power off.
As this was my first Aduino (well, my first introduction to the µC world) I had to figure out and build a parallel programmer to be able to use it.

On the other hand I got plenty of chinese clones from eBay ( duemilanove, Mega2560/ftdi, pro mini, bare ATMEGA328 chips) and they've all worked flawlessly out of the box !

My 2cts...
11  International / Français / Re: Arduino PIN 13 on: June 07, 2011, 11:26:36 am
Exact, mais:
Quote
les pin 0 et 1 cause des problèmes aussi
smiley-wink
12  International / Français / Re: Arduino PIN 13 on: June 07, 2011, 08:55:32 am
Voici les causes de tes problèmes:

- Le pin 13 a déjà une résistance de connectée, pour limiter le courant à la led intégrée sur l'Arduino.
- Les pins 0 et 1 sont déja utilisé car tu utilises Serial !
13  Using Arduino / Microcontrollers / Re: ATmega328 on breadboard (8MHZ internal oscillator) on: May 06, 2011, 01:22:45 am
It's connected to the pin that light a led, I don't know if it will work for you if you're not having the same design.
Do you have a led on your board ?
Does it flash briefly when you upload a sketch from the Arduino IDE ?
14  Using Arduino / Microcontrollers / Re: ATmega328 on breadboard (8MHZ internal oscillator) on: May 05, 2011, 04:15:06 pm
I just found a way to provide auto-reset with a cheap cp2102 usb to serial converter breakboard:



This require a bit of soldering, but at least it's not directly on the chip pins.
Worked for me, less than $5 on ebay, hope this help ...
15  Using Arduino / Displays / Re: Lite-On LTM-8328PKR-04 4x7 LED segments display library for Arduino on: February 18, 2011, 06:48:44 am
My lib doesn't support custom characters but that would be easy to implement as each segment is controlled individually.
I don't know where to get them as I only found one in a junk bag.
Pages: [1] 2