Week 4: Progression – Dom Heyland, Toby Nalder

At the stage in the project, we have set up our Arduino with a single light sensor and resistor. We wanted to fully understand how the sensor worked before moving on and adding in several LED Lights and multiple Sensors.

Using the torch on the iPhone and covering the sensor with a hand, we where able receive different readings from the sensor through the serial monitor.

Code used to test the sensor:

int potPin = 8;

void setup() {
  // put your setup code here, to run once:
pinMode (potPin, INPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println(analogRead(potPin));
delay(1000);
}

Our readings varied from a range of 260-1010

img_3330

We then moved on to try and include a caterpillar into our circuit to control 8 LEDs through 3 outputs. After researching into how the caterpillar is used we then tried to replicate an existing code we found. This wasn’t successful as only 1 of the 8 LEDs blinked.

 

 

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
 
byte leds = 0;

void setup() 
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
}
 
void loop() 
{
  leds = 0;
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(500);
  }
}
 
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}

 

learn_arduino_fritzing1

image1-1

Towards the end of the session we managed to make a LED glow when it got dark (by covering up the light sensor). This was achieved using analog read and writes so that the LED changed brightness depending on the light in the sensor, and the range can easily be changed in the code. This is close to the end result we want.

Before the deadline next week we need to recreate this set up with multiple led’s connected to more light sensors to give the field of firefly’s effect.

Below is the code we used, the breadboard setup and a picture of it working.

int ledPin = 9;
int potPin = 0;
int minLight = 0;
int maxLight = 400;
int val = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(potPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(analogRead(potPin));
  val = analogRead(potPin);
  if (val > minLight && val < maxLight)
  {
    val = map (val, minLight, maxLight, 255, 0);
  }
  else
  {
    val = 0;
  }
  analogWrite(ledPin, val);
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s