Drawbridge Project, LEDS aren't turning on.


hello, i'm in first basic engineering course in college , i'm learning how use arduino. i'm using arduino uno processor, , i'm working on small drawbridge project.

code: [select]

int buzzer = 8;
int prox = a5;
int pot = a4;
int presr = a3;
int lghtsen = a2;
int bigblue = 11;
int led1 = 6;
int led2 = 5;
int led3 = 3;
int potval = 0;
int lghtval = 0;
int prxval = 0;
int presrval = 0;
#include <servo.h>
servo serv1;
servo serv2;
int pos = 0;


void setup(){
  pinmode(buzzer, output);
  pinmode(prox, input);
  pinmode(pot, input);
  pinmode(presr, input);
  serv1.attach(9);
  serv2.attach(10);
  pinmode(lghtsen, input);
  pinmode(bigblue, output);
  pinmode(led1, output);
  pinmode(led2, output);
  pinmode(led3, output);
}

void loop(){
  potval=analogread(pot);
  lghtval=analogread(lghtsen);
  prxval=analogread(prox);
  presrval=analogread(presr);
 
  digitalwrite(led1, high);
  digitalwrite(led2, low);
  digitalwrite(led3, low);
  digitalwrite(bigblue, low);
  digitalwrite(buzzer, low);
 
  if (lghtval>500 && prxval>60 && presrval<300){
    digitalwrite(led1, low);
    digitalwrite(led2, high);
    digitalwrite(led3, low);
    delay(5000);
    digitalwrite(led1, low);
    digitalwrite(led2, low);
    digitalwrite(led3, high);
    tone(buzzer, 300);
    digitalwrite(bigblue, high);
    if (potval<420){
      for(pos = 0; pos<60; pos+= 1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
      delay(4000);
      for(pos = 60; pos>=1; pos-=1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
    }
    if (potval>420 && potval<850){
      for(pos = 0; pos<90; pos+= 1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
      delay(4000);
      for(pos = 90; pos>=1; pos-=1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
    }
    if (potval>850){
      for(pos = 0; pos<180; pos+= 1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
      delay(4000);
      for(pos = 180; pos>=1; pos-=1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
    }
  if (lghtval<500 && prxval>60 && presrval<300){
    delay(7000);
    digitalwrite(led1, low);
    digitalwrite(led2, high);
    digitalwrite(led3, low);
    delay(5000);
    digitalwrite(led1, low);
    digitalwrite(led2, low);
    digitalwrite(led3, high);
    tone(buzzer, 300);
    digitalwrite(bigblue, high);
    if (potval<420){
      for(pos = 0; pos<60; pos+= 1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
      delay(4000);
      for(pos = 60; pos>=1; pos-=1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
    }
    if (potval>420 && potval<850){
      for(pos = 0; pos<90; pos+= 1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
      delay(4000);
      for(pos = 90; pos>=1; pos-=1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
    }
    if (potval>850){
      for(pos = 0; pos<180; pos+= 1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
      delay(4000);
      for(pos = 180; pos>=1; pos-=1){
        serv1.write(pos);
        serv2.write(pos);
        delay(20);
      }
    }
  }
  }}



basically code, when object (a "boat", since it's drawbridge) gets close enough distance sensor , there no "car" on bridge (making pressure value under amount) bridge should raise. have when it's "daytime" (based off light sensor) bridge wait before opening let more traffic through, , @ "night" when there less traffic, bridge automatically open. potentiometer controls how high bridges rises.

the problem have when bridge rises buzzer , blue light ( in code bigblue) should turn on. 3 leds (led1, led2, led3) supposed act traffic lights. problem none of these outputs working. 2 servos changing when bridge raises.

is problem in code? or power issue? figure if power issue servos wouldn't work either. of course i'm new both arduino , dealing electronics in general. appreciated. hope answer simple more experienced users.

code: [select]
  pinmode(prox, input);
  pinmode(pot, input);

you can't set mode of read-only analog pin.

why not write simple sketch turns led pins on? then, if leds light up, wired correctly. if not, aren't.


Arduino Forum > Using Arduino > Project Guidance > Drawbridge Project, LEDS aren't turning on.


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code