Post 6

The last few weeks I have been looking into different LEDs that I could use for my project. I have looked into LED strips (short and long) and spent most of my time playing with them to understand how I could use them in relation to the Ultrasonic sensor. I also wanted to fine tune the type of code I was using to enact the LEDs with the input from the Ultrasonic Sesnor.




I learned that you could cut and re-solder the LED strips, but I am still pretty unfamiliar with them and I am scared to break/short circuit something. But I spent a good amount of time understanding the connections and how I would potentially connecct it to an Arduino board. Also, LED strips require a lot more pieces such as a capacitor, direct current, and specific battery packs. I believe the connection and coding process is a little different that working with other objects and arduino.

I began working on the physcial computing of my LED lights for the physical art work. I found a diagram on how to connect a Ultrasonic sensor and LED to an Arduino uno board. I then found existing code that someone else had created i began testing the code:


Test 1: I found a code that created a relationship between the ultrasonic sesnor and LED connected through the arduino. My issue was that the LED did not get brighter as my hand arrpoached the sesnor, but instead when I put my hand in front of the sensor which acted as a trigger.


Test 2: I found another code that was based on an alarm base don how close something is, and I tried to play with the brightness




Origianal Code


http://www.instructables.com/id/Arduino-Distance-Detector-with-a-Buzzer-and-LEDs/

#define trigPin 7
#define echoPin 6
#define led 13
#define led2 12
#define led3 11
#define led4 10
#define led5 9
#define led6 8
#define buzzer 3

int sound = 250;


void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(buzzer, OUTPUT);
 
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 

  if (distance <= 30) {
    digitalWrite(led, HIGH);
    sound = 250;
}
  else {
    digitalWrite(led,LOW);
  }
  if (distance < 25) {
      digitalWrite(led2, HIGH);
      sound = 260;
}
  else {
      digitalWrite(led2, LOW);
  }
  if (distance < 20) {
      digitalWrite(led3, HIGH);
      sound = 270;

  else {
    digitalWrite(led3, LOW);
  }
  if (distance < 15) {
    digitalWrite(led4, HIGH);
    sound = 280;
}
  else {
    digitalWrite(led4,LOW);
  }
  if (distance < 10) {
    digitalWrite(led5, HIGH);
    sound = 290;
}
  else {
    digitalWrite(led5,LOW);
  }
  if (distance < 5) {
    digitalWrite(led6, HIGH);
    sound = 300;
}
  else {
    digitalWrite(led6,LOW);
  }
 
  if (distance > 30 || distance <= 0){
    Serial.println("Out of range");
    noTone(buzzer);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    tone(buzzer, sound);
   
  }
  delay(500);
}


I also assess code that focused on brightness:

https://www.arduino.cc/en/Tutorial/Dimmer

const int ledPin = 9;      // the pin that the LED is attached to


void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
  }
}




Questions and Reflections
I also continued working on painting the physical part of my piece. Right now the code works somewhat, but the LED is very dim and want to seek help from some classmates who have more experience with Aurduino. Also, I want to make sure I was apporaching the LED strip properly.

Comments

Popular posts from this blog

Phase 1

Brainstorming

Brainstorming Materials and Wants