I need help with my school project using LEDs, LDRs and timer.


hello everyone, need school project.
in physics class, learning how use arduino understand physics.
basically, have aluminum bar , trying explain why neodymium magnet goes down slower iron ball inside it.
and i'm supposed program leds turn on (using ldrs) everytime ball passes through , write down seconds, can't use others hardwares, serial monitor.

hardware: 6 ldrs, 6 leds , aluminium bar

so, here need know:

1- how can make serial monitor show every 6 ldrs values in every second?
2- need program write down seconds in serial monitor everytime ball passes through.

here have far, isn't right, it's start.

code: [select]
int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
int led5 = 9;
int led6 = 8;

int ldr1 = a0;
int ldr2 = a1;
int ldr3 = a2;
int ldr4 = a3;
int ldr5 = a4;
int ldr6 = a6;

int val1;
int val2;
int val3;
int val4;
int val5;
int val6;

void setup (){
  pinmode (led1, output);
  pinmode (led2, output);
  pinmode (led3, output);
  pinmode (led4, output);
  pinmode (led5, output);
  pinmode (led6, output);
  serial.begin (9600);
}

void loop(){
  val1 = analogread (ldr1);
  serial.println (val1);
  delay (1000);
  if (val1 > 50){
    digitalwrite (led1, high);
  }
  else if (val1 <= 50){
    digitalwrite (led1, low);
  }

  val2 = analogread (ldr2);
  serial.println (val2);
  delay (1000);
  if (val2 > 50){
    digitalwrite (led2, high);
  }
  else if (val2 <= 50){
    digitalwrite (led2, low);
  }

  val3 = analogread (ldr3);
  serial.println (val3);
  delay (1000);
  if (val3 > 50){
    digitalwrite (led3, high);
  }
  else if (val3 <= 50){
    digitalwrite (led3, low);
  }
 
  val4 = analogread (ldr4);
  serial.println (val4);
  delay (1000);
  if (val4 > 50){
    digitalwrite (led4, high);
  }
  else if (val4 <= 50){
    digitalwrite (led4, low);
  }

   val5 = analogread (ldr5);
  serial.println (val5);
  delay (1000);
  if (val5 > 50){
    digitalwrite (led5, high);
  }
  else if (val5 <= 50){
    digitalwrite (led5, low);
  }

   val6 = analogread (ldr6);
  serial.println (val6);
  delay (1000);
  if (val6 > 50){
    digitalwrite (led6, high);
  }
  else if (val6 <= 50){
    digitalwrite (led6, low);
  }
}



i'm new programming, why need help. if can me, thankful.  :d

quote
how can make serial monitor show every 6 ldrs values in every second?
the first thing stop using delay() because blocks program execution expect have found.

next, put sensor , led pins in arrays can loop through them quickly
here code started.
code: [select]
const byte ldrpins[] = {a0, a1, a2, a3, a4, a5, a6};
const byte ledpins[] = {13, 12, 11, 10, 9, 8};
const byte ldrthreshold = 50;
unsigned long starttime;

void setup()
{
  serial.begin(115200);
//add pinmodes here
}

void loop()
{
  starttime = millis();
  for (int t = 0; t < 7; t++)
  {
    if (analogread(ldrpins[t]) > ldrthreshold)
    {
      digitalwrite(ledpins[t], high);
      serial.println(millis() - starttime);
    }
  }
}

it not complete if flesh out should work.


Arduino Forum > Using Arduino > Programming Questions > I need help with my school project using LEDs, LDRs and timer.


arduino

Comments