Show Posts
Pages: 1 ... 12 13 [14]
196  Using Arduino / Programming Questions / Re: Switch case: always default case on: December 21, 2011, 08:18:30 pm
 if (digitalRead(button2)==LOW) {
    LEDcase==2;
      whichLED(LEDcase);
  }

should be

 if (digitalRead(button2)==LOW) {
    LEDcase=2;
      whichLED(LEDcase);
  }

== checks for a value

= assigns a value
197  Using Arduino / Motors, Mechanics, and Power / Re: How to stop a stepper motor from holding/locking? on: December 21, 2011, 07:58:10 pm
@wortelsoft I'm using an h bridge made of discrete transistors that I ripped out of some remote control car a while ago, obviously no enable pin there smiley-sad

@MarkT Version 0.4 of the standard stepper library that comes with the arduino IDE.

After googling I found that the AFmotor library has a release() function which seems to do what I need, but I don't know how I should hook up my stepper motor, since AFmotor is supposed to be used with the motor shield. Currently the stepper is connected with all four wires going to seperate pins.
198  Using Arduino / Motors, Mechanics, and Power / How to stop a stepper motor from holding/locking? on: December 21, 2011, 12:43:06 am
Is there anyway I can stop powering my stepper motors after they're done doing what they need to do? Seeing as I don't have a proper power supply for them, they tend to get hot after just a few minutes, even though they're rarely in use. I don't need them to lock when not in use, so is there anyway to turn them off with the stepper library?
199  Using Arduino / Sensors / Re: Strange sensor interference? on: August 18, 2011, 04:45:13 am

The Arduino only hjas one ADC which is multiplexed. If readings differ too much they interfere.

solutions:
* do double readings and ignore the first (see below)
* do multiple readings and average them (exercise for you smiley-wink
* do a running average  e.g. temp = (2 * analogRead() + 14 *temp) / 16;
* take care there is enough time between the readings  (move reading of light after Serial prints (temp)

Code:
int tempPin = A5;//temp sensor
int lightPin = A0;//photoresistor, hooked up between A0 and ground - pulled high

int light = 0;
int temp = 0;

void setup() {
  Serial.begin(300);
 
  pinMode(lightPin, INPUT);
  pinMode(tempPin, INPUT);
 
  digitalWrite(lightPin, HIGH);// pull photoresistor high
}

void loop()
{
  // read sensors
  analogRead(tempPin);
  temp = analogRead(tempPin);
 
  analogRead(lightPin);
  light = analogRead(lightPin);
 
  //send data to computer for graphing
  Serial.print("t");
  Serial.print(temp, DEC);
 
  Serial.print("l");
  Serial.print(light, DEC);
 
  delay(100);
}

Thanks, the code works perfectly but I'm still not really understanding the problem. This is how I understand it: I tell the arduino to read a pin, it sends the voltage through the ADC and stores the number it gets in the ram, then it clears the ADC and switches to the next pin...

So how could there be interference in the values?

Also, "take care there is enough time between the readings  (move reading of light after Serial prints (temp)"

I tried that and it worked aswell, yet if I use my original code with a very generous 100ms delay(far more than serial printing) between reading the temp pin and the light pin I get the same interference.
200  Using Arduino / Sensors / Strange sensor interference? on: August 18, 2011, 01:37:07 am
Hi, I have a lm19 temperature sensor and a photo resistor hooked up to analog inputs of my arduino and I'm getting some very strange readings. I dont think my code is the problem but here it is just in case:
Code:
int tempPin = A5;//temp sensor
int lightPin = A0;//photoresistor, hooked up between A0 and ground - pulled high

int light = 0;
int temp = 0;

void setup() {
  Serial.begin(300);
 
  pinMode(lightPin, INPUT);
  pinMode(tempPin, INPUT);
 
  digitalWrite(lightPin, HIGH);// pull photoresistor high
}

void loop() {
  // read sensors
  temp = analogRead(tempPin);
  light = analogRead(lightPin);
 
  //send data to computer for graphing
  Serial.print("t");
  Serial.print(temp, DEC);
 
  Serial.print("l");
  Serial.print(light, DEC);
 
  delay(100);
}

So the problem is that as the light level drops below the temperature level, I get erratic readings from the temperature sensor. I posted a picture of one of the readings I graphed, where green is light and red is temperature. The only thing I can think of is adding a capacitor between ground and the temp. sensor Vout pin but really I'd just like to know what's causing this interference.

Thanks.



Uploaded with ImageShack.us

201  Using Arduino / Microcontrollers / Found a PIC16f716... how to use? on: August 13, 2011, 01:09:31 am
So I found a PIC16f716 in an old lipo battery charger (i think it controlled the blinking charge LED), and I was wondering what software and hardware I need to hook it up to my computer and program it, or maybe if I could program it from my arduino? I have a serial port and USB ports on my computer, so could someone direct to some links? thanks.
202  Using Arduino / Programming Questions / Re: insert a carraige return? on: July 29, 2011, 10:02:14 pm
thanks for the quick reply. and even more for the refference. Will use it again!
203  Using Arduino / Programming Questions / insert a carraige return? on: July 29, 2011, 09:36:53 pm
hi, I'm pretty new to the arduino language and the current program I'm working on doesnt make much sense to me. First of all heres the code(mostly copied from other people):
Code:

//Add the SdFat Libraries
#include <SdFat.h>
#include <SdFatUtil.h>
#include <ctype.h>

//Create the variables to be used by SdFat Library
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

char name[] = "10.txt";     //Create an array that contains the name of our file.
char contents[256];           //This will be a data buffer for writing contents to the file.
char in_char=0;
int index=0;                  //Index will keep track of our position within the contents buffer.
int temp;
int data_size;
int in;

void setup(void)

    Serial.begin(9600);        //Start a serial connection.
    pinMode(10, OUTPUT);       //Pin 10 must be set as an output for the SD communication to work.
    card.init();               //Initialize the SD card and configure the I/O pins.
    volume.init(card);         //Initialize a volume on the SD card.
    root.openRoot(volume);     //Open the root directory in the volume.
}
void loop(void){
    temp = (1.8663 - (5.0 * analogRead(A5) / 1024.0)) / 0.01169; 
    file.open(root, name, O_CREAT | O_APPEND | O_WRITE);    //Open or create the file 'name' in 'root' for writing to the end of the file.
    sprintf(contents, "Temp:,%0d", temp);
    file.print(contents);    //Write the 'contents' array to the end of the file.
    file.close();            //Close the file.
   
delay(1000);
}


Basically I'm reading a temp. sensor and (if I understand properly) sending the data to a buffer and then to my sd card with the help of the sdFat library. So the problem is that I want a carraige return after each reading but I dont know how to accomplish that. Currently when I read off the card I get this: Temp:,24Temp:,25Temp:,24 but i want to get:

Temp:,24
Temp:,25
Temp:,24
Do any of you know how to do this?
Pages: 1 ... 12 13 [14]