Skills Dev II- Working with Inputs and Sensors

Made by Darshil Shastri

My goal is to develop a circuit using 3 components- input, sensor, output.

Created: November 26th, 2023

0

Exercise 2.1- Get the LED light to blink after pushing a button and having a potentiometer.

In this circuit, I am going to be using a potentiometer and a button to light up the LED. 

0
//writing the code to have button input and potentiometer input

// name and assign the pin

int led = D2;
int buttonPin = D3; 
int buttonState; //Store the reading from Button


void setup() {
    
    pinMode( led, OUTPUT );
    pinMode (buttonPin, INPUT_PULLUP);

}

void loop() {
   
   buttonState = digitalRead(buttonPin);

   if (buttonState == LOW) {
       digitalWrite (led,HIGH);
   }else{
       digitalWrite (led,LOW);
   }   
  
  delay(500);

}
Click to Expand
0
0

Exercise 2.2- Using a flex sensor, 2 LEDs and a button.

Objective- Here, I'm trying to see the difference in pressure after the button is pressed. So there is a threshold, below which the Green LED will light up, and after the bend is increased, the Orange LED will light up. The button has to be pressed at all points for this to work. Its practically like building a maximum weight alert device.

0
0

The code for the following is given below:

0
//writing the code to have button input and flex sensor input

// name and assign the pin

int led = D2;
int led2= D5;
int buttonPin = D3; 
int buttonState; //Store the reading from Button
int flexPin = A2; //store data from Flex sensor


void setup() {
    
    pinMode( led, OUTPUT );
    pinMode (led2,OUTPUT);
    pinMode (buttonPin, INPUT_PULLUP);
    pinMode (flexPin, INPUT);

}

void loop() {
 
 int flexValue = analogRead(flexPin);
 
   buttonState = digitalRead(buttonPin);

   if (buttonState == LOW) {
       if (flexValue >=150){
       digitalWrite (led,HIGH);
       digitalWrite(led2,LOW);
       }
       else {
           digitalWrite (led,LOW);
           digitalWrite (led2,HIGH);
       }
      
   }else{
       digitalWrite (led,LOW);
       digitalWrite(led2,LOW);
   }   
  
  delay(500);

}
Click to Expand
0

Reflection- I think the key here was to find the range over which the code worked. It took me a while, by trial and error to find the exact bend number which will make the both the LEDs blink. 

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

My goal is to develop a circuit using 3 components- input, sensor, output.