Skills Dev II: Working with Inputs and Sensors_Yulin
Made by Yulin Chen
Made by Yulin Chen
Created: November 6th, 2024
Try to imagine a simple three component sensing device (an LED, a sensor and one additional sensor)
It is very hard to connect two sensors together on the breadboard at first. Because I connected these two as series circuits at first, so it didn't work for a long time, I searched a lot about Arduino circuits to find the solution to achieve this successfully. And I tried to add the piezo but there is not enough space on a single breadboard, so I just tried to write the code to control it and then // them. And I will try after I get another breadboard.
I think combining the bend sensor and force sensor may can be a prototype of the wearable device for finger bending recovery, when the injured finger bends a lot (will be limited in a range based on the Heathcare knowledge) or be pressed a lot which will aggravate the injury, the alert will remind people of taking care of their injured fingers. I think this direction can be my improvement direction in the future.
Condition 1: When the bend sensor is over bending and press sensor is pressed a lot, the piezo’s sound alert will start, and the LED will blink for 1.5s.
Condition 2: When only the bend sensor is over bending, the piezo’s sound alert will start for a short time, and the LED will blink for 0.5s.
Condition 3: When only press sensor is pressed a lot, the piezo’s sound alert will start for a short time, and the LED will blink for 1s.
Condition 4: When nothing on the press sensor and bend sensor, the LED and will piezo’s sound alert keep off.
(Only code about piezo and I will try it on breadboard when I get another breadboard)
// Include Particle Device OS APIs
#include "Particle.h"
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
//sensor
int bendPin = A0;
int bendReading = 0;
int threshold_1 = 500;
int pressPin = A1;
int pressReading = 0;
int threshold_2 = 500;
//output
int ledPin = D1;
int ledBrightness = 0;
//int piezonPin = D3;
//int piezonReading = 0;
void setup() {
pinMode(ledPin, OUTPUT);
//pinMode(piezonPin, OUTPUT);
Particle.variable("bend", &bendReading, INT);
Particle.variable("Press",&pressReading, INT);
}
void loop() {
pressReading = analogRead(pressPin);
bendReading = analogRead(bendPin);
if(bendReading<threshold_1 && pressReading<threshold_2){
//noTone(piezonPin);
digitalWrite(ledPin, LOW);
}
else if(bendReading>threshold_1 && pressReading>threshold_2){
//tone(piezonPin, 1000);
digitalWrite(ledPin,HIGH);
delay(1500);
digitalWrite(ledPin,LOW);
delay(500);
}
else if(pressReading>threshold_2 && bendReading<threshold_1){
//tone(piezonPin, 500);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1500);
}
else if(bendReading>threshold_1 && pressReading<threshold_2){
//tone(piezonPin, 500);
digitalWrite(ledPin,HIGH);
delay(500);
digitalWrite(ledPin,LOW);
delay(1500);
}
else{
digitalWrite(ledPin,LOW);
//noTone(piezonPin);
}
delay(500);
}
Click to Expand