Skills Dev II: Working with Inputs and Sensors

Made by Yiming Jiao

Use 2 sencors as input to make some outputs.

Created: November 9th, 2023

0

Outcome

This project are mainly construct by 4 conponents: a bend sensor, a photoresistor, a LED, and a buzzer.

The range of  bend sensor is between 150 to 500, which of  photoresistor is 2000 to 4000. I maped valuse from  photoresistor in range 0 to 255. When only bend valus lower than 250, the LED will display for 1.5 seconds and off for 0.5 seconds.  When only photoresistor valus lower than 100,  the LED will display for 0.5 seconds and off for 1.5 seconds. And if both of them are in a poor valus, the buzzer will start beeping.

Process

I start this project by following the tutorial at first, then added my own component and reactions. One problen I met is I didn't realized that the bend sensor is not accurate. It was not work at beginning because I thought there are bug in my circuit or code, but finally find it is because it need more bend to react.

Next Steps

This project is interesting. probably I can combine this project with Lab1, so I can triger the buzzer though wifi.

Reflection

In this project, I find the use of bend sensor is very interesting and potential, because it is very likely to interacting with people.

0
Skills Dev II: Working with Inputs and Sensors
Yiming Jiao - https://youtu.be/7wD3DfysZ8k?feature=shared
0
// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int photoCellPin = A0;
int bendPin = A1;
int buzzerPin = D3;
// Create a variable to hold the light reading
int photoCellReading = 0;
int bendReading = 0;

// Define a pin we'll place an LED on
int ledPin = D2;

// Create a variable to store the LED brightness.
int ledBrightness = 0;

void setup() {
    pinMode(bendPin, INPUT);
    pinMode(photoCellPin, INPUT);
    pinMode(ledPin, OUTPUT);
    pinMode(buzzerPin, OUTPUT);
    Particle.variable("light", &photoCellReading, INT);
    Particle.variable("bend", &bendReading, INT);

}

void loop() {
  // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  photoCellReading = analogRead(photoCellPin);
  bendReading = analogRead(bendPin);
  // Map this value into the PWM range (0-255)
  // and store as the led brightness
  ledBrightness = map(photoCellReading, 2800, 4095, 0, 255);
  
  //light the led when Bend Sensor is bent
  if(bendReading < 250 && ledBrightness < 100){
      // both sensors show bad readings at the same time, play a sound alert
      tone(buzzerPin, 1000, 500);
      delay(500);
  }else{
      if(bendReading < 250){
          // only the first sensor has poor readings, blink the LED to display the led for 1.5 seconds and off for 0.5 seconds
          analogWrite(ledPin, 255);
          delay(1500);
          analogWrite(ledPin, 0);
          delay(500);
      }else{
          if(ledBrightness < 100){
              // only the second sensor has poor readings, blink the LED such that it is on for 0.5seconds and off for 1.5 seconds
              analogWrite(ledPin, 255);
              delay(500);
              analogWrite(ledPin, 0);
              delay(1500);
          }
      }
  }

  // wait 1/10th of a second and then loop
  delay(100);
}
Click to Expand
x
Share this Project

Courses

48-675 Designing for the Internet of Things 24

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Use 2 sencors as input to make some outputs.