Show Posts
Pages: [1] 2 3
1  Using Arduino / Sensors / Re: Which capacitor to use to stabilise capacitive sensing circuit on: August 20, 2014, 03:40:01 am
Thanks so much.

I am going to keep trying with this technique a little longer as I would really like the piece to be touch sensitive all over.

A
2  Using Arduino / Sensors / Which capacitor to use to stabilise capacitive sensing circuit on: August 19, 2014, 05:19:00 pm
Hi all,

I am building an interactive sculpture which uses capacitive sensing to take readings and control various outputs like sound and lights.

I have followed this topic on arduino to create my circuit: http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense

I have found that it is difficult for me to get repeatable results and results that are stable enough for me to use for this purpose. The sensor pad needs to be very large and I think this is why I am encountering issues.

I have noticed that there are still a few things which I have not tried yet to improve the stability of the sensor. So before I decide to go down a different route I would like to try them but I am unclear of the following things which are quoted from the link above:

'Research has shown that a small capacitor (100 pF) or so from sensor pin to ground improves stability and repeatability.'

and

'Adding small capacitor (20 - 400 pF) in parallel with the body capacitance, is highly desirable too, as it stabilizes the sensed readings.'

I was just wondering if anyone may be able to help me out with what type of capacitor I should use to do this? There are so many different types ceramic, electrolyte etc...

Please would someone be able to email me a link to the type of capacitors I should use to stabilise the circuit?

I would be very grateful.

Many thanks,

A
3  Using Arduino / LEDs and Multiplexing / Help with sourcing RGB LED Tape on: July 20, 2014, 06:06:41 am
Dear all,

I am working on an interactive sculpture at the moment. It uses RGB LEDs and ultrasonic sensors, to allow people to colour mix as they move around the piece.

Because of the colour mixing side of the interactivity, the bog standard RGB LEDs from ebay or Amazon that I have been using previously aren't quite good enough to get really evenly mixed colours, as the component green, red and blue LEDs are unevenly matched.

I have done a dirty hack with a friend to correct the LEDs in my programming but I was wondering if anyone had any knowledge in RGB LEDS and would know who would be good to buy from? In terms of getting a good quality led tape that is not too expensive. Aside from me just ordering loads from the internet to see what they are like - I thought I would ask here first.

Spec required:

5 metres (possibly more but lets start with this)
RGB LED
300 LEDS
Non-waterproof
Black PCB or White PCB
does not need to be individually addressable but if you think that the LED quality may be better because of this, then could get this type.

Also is there a way to diffuse the tape without using the plastic covering? The sculpture requires the LEDs be able to bend around come tight angles so the plastic sheeting is no good, any ideas?

Any suggestions, companies that people have used before that they think are good.

I look forward to hearing from you,

Aphra.
4  Using Arduino / Programming Questions / Re: Fading LEDs in and out on a sequence on: October 11, 2013, 09:25:14 am
Hi all,

I have been working on this code below in reference to my queries above I think if I tell the arduino to fade in and out pin 5 and delay then fade in/out pin 6 and use a longer delay then this should produce the desired affect which I can test with the sculpture itself to get the desired delay and brightness.

However I am getting an error message when i load this code up

see code
Code:
#define triangle 5
#define square 6

int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  {
  // declare pin 5 to be an output:
  pinMode(triangle, OUTPUT);
  pinMode(square, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop()  {
  // set the brightness of pin 5:
  analogWrite(triangle, brightness);   

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
  // wait for 30 milliseconds to see the dimming effect   
  delay(30);                           


 // set the brightness of pin 6:
  analogWrite(square, brightness);   

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }     
  // wait for 100 milliseconds to see the dimming effect   
  delay(100); 
  } 
}

error message:

In file included from /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:6,
                 from sketch_oct11b.ino:12:
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/math.h:323: error: expected unqualified-id before numeric constant

Does anyone know what this means?

Thanks
5  Using Arduino / Programming Questions / Fading LEDs in and out on a sequence on: October 11, 2013, 09:06:01 am
Hi there,

I have made an interactive light sculpture which can be seen here: http://www.aphrashemza.com/composition-x.html. I am installing it at an event later today and have just realised that for this event running the sculpture through a sensor will not work as it is going to be too busy, so I need to alter my code so that the LEDs just fade in and out on a loop instead of taking readings from the sensor and fading in/out accordingly.

My original code is as follows:

Code:
float maxValue = 200;//200 refers to led max brightness turn down less bright
float current5 = 0;
float current6 = 0;

int readDistance()
{
  long pulse = pulseIn(4, HIGH);
  return pulse / 58;
}


void setup()
{
  analogWrite(5, current5);
  analogWrite(6, current6);
     
  Serial.begin(9600);          // start serial communication at 9600bps
}



void loop()
{
  float reading = readDistance();
 
  if (reading < 700)
  {
    if (reading > 150)
    {
      current5 = 0.4 * current5;
      current6 = 0.4 * current6;
     
      // turn both off
      analogWrite(5, current5);
      analogWrite(6, current6);
    }
    else if (reading > 75)
    {
      // turn 6 off
      current6 = 0.4 * current6;
      analogWrite(6, current6);
   
      // dim 5
      int brightness = map(reading, 75, 150, maxValue, 0);
      current5 = 0.7 * current5 + 0.3 * brightness;
      analogWrite(5, current5);
    }
    else
    {
      // turn 5 on
      current5 = 0.7 * current5 + 0.3 * maxValue;
      analogWrite(5, current5);
     
      // dim 6
      int brightness = map(reading, 0, 75, maxValue, 0);
      current6 = 0.7 * current6 + 0.3 * brightness;
      analogWrite(6, current6);
    }
  }
   
  Serial.println(reading);
}



I would like my code to now do the following:

-define a maxvalue for the brightest stage the leds can go
-set both leds to 0 at beggining

- Start with pin 5 and fade up to maxvalue
- Then when pin 5 is at maximun brightness to keep that on full and the fade in pin 6 to maxvalue
- When both pin 5 and 6 are at maximum brightness, fade out pin 6 to min value
- When that is at value 0 fade out pin 5 to value 0
- repeat sequence forever.

This is what I have been working on but it is not quite right! I though if I can do in two sections and put a delay on one then this would create the above sketch.

For example tell 5 to fade in and out and tell 6 at the same time but delay until it starts halfway through 5's sequence.

Code:
/*
 Fade
 
 This example shows how to fade an LED on pin 9
 using the analogWrite() function.
 
 This example code is in the public domain.
 */
#define triangle 5
#define square 6

int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  {
  // declare pin 5 to be an output:
  pinMode(triangle, OUTPUT);
  pinMode(square, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop()  {
  // set the brightness of pin 5:
  analogWrite(triangle, brightness);   

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
  // wait for 30 milliseconds to see the dimming effect   
  delay(30);                           
 
 // set the brightness of pin 6:
  analogWrite(square, brightness);   

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }     
  // wait for 30 milliseconds to see the dimming effect   
  delay(100);                           
}

If anyone can help I would really appreciate it.

Thanks
6  Using Arduino / Sensors / Circuit for ultra sonic sensor on: September 08, 2013, 03:04:19 pm
Hi there,

I am using an ultra sonic range finder which can be found here: http://www.coolcomponents.co.uk/catalog/ultrasonic-range-finder-p-595.html
with my arduino using one of my digital pins to take the readings and then using them to power to led lighting strips.

I had a friend helping me with this project previously who is now out of the country and I have stupidly forgotten to write down which port of the sensor should be connected to the digital pin of my arduino and have got stupidly stuck on this minor issue, which should be easy to work out!

The schemematic can be found here: http://www.maxbotix.com/documents/XL-MaxSonar-EZ_Datasheet.pdf if someone would be able to let me know which in communicates via serial digital that would be of great help, as I cannot see for looking!

Many thanks.
7  Using Arduino / Programming Questions / Re: Stuck on stepper code on: August 04, 2013, 11:30:31 am
Hi there,

Thanks so much for getting back to me so quickly. I have run the code through the Arduino software but it came up with the following error for the following line of code:

error:

sketch_aug04a.ino: In function 'void loop()':
sketch_aug04a:24: error: expected ',' or ';' before ')' token
sketch_aug04a:25: error: expected ',' or ';' before ')' token
sketch_aug04a:26: error: expected ',' or ';' before ')' token

this code highlighted:

unsigned int forwardTime   = map(analogRead(0), 0, 1023, minMilliseconds, maxMilliseconds));

Do you know how to rectify this error? as I am unsure?

hope to hear from you again soon.

Thanks so far.
8  Using Arduino / Programming Questions / Stuck on stepper code on: August 04, 2013, 10:02:27 am
Hi there,

I have bought a stepper linear actuator from ebay:

http://www.ebay.co.uk/itm/180772065982?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

I have wired it up like a bipolar stepper motor with hbridge on this Arduino example page see link:

http://arduino.cc/en/Tutorial/MotorKnob

I am now stuck on the code - would anyone be able to help me? I only seem to be able to find code for turning one direction or another with a sensors reading or code that is just to complicated for me to understand it. I am also very new to coding so have pretty much no knowledge when it comes to using the arduino library as reference.

I would like to make the motor turn in one direction for an adjustable period of time and for an adjustable speed and then turn the other way for an adjustable period of time and speed. Please could someone help me with the code needed for this?

Many thanks and looking forward to your responses.
9  Using Arduino / Motors, Mechanics, and Power / Re: Linear Actuator control with Arduino Uno on: June 09, 2013, 06:44:38 am
Thank you very much for such a detailed response. I think that I am beginning to understand everything better now, however I still have afew questions if you would be so kind to answer them that would be great.

1. I have an SN75441ONE (4 channel Half-H bridge driver) at home, is this ok to use to make the circuit? can be found here: http://www.alldatasheet.com/datasheet-pdf/pdf/28616/TI/SN754410NE.html

2. I am confused as to what the circuit should look like, would it be similar to this image (see image attached) of a unipolar steeper circuit with a h-bridge? Please can you explain to me in complete lamens terms exactly how the circuit goes together? It would be mega useful to have a Fritzig diagram if at all possible because I am very new to all this and am finding most things quite tricky!

3. How do you decide on a 'properly sized heatsink'? can you point me to a place that sells these and the kinds which I may want to buy?

4. As I am struggling with the very basics I think I will be at a complete loss as to how the code works, can you point me in the direction of a code which I can use to control the motor, so that it extends fully and retracts fully, how would this work? Is it similar to the stepper commands to change the devices direction? Would something like the cods on this page work? http://www.tigoe.net/pcomp/code/circuits/motors/stepper-motors/ Or something like the code here? http://arduino.cc/en/Tutorial/MotorKnob

Thanks so much for your help, I really hope I can create this circuit and get everything going, it would be such a great achievement! Hopefully with your help, I will be able too!

A
10  Using Arduino / Motors, Mechanics, and Power / Linear Actuator control with Arduino Uno on: June 08, 2013, 07:21:55 am
Hi there,

I have recently bought a cheap linear actuator from ebay see link to model and specs here: http://www.ebay.co.uk/itm/390595957552?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

I am afraid I am new to controlling motors with an arduino and so need help with pretty much everything, as there does not seem to be a tutorial which I can find online for wiring up an arduino uno with a linear actuator.

Please see what I would like to know below:

1. How do I wire up my linear actuator to my arduino uno? (Do I need any extra components for the circuit? resistors etc...)

2. How do I control my actuator, what code do I use? I need to be able to turn off for a certain amount of time then turn on for a certain amount of time, extending and retracting fully each time.

3. Eventually I need to control around 8 of these motors with the arduino, is this possible and what would I need circuit-wise in order for this to work?

Sorry for the total novice status here, any help would be much appreciated and if someone would like to write a tutorial on the topic I would be much obliged!

Aphra
11  Using Arduino / Sensors / Using an ultrasonic sensor to send signals to LEDs on: February 14, 2013, 06:55:03 pm
Hi there,

I have been struggling and puzzling with this project for a while. I am making an interactive light sculpture. I use an ultrasonic SFRX02 sensor to take readings of how far a person is in relation to my sculpture. I have been using a code for ages which wasn't good enough or fast enough. But now I have found the code below:
Code:
#include <Wire.h>

void setup()
{
  Wire.begin();                // join i2c bus (address optional for master)
  Serial.begin(9600);          // start serial communication at 9600bps
}

int reading = 0;

void loop()
{
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(112); // transmit to device #112 (0x70)
                               // the address specified in the datasheet is 224 (0xE0)
                               // but i2c adressing uses the high 7 bits so it's 112
  Wire.write(byte(0x00));      // sets register pointer to the command register (0x00) 
  Wire.write(byte(0x50));      // command sensor to measure in "inches" (0x50)
                               // use 0x51 for centimeters
                               // use 0x52 for ping microseconds
  Wire.endTransmission();      // stop transmitting

  // step 2: wait for readings to happen
  delay(70);                   // datasheet suggests at least 65 milliseconds

  // step 3: instruct sensor to return a particular echo reading
  Wire.beginTransmission(112); // transmit to device #112
  Wire.write(byte(0x02));      // sets register pointer to echo #1 register (0x02)
  Wire.endTransmission();      // stop transmitting

  // step 4: request reading from sensor
  Wire.requestFrom(112, 2);    // request 2 bytes from slave device #112

  // step 5: receive reading from sensor
  if(2 <= Wire.available())    // if two bytes were received
  {
    reading = Wire.read();  // receive high byte (overwrites previous reading)
    reading = reading << 8;    // shift high byte to be high 8 bits
    reading |= Wire.read(); // receive low byte as lower 8 bits
    Serial.println(reading);   // print the reading
  }

  delay(250);                  // wait a bit since people have to read the output :)
}

Which is great, really good feedback, fast enough and accurate too. But now I need to use these readings to control the brightness of two seperate strips of leds attached to points 5 and 6. This is where I get stuck in my old code my sensor was labelled SFRX02 so I knew whch bit of the code related to my sensor and could use a command like this:

Code:
if (srf02[0].read() >=50 && srf02[0].read() <= 0) {
     digitalWrite(5, HIGH);
     analogWrite(6, map(srf02[0].read(), 50, 0, 0, 255));

But with my new code I do not know which bit relates to my sensor in order to then say to my arduino take reading from the sensor and use those readings to control the brightness of my led strip.

Can anyone help?

I would like my code to say:

when the sensor takes a reading between 50 and 100.
fade in led strip on pin number 5, 100 being the faintest, 50 being the brightest.
led strip on pin number 6, do nothing, keep low/off

when sensor takes a reading between 50 and 0
keep led strip on pin number 5 on high
AND fade in strip on pin number 6, 50 being the faintest, 0 being the brightest.

Can anyone help me to work out, which part of the code above relates to the sensor (what is its name) as i may be able to work out the code from there. or can anyone help me with writing some code that corresponds to request below and the code above?

I would most appreciate it,

Thanks,

Aphra
12  Using Arduino / Programming Questions / code for ultrasonic sensors setting off led strips on: January 16, 2013, 05:27:21 pm
Hi there,

I have managed to get myself into an impossible situation where I am at a gallery installing my show and have got some glitches in the code and don't know how to fix them. If anyone could help me i would be much appreciated.

The reasons why I do not know the answers to the questions is because someone very kindly helped me with the code, i didn't write it and am not that clued up about it!

My code below:

Code:
#include "Wire.h"
#include "SRF02.h"

SRF02 srf02[4] = {
  SRF02(0x70, SRF02_CENTIMETERS),
  SRF02(0x71, SRF02_CENTIMETERS),
  SRF02(0x72, SRF02_CENTIMETERS),
  SRF02(0x73, SRF02_CENTIMETERS)
};

unsigned long nextPrint = 0;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
}

void loop()
{
  SRF02::update();
  if (millis() > nextPrint)
  {
    Serial.print(srf02[0].read());
      Serial.print(",");
      Serial.print(srf02[1].read());
      Serial.print(",");
      Serial.print(srf02[2].read());
      Serial.print(",");
      Serial.print(srf02[3].read());
      Serial.println();
      nextPrint = millis () + 1000;
}



// When sensor's 70, 71, 72 & 73 take a reading between 0-50 turn on LED strip on port 5.

if (srf02[0].read() >=0 && srf02[0].read() <= 50)
     digitalWrite(5, HIGH);
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
     digitalWrite(5, HIGH);
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
     digitalWrite(5, HIGH);
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
     digitalWrite(5, HIGH);

// When sensor's 70, 71, 72 & 73 take a reading between 50-100, keep on LED strip 5 and also turn on the LED strip on port 6.'

if (srf02[0].read() >=50 && srf02[0].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}


// I would be happy to have this communication going first but ultimately I actually want
// the readings to fade in and out my LEDs, see below:

// 'When sensors 70, 71, 72 & 73 take readings 0-50 fade in LED strip on port 5, 0 being the lowest, 50 being the brightest.

if (srf02[0].read() >=0 && srf02[0].read() <= 50)
     analogWrite(4, map(srf02[0].read(), 0, 50, 0, 255));
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
     analogWrite(4, map(srf02[1].read(), 0, 50, 0, 255));
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
     analogWrite(4, map(srf02[2].read(), 0, 50, 0, 255));
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
     analogWrite(4, map(srf02[3].read(), 0, 50, 0, 255));


// When sensors 70, 71, 72 & 73 take readings 50-100, keep strip 5 on its brightest and fade in strip on port 6, 50 beng the lowest, 100 being the brightest.'


if (srf02[0].read() >=50 && srf02[0].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5, map(srf02[0].read(), 50, 100, 0, 255));
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5, map(srf02[1].read(), 50, 100, 0, 255));
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5, map(srf02[2].read(), 50, 100, 0, 255));
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5
     , map(srf02[3].read(), 50, 100, 0, 255));
 }
}

My problems:

1. For some reason when the sensors read above 100 the light in port 5 just stays on all the time. I beileve that i need to state in the code when sensors read above 100 keep both lights in ports 5 and 4 off.
2. The lights don't appear to fade in or out - please can you indicate in the code which bit is that states the fade in and out and how to alter it.
3. i would also like to know which bit in the code indicates the sensor readings as i may need to tweak these. Please can you point this out to me aswell.

If anyone can help me i would appreciate it greatly,

Thankyou,

Aphra
13  Using Arduino / Sensors / Re: Controlling LEDs with 4 ultra sonic sensors on: January 16, 2013, 05:18:17 pm
Hi there,

I managed to solve that problem that i had before but have managed to get myslef into a silly situation: I am now at a gallery installing my work and I have not sorted out the problems with the code that I had before I made my sculpture itself! Too much to think about I think!

So I could really use some help!

The code
Code:
#include "Wire.h"
#include "SRF02.h"

SRF02 srf02[4] = {
  SRF02(0x70, SRF02_CENTIMETERS),
  SRF02(0x71, SRF02_CENTIMETERS),
  SRF02(0x72, SRF02_CENTIMETERS),
  SRF02(0x73, SRF02_CENTIMETERS)
};

unsigned long nextPrint = 0;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
}

void loop()
{
  SRF02::update();
  if (millis() > nextPrint)
  {
    Serial.print(srf02[0].read());
      Serial.print(",");
      Serial.print(srf02[1].read());
      Serial.print(",");
      Serial.print(srf02[2].read());
      Serial.print(",");
      Serial.print(srf02[3].read());
      Serial.println();
      nextPrint = millis () + 1000;
}



// When sensor's 70, 71, 72 & 73 take a reading between 0-50 turn on LED strip on port 5.

if (srf02[0].read() >=0 && srf02[0].read() <= 50)
     digitalWrite(5, HIGH);
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
     digitalWrite(5, HIGH);
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
     digitalWrite(5, HIGH);
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
     digitalWrite(5, HIGH);

// When sensor's 70, 71, 72 & 73 take a reading between 50-100, keep on LED strip 5 and also turn on the LED strip on port 6.'

if (srf02[0].read() >=50 && srf02[0].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
     digitalWrite(5, HIGH);
     digitalWrite(6, HIGH);
}


// I would be happy to have this communication going first but ultimately I actually want
// the readings to fade in and out my LEDs, see below:

// 'When sensors 70, 71, 72 & 73 take readings 0-50 fade in LED strip on port 5, 0 being the lowest, 50 being the brightest.

if (srf02[0].read() >=0 && srf02[0].read() <= 50)
     analogWrite(4, map(srf02[0].read(), 0, 50, 0, 255));
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
     analogWrite(4, map(srf02[1].read(), 0, 50, 0, 255));
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
     analogWrite(4, map(srf02[2].read(), 0, 50, 0, 255));
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
     analogWrite(4, map(srf02[3].read(), 0, 50, 0, 255));


// When sensors 70, 71, 72 & 73 take readings 50-100, keep strip 5 on its brightest and fade in strip on port 6, 50 beng the lowest, 100 being the brightest.'


if (srf02[0].read() >=50 && srf02[0].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5, map(srf02[0].read(), 50, 100, 0, 255));
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5, map(srf02[1].read(), 50, 100, 0, 255));
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5, map(srf02[2].read(), 50, 100, 0, 255));
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
     digitalWrite(4, HIGH);
     analogWrite(5
     , map(srf02[3].read(), 50, 100, 0, 255));
 }
}

My problems:

1. For some reason when the sensors read above 100 the light in port 5 just stays on all the time. I beileve that i need to state in the code when sensors read above 100 keep both lights in ports 5 and 4 off.
2. The lights don't appear to fade in or out - please can you indicate in the code which bit is that states the fade in and out and how to alter it.
3. i would also like to know which bit in the code indicates the sensor readings as i may need to tweak these. Please can you point this out to me aswell.

If you or anyone else can help me, I would most appreciate it.

Thankyou,

Aphra
14  Using Arduino / Programming Questions / Re: interactive leds controlled by sensors on: January 05, 2013, 06:10:35 pm
Hi there,

I've cracked that problem so the code is now uploaded. I have a problem with the code now perhaps you can help me?

Code:
#include "Wire.h"
#include "SRF02.h"

SRF02 srf02[4] = {
  SRF02(0x70, SRF02_CENTIMETERS),
  SRF02(0x71, SRF02_CENTIMETERS),
  SRF02(0x72, SRF02_CENTIMETERS),
  SRF02(0x73, SRF02_CENTIMETERS)
};

unsigned long nextPrint = 0;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
}

void loop()
{
  SRF02::update();
  if (millis() > nextPrint)
  {
    Serial.print(srf02[0].read());
      Serial.print(",");
      Serial.print(srf02[1].read());
      Serial.print(",");
      Serial.print(srf02[2].read());
      Serial.print(",");
      Serial.print(srf02[3].read());
      Serial.println();
      nextPrint = millis () + 1000;
}



// 'When sensors 70, 71, 72 & 73 take readings 0-50 fade in LED strip on port 5, 0 being the lowest, 50 being the brightest.

if (srf02[0].read() >=0 && srf02[0].read() <= 50)
     analogWrite(5, map(srf02[0].read(), 0, 50, 0, 255));
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
     analogWrite(5, map(srf02[1].read(), 0, 50, 0, 255));
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
     analogWrite(5, map(srf02[2].read(), 0, 50, 0, 255));
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
     analogWrite(5, map(srf02[3].read(), 0, 50, 0, 255));


// When sensors 70, 71, 72 & 73 take readings 50-100, keep strip 5 on its brightest and fade in strip on port 6, 50 beng the lowest, 100 being the brightest.'


if (srf02[0].read() >=50 && srf02[0].read() <= 100) {
     digitalWrite(5, HIGH);
     analogWrite(6, map(srf02[0].read(), 50, 100, 0, 255));
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
     digitalWrite(5, HIGH);
     analogWrite(6, map(srf02[1].read(), 50, 100, 0, 255));
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
     digitalWrite(5, HIGH);
     analogWrite(6, map(srf02[2].read(), 50, 100, 0, 255));
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
     digitalWrite(5, HIGH);
     analogWrite(6, map(srf02[3].read(), 50, 100, 0, 255));
  }
}

It is fading my lights on and off how I wish however when the reading goes above 100 the lights seem to just stay on, is there a way to remedy this in the code?

thanks for your help
15  Using Arduino / Programming Questions / Re: interactive leds controlled by sensors on: January 05, 2013, 05:52:36 pm
Hi,

There is no more code beyond what I have there, I am quite new to all this so I also am not entirely sure what you mean!? any suggestions?

thanks
Pages: [1] 2 3