Category Archives: Week 5 Assignment

WEEK5 light up led with ultrasonic sensor and photocell

The goal of this assignment:

Create a circuit with ultrasonic sensor and photocell to fulfill the following requirements:

  • If the environment is bright, the LED won’t light up.
  • If the environment is dark but the distance is far away, the LED won’t light up.
  • If the environment is dark and the distance is less than__, the LED will light up.

List of components:

  • arduino Uno
  • 220-ohm resistorx1 (led)
  • 10k resistorx1 (photocell)
  • photocellx1
  • ultrasonic sensorx1
  • wires and breadboard

How it works:

How photocell works is to change analog voltage based on the amount of light received by the sensor. As the light level increases, the analog voltage goes up even though the resistance goes down. For the ultrasonic sensor, using echo and trig pin to detect the soundwave and then calculate the distance between object. Put all together in this circuit, the photocell will detect the light amount in the environment at first, and if it’s bright enough (depend on each photocell, the number change dramatically because it’s super unstable) the led won’t light up. If the distance between the object(hand) and ultrasonic sensor is less than 10cm, the led will light up. However, even if you cover the whole photocell to make the environment dark, the led won’t light up because of the && function in code. You still need to be close enough to the distance sensor to make it work.

Circuit:

CODE in Arduino : 

const int trigPin = 13; //naming a constant value / giving a variable name / #define acts as a find and replace
const int echoPin = 12;
const int yellowLed = 8;
const int photocell = A0;
int light;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT); //trigPin is sending out the signal
pinMode(echoPin, INPUT); //echoPin is retrieving information, therefore it is INPUT
pinMode(yellowLed, OUTPUT); //trigPin is sending out the signal
pinMode(photocell, INPUT); //echoPin is retrieving information, therefore it is INPUT

}

void loop() {
long duration, distance, light;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1; //Time it took for the echo to be received and divided in half then divided by the speed of sound

light = analogRead(photocell);

if(light < 700 && distance < 10){

// Serial.println(“work”);
digitalWrite(yellowLed, HIGH);
// wait for a second
}
else{
digitalWrite(yellowLed, LOW);
}
// Serial.print(distance);
// Serial.println(” cm”);

Serial.println(light);
// Serial.println(distance);

}

Problem:

The photocell is really unstable, I tried connecting two different photocells at first, and kept getting 1023 in my serial monitor. Only after I moved to somewhere really bright and opened up the third brand new photocell then I got the reasonable number from the serial monitor.

 

Week 5 Serial Connect with Processing

Goal:

I want to create a use ultrasonic sensor and a photocell to send data and bytes to processing, that allows me create a sense of controlling nature force on digital screen.

Description:

The sum of sensor values from ultrasonic and photocell determines the opacity and position of particles inside the fog.

  • How it works: people use hands to move around the ultrasonic sensor and use finger to cover the amount of light through photocell to control the position and opacity of fog particles on screen

Problem:

The data sent from Arduino to Processing are within certain range which are hard to be calculated and mapped precisely into the Processing sketches. Also, the bytes are not stable. (Also, I forgot to write code for LED, but I think it does not matter that much)

Materials:

  1. Arduino UNO R3 x 1
  2. Breadboard x 1
  3. Ultrasonic sensor x 1
  4. Photocell x 1
  5. 220Ω Resistors x 1
  6. Wires

Connection Diagram:

Code:

Arduino

Processing:

week 5 Phtotcell & Ultrasonic

 

Goal:

  • If the environment is bright, the LED won’t light up.
  • If the environment is dark but the distance is far away, the LED won’t light up.
  • If the environment is dark and the distance is close, the LED will light up.

List:

  • 1x Yellow LED
  • 1x Ultrasonic sensor
  • 1x Photocell
  • 1x Resistors (220 ohms) – resistor
  • 1x Resistors (10K ohms) – photocell

Arduino Code:

https://github.com/yuemelz/pcom2018/blob/master/photocell_distance.ino

Sensor Combination (Week 5)

  • Goal of this project : I made a circuit enables RGB LED to be on/off and change the light color corresponding to both sensor – ultrasonic sensor and photoresistor. I used RGB LED to change its color according to the distance detected by ultrasonic sensor, and also it will be on/off according to the light of space detected by photoresistor.
  • Circuit and components : Arduino, RGB LED, Ultrasonic sensor, photoresistor, 3 x 220ohm resistors(for RGB LED), 1 x 1K ohm resistor(for photoresistor), jumper wires          * RGB LED has 4 legs – three legs are for red, green, blue output color, and one long leg is for ground.

Continue reading

Week 5- Joyce

Goal:

The goal of this project is to build a LED light that will light up when the environment is dark and senses people approach.

Components:

red led x1

green led x1

 

resistor(200Ω) x1

resistor(10kΩ) x1

photocell x1

arduino board & breadboard

 

How it works

The photocell will first sense the light in the room. If the data is less that 700 and the distance that UltraSensor sense is less that 10, the light will turn on.

Code: https://github.com/joycemolly/pcomp–lock-combination/blob/master/homeworkLock.ino

Distance Sensor + Photo-resistor – Dario N (Week 5)

Goal of the Project:

The intention with this project was to explore the capabilities of sensors connected to an Arduino, and how with the transformed data it is possible to create statements (conditionals) to achieve different purposes. In this particular case, the proposal was to create conditionals by mapping the values of a distance sensor and a photoresistor in order to light up or turn off and Led.

Conditions:

  1. If the environment is bright, the LED won’t light up.
  2. If the environment is dark but the distance is far away, the LED won’t light up.
  3. If the environment is dark and the distance is close, the LED will light up.

List of Components:

  • x1 Arduino Uno
  • x1 Breadboard
  • x1 Distance Sensor
  • x1 Photoresistor
  • x1 RED LED
  • x1 220 kohm Resistors (for the LED)
  • x1 10 kohm Resistors (for the photosensor)
  • Jumper Wires

Assembly Process:

A good practice to create this circuit consists to connect each sensor (one by one) and check if the microcontroller is reading the data and is doing it correctly. First, the LED is connected, positive side to pin 11, and negative to a 10kohm resistor and ground. The Distance Sensor Trig and Echo are connected to pins 13 and 12 respectably.  The photoresistor is connected to the Analog Pin A0.

How it works:

The Arduino program is constantly reading 3 conditions: If it’s bright (more than 30 for the photoresistor sensorValue), then the LED is off (LOW). if (sensorValue > 30), then: digitalWrite(led,LOW). If it’s dark and the distance to the sensor is more than 10cms, then the LED is off (LOW). if (distance > 10 && sensorValue < 30), then digitalWrite(led,LOW). Finally, if it’s dark and the distance to the sensor is less than 10cms, then turn on the led (HIGH). if (distance < 10 && sensorValue < 30), then, digitalWrite(led,HIGH).

Problems:

The main issue doing this exercise was trying to understand the Photoresistor I had available. The one that I have it’s from Elegoo and it has 3 connections instead of 2. In this case, it’s a bit more convenience when I want to connect the different wires to the breadboard and to the Arduino. I just had to check the “info-sheet” of the product.

Arduino Code (File):

https://www.dropbox.com/s/wb1e1fnj43sxcen/DarioNarvaez_HW_5.ino?dl=0

Circuit Diagrams:

Alternative Photo-Resistor Connection:

 

Week 5: Combination of sensors

This week’s assignment was to create a circuit, where an ultrasonic sensor and a photosensor are used to control the state of the LED. Only when certain conditions are met for both, does the LED turn on.

  

List of Materials

1 x Elegoo Uno R3

1 x Full sized breadboard

1 x HC-SR04 Ultrasonic sensor

1 x Photocell (or photoresistor)

1 x LED

Resistors: 1x 220 Ohms (for the LED), 1 x 10K Ohms (for the photocell)

Jumper wires

Description of assembly 

  1. Connect the ground side of the breadboard to the GND pin, and the power side to the 5V pin, on the Arduino.
  2. Place the Ultrasonic sensor on the breadboard. Connect the VCC pin to the power, the trig and echo pins to digital pins 13 and 12  respectively, and the GND pin to the ground. Then connect the photoresistor, with one of the legs connected to power, and the other to the ground (through a 10K Ohm resistor) and to the Analog Input Pin A0.
  3. Finally, add an LED to the circuit, with the shorter leg connected to the ground via a 220 Ohm resistor, and the longer leg to digital pin 8.
  4. Upload the code to the Arduino IDE.
  5. Debug, check connections and keep working!

Fritzing Diagram (Using the open source, free software available at http://fritzing.org)

How it works

The code has an if statement that checks for two conditions- the proximity of the object from the ultrasonic sensor and the amount of light entering the photocell. Only when BOTH the conditions are satisfied, does the LED turn on. In all other cases, it remains off.

Challenges

Initially, I was having a problem with adjusting the threshold values for the two analog sensors. With the help of the serial monitor, I was able to choose the appropriate value.

Code 

Continue reading

week 5 sensors Xiaoyu

Goal of project/interaction

Create a circuit that the LED will light up only when the ultrasonic sensor detect something close and photocell sensor is covered.

Core components

1 * ultrasonic sensor
1 * photocell sensor
1 * LED
1 * 10k ohms resistors
1 * 220 ohms resistors
Wires & jumpwires
Arduino board

How it works

Get close to the ultrasonic sensor
Cover the photocell
LED light up

 

Github

pcom/ultrasonic&photocell

 

 

Week 5 – sensors

Goal of the project : Turn on the light according to distance and ambient light
Core components : Led light, photocell, 220 Ohm resistor, 1k resistor, ultrasonic sensor, arduino
How it works : the ultrasonic sensor measures the distance and the photocell measures the ambient light. An if statement combines the two measurements to control the led light
Problems encountered : the led light blink when is on. I couldn’t find a way to connect the photocell data without using a map function

Continue reading