Show Posts
|
|
Pages: [1] 2
|
|
1
|
Using Arduino / Sensors / Re: Can't read Atlas Scientific colour detector
|
on: February 04, 2013, 06:42:29 pm
|
|
did a quick test with the default code for serial communication and tested against a black surface and got a reading of (0,0,0) so sensor seems to be responding correctly... but then entering the code above I dont receive any 0's
|
|
|
|
|
3
|
Using Arduino / Sensors / Re: Can't read Atlas Scientific colour detector
|
on: February 03, 2013, 04:48:06 pm
|
Thanks this give me this... #include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup() { Serial.begin(38400); Serial.println("Start color sensor");
// set the data rate for the NewSoftSerial port mySerial.begin(38400); mySerial.print('C'); }
void loop() { if (mySerial.available()) { unsigned char c = mySerial.read(); // <------------ added unsigned char Serial.print("<"); Serial.print(c, DEC); Serial.print(">"); if (c == ',') Serial.println(); // split the R G and B if (c == 13) Serial.println(); // extra newline
} delay(1000); }
I also added a delay just to see what I was getting from the sensor in one loop. the resulting data is somelike like: <51> 10 seconds of running the serial monitor, i get something like: b,Start color sensor <49><56><44> <177><147><148><152><156><134><49>
|
|
|
|
|
4
|
Using Arduino / Sensors / Re: Can't read Atlas Scientific colour detector
|
on: February 03, 2013, 04:31:28 pm
|
I just updated your code #include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup() { Serial.begin(38400); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< changed to 38400 Serial.println("Start color sensor");
// set the data rate for the NewSoftSerial port mySerial.begin(38400); mySerial.print('C'); }
void loop() { if (mySerial.available()) { char c = mySerial.read(); Serial.print("<"); Serial.print(c, DEC); Serial.print(">"); if (c == ',') Serial.println(); // split the R G and B if (c == 13) Serial.println(); // extra newline } } That gives me this b,¡¡¤%¥¡%%%Start color sensor <52><51><44> <-77><-108><-106><-103><-102><-122><50><53><44> <-79><-107><-106><-104><-103><-122><50><53><44> <-78><-111><-108><-103><-104><-122><50><53><44> <-78><-103><-106><-103><-104><-122><50><49><44> <-79><-104><-108><-104><-100><-122><50><52><44> <-79><-103><-106><-102><-103><-122><52><51><44> <-77><-111><-106><-103><-102><-122><52><48><44> <-78><-104><-106><-103><-103><-122><49><48><44> <-79><-104><-106><-102><-103><-122><51><50><44> <-78><-104><-106><-103><-103><-122>
|
|
|
|
|
6
|
Using Arduino / Sensors / Re: Can't read Atlas Scientific colour detector
|
on: February 03, 2013, 04:00:36 pm
|
ah yes, that makes sense then sensor runs at 38400, changing that shows this b,Start color sensor 495253-84494853-84494857-115495250-84494850-84494854-115495253-84494853-844948-75-115495253-84494853-84494853-115545344 -76-105-108-103-104-122544944 -108-99-106-102-102-122
|
|
|
|
|
10
|
Using Arduino / Sensors / Re: Can't read Atlas Scientific colour detector
|
on: February 03, 2013, 12:44:19 pm
|
I bought one of these sensors a week ago and struggling to get it working properly. The code they provided did not work. Ive managed to get a reading through the serial, digital 0, 1 pins and then entering this code: void setup() {} void loop(){}
opening the serial reader and entering "C" to start taking a reading at 620ms. you should get something like this. 14,8,414,14,1410,10,1413,18,18 What I would like to know is how can you use soft serial and strings to be able to take a reading that arduino can then do something with.
|
|
|
|
|
11
|
Forum 2005-2010 (read only) / Troubleshooting / Re: led fade from 0 to 225 then hold at 255
|
on: December 05, 2010, 06:31:20 pm
|
intially the led would be set at 0 when pressed and held it would go from 0 to 255 and once there stay at 255 when pressed again it would go from 255 to 0 but also what I would like it to do is, say the button was pressed and it started to brighten, if the button was pressed again before the led got to 255 it would take the current value and got back down to 0. The project Im looking to do is control a series of leds with in IR sensor, when the user comes into range of the sensor this triggers the leds to fade in, if the were to stay they would see all the leds come on. if they were to walk away the leds would fade out. A quick swipe with the hand would start to activate the leds but then they would fade out again quickly Hope this helps Ahh ill try use switches from now on, pretty new to all this Yeah further on in the book it talks about debouncing I thought it would be better to leave it out for now to make it more simple for myself : 
|
|
|
|
|
12
|
Forum 2005-2010 (read only) / Troubleshooting / led fade from 0 to 225 then hold at 255
|
on: December 05, 2010, 06:06:54 pm
|
Hi, Im trying to create a bit of code that when a button is pressed its fades in a led to full brightness and then the led stays on. Ive got the getting started with arduino book and adapted a bit of code that will turn an led on and off with a button press to now fade in, but the loop when it gets to the 255 value just resets to 0 and fades in again. Ive been looking at breaks and trying to include them in my code but had no luck so far. this is the bit of code i have so far const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 9; // the number of the LED pin
// variables will change: int buttonState = 0; // variable for reading the pushbutton status int fade = 0;
void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }
void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { for (fade = 0; fade <= 255; fade++){ analogWrite(ledPin, fade); delay(15); } } else { // turn LED off: for (fade = 255; fade > 0; fade--){ analogWrite(ledPin, fade); delay(15); } } }
Thanks in advance, Phil
|
|
|
|
|
13
|
Forum 2005-2010 (read only) / Interfacing / Re: taking two sensor readings over time
|
on: December 27, 2010, 03:54:04 pm
|
Thanks nightfigther, got it working ;D Code below: int analogInPin = A0; // define IR Sensor int analogOutPin = 9; // define LED int oldValue; int currentValue;
void setup() { oldValue = 0; //Set the values to be 0 when we first start currentValue = 0; Serial.begin(9600);
}
void loop() { oldValue = currentValue; //Every iteration the Arduino runs through, //assign oldValue to be what the previous currentValue is. currentValue = analogRead(analogInPin); //assign currentValue to the what //the function returns
//do our logic tests if((oldValue < 50) && (currentValue >= 400)) { digitalWrite(analogOutPin, HIGH); delay(1000); } else { digitalWrite(analogOutPin, LOW); } // print the results to the serial monitor: Serial.print("sensor = " ); Serial.println(currentValue); // wait 10 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(1000);
} //End Loop();
|
|
|
|
|