SDII Inputs and Sensors
Made by Tyler White
Made by Tyler White
Work with inputs and sensors
Created: December 15th, 2023
Write about the big ideas behind your project? What are the goals? Why did you make it? What are your motivations?
No big ideas, just working with the two sensors. I started by using the button. The button to me seemed like the most obvious sensor to use / try out. The force sensor was more because it looked cool and I talked with other students about incorporating it.
Detail what you created. What methods or techniques did you use? What tools and technologies were involved? Include images, code or video.
For part one implementing it was pretty straight forward. I just connected the button to one of the LED lights and it worked pretty easily. The force sensor was a bit more tricky. I figured out how to get it to work but I was trying to set it up so the lights would alternate when the sensor was triggered and that gave me a bit of trouble for a while but I was able to get it to work.
//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
//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);
delay (100);
digitalWrite (led,LOW);
digitalWrite(led2,HIGH);
delay (100);
}
else {
digitalWrite (led,HIGH);
digitalWrite(led2,LOW);
delay (3000);
digitalWrite (led,LOW);
digitalWrite(led2,HIGH);
delay (3000);
}
}else{
digitalWrite (led,LOW);
digitalWrite(led2,LOW);
}
delay(500);
}
Click to Expand
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Work with inputs and sensors