Skills Dev II: Working with Inputs and Sensors

Made by Maria Jose Fernandez · UNLISTED (SHOWN IN POOLS)

Created: November 10th, 2022

0

Outcome

    • Light up the led light by using different buttons and building different circuits.

0

Process

The most challenging part in this exercise was the wiring. Putting the resistor in the correct place in the breadboard and connecting the jump wires precisely is always a challenging task.

0

Reflection

I would try create/propose a new circuit so that way I totally understand the logic behing specific connections and not just do it by the instructions. This will allow me to explore and be more creative for my final projet.

0

Using a pushbutton 

0
0
int ledPin = D2;

// Our button wired to D0
int buttonPin = D3;

void setup()
{

  // For input, we define the
  // pushbutton as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

  pinMode( buttonPin , INPUT_PULLUP); // sets pin as input

  // We also want to use the LED

  pinMode( ledPin , OUTPUT ); // sets pin as output

}

void loop()
{
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( buttonPin );

  // remember that we have wired the pushbutton to
  // ground and are using a pulldown resistor
  // that means, when the button is pushed,
  // we will get a LOW signal
  // when the button is not pushed we'll get a HIGH

  // let's use that to set our LED on or off

  if( buttonState == LOW )
  {
    // turn the LED On
    digitalWrite( ledPin, HIGH);
  }else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);

  }


}
Click to Expand
0

Using a potentiometer

0
0
// Define a pin that we'll place the pot on
int potPin = A5;

// Create a variable to hold the pot reading
int potReading = 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(){

  // Set up the LED for output
  pinMode(ledPin, OUTPUT);

  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Particle.variable("pot", potReading );
}

void loop() {

  // 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);
}
Click to Expand
0

Using a switch

0
0
// We will be using D1 to control our LED
int ledPin = D2;

// Our button wired to D3
// We wire D0 to the middle terminal on the switch
// And any of the two other terminals to ground
int switchPin = D3;

void setup()
{

  // For input, we define the
  // switch as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

  pinMode( switchPin , INPUT_PULLUP); // sets pin as input

  // We also want to use the LED

  pinMode( ledPin , OUTPUT ); // sets pin as output

}

void loop()
{
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( switchPin );

  // Using a pulldown resistor we get a LOW
  // Signal when its on
  
  if( buttonState == LOW )
  {
    // turn the LED On
    digitalWrite( ledPin, HIGH);
  }else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);

  }


}
Click to Expand
x
Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.


Courses

About

~