Inputs and Sensors

Made by Stephanie Ho

Created: November 9th, 2023

0

Intention

  • get to know the sensors in your kits
  • learn how to integrate sensing into your circuits and read information from the environment around you;
  • become familiar with how to write code to translate sensors into outputs (cloud connectivity or output like LEDs)
  • build familiarity with conditional logic and if statements
  • map sensor readings onto actions and feedback 
0

Process

I built familiarity with several of the sensors, including the operations of:

  • Button
  • Potentiometer
  • Light Sensor
  • Pressure Sensor

I encountered several difficulties when trying to repeat the design and ultimately did not use the light sensor because it responded poorly and slowly. I adjusted the original code for a 300-4095 range and that worked the first time, but did not respond in subsequent tests.

0
int photoCellPin =A0;
int photoCellReading=0;
int ledPin=D2;
int ledBrightness=0;

void setup() {
pinMode(ledPin, OUTPUT);

Particle.variable("light",&photoCellReading, INT);

}

void loop() {
//analogRead reads the photocell, and gives a value from 0 to 4095
photoCellReading =analogRead (photoCellPin);

//We want to map this value into the PWM range of 0-255
ledBrightness =map(photoCellReading, 3000,4095,0,255);

//fade the LED to the desired brightness, sets the value
analogWrite(ledPin, ledBrightness);

//waits and then loops
delay(100);
}
Click to Expand
0
0

Process

I then experimented with the pressure or 'flex sensor' as it's labeled in the code with greater success. I used the cloud readings to adjust the if loop conditions so that the effects in the lights were more distinguished, and turned 'off' the lights to mark the end of the loop.

0
int flexSens =A0;
int YellowPin=D2;
int GreenPin=D3;

int ledBrightness;
int flexSensReading;

void setup() {
    pinMode(YellowPin, OUTPUT);
    pinMode(GreenPin, OUTPUT);
    pinMode(flexSens, INPUT);
    Particle.variable("power",&flexSensReading, INT);

}

void loop() {
    //analogRead reads the sensor, and gives a value from 0 to 4095
    flexSensReading =analogRead (flexSens);

    //We want to map this value into the PWM range of 0-255
    ledBrightness = map(flexSensReading, 0, 4095, 0, 255);
    
    if(flexSensReading<=1000){
        analogWrite(YellowPin, ledBrightness);
    }
    //fade the LED to the desired brightness, sets the value
    else if (flexSensReading >2000){
        analogWrite(YellowPin, ledBrightness);
        analogWrite(GreenPin, ledBrightness);
    }
    //waits and then loops
    delay(100);
    digitalWrite(YellowPin, LOW);
    digitalWrite(GreenPin, LOW);
    }
Click to Expand
0
0

Learnings

My learnings from this skill development are to 1) explore different ways to "bug test", such as testing a different sensor and 2) utilize the cloud readings as input to adjust the cloud. I spent a significant amount of time trying to understand the issue with the light sensor that may have been helpful testing something else!

x
Share this Project

Courses

48-675 Designing for the Internet of Things

· 11 members

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


About

~