Working with Inputs and Sensors

Made by Wendy Rodriguez

Prepare a simple 2-in (sensors or inputs) 1-out (LED) device (i.e., your project will use three components, and at least one must be a sensor). Present a straightforward use case for a connected sensor device.

Created: December 18th, 2022

0

Process

Describe the process you underwent to reach the outcome (problems encountered, how you resolved them, as well as, experiments, hacks, tests, refinements, iterations, failures)

A LOT of things went wrong with this project. All my issues revolved around the circuit. 

  • I created the first circuit on my bigger breadboard first. I ran the code, and fixed wiring left, and right to figure one side of the breadboard's ground aisle was not working. This breadboard kept giving me problems, so I switched my circuit to the smaller breadboard that comes with the original particle. 
  • After switching to the smaller breadboard, I realized that the components were working, but the LED was not as bright as it should be. Since this is a smaller breadboard, I could not catch that the wire connected to 3V3 had undone itself. After that was fixed, everything was working wonderfully. 

0

Reflection

Reflect on the process of doing this project. What did you learn? What would you do differently?

The main thing I learned is that having an efficient troubleshooting process can save you a lot of time. When trying to realize what was wrong with my bigger breadboard, rather than testing the ground cable first, I just ripped everything off the breadboard and then tested the ground cable. 

0
//pins 

int ledPin = D3; 

int switchPin = D4; 

int potPin = A5; 

//variable to store pot readings and brightness of the LED. 
int potReading = 0; 

int ledBrightness = 0; 

void setup()
{
    pinMode(switchPin , INPUT_PULLUP); 
    
    pinMode(ledPin, OUTPUT); 
    
    Particle.variable("pot" , potReading); 
    
}

void loop() 
{
    int switchState = digitalRead(switchPin); 
    
    if(switchState == LOW)
    {
        digitalWrite(ledPin, HIGH); 
        
         // Use analogRead to read the potentiometer reading
        // This gives us a value from 0 to 4095
       potReading = analogRead(potPin); 
        
          // Map this value into the PWM range (0-255)
         // and store as the led brightness 
        ledBrightness = map(potReading, 0, 4095, 0, 255); 
        
         
        // fade the LED to the desired brightness
       analogWrite(ledPin, ledBrightness); 
        
         //wait 1/10th of a second and then loop
        delay(100); 
   }
   else
    { 
       digitalWrite(ledPin, LOW); 
  }
}
Click to Expand
x
Share this Project

Courses

About

Prepare a simple 2-in (sensors or inputs) 1-out (LED) device (i.e., your project will use three components, and at least one must be a sensor). Present a straightforward use case for a connected sensor device.