Hiya,
I've been using this forum for a little while for a few small projects, however being a novice still I'm having trouble with this one and am very short for time, so would like to ask for some help! ![]()
The function of the project is to replicate the process of activating a distress beacon.
An accelerometer and thermistor provide a value, and if this value goes out of a "safe range" (eg above 50 degrees or below-10), or if a large shock is detected, then an LED 1 illuminates (this is an alarm on the distress beacon).
If the user does not press a button to turn the LED 1 off (disabling the alarm on the distress beacon) within 5 seconds, then the LED 1 turns off, and LED 2 turns on (which would mean that the distress signal is sent in the real product).
So when LED 1 is on, the idea is that you can press a button (the "I'm OK") to prevent the distress signal being sent out (LED 2 turning on), and it loops back to monitoring the thermistor/accelerometer. If you don't press the button within 5 seconds, then LED 2 turns on automatically.
I've got the accelerometer/thermistor working to illuminate LED 1.
But I am stuck with the rest, and am just going round in circles making silly mistakes. If someone could help it would be much appreciated. Bear in mind that I am very new to this so fully explaining everything would be very helpful!
My code so far is here:
int accelerometer = 2; // accelerometer
int thermistor = 3; // thermistor
int LED1 = 11; // activation LED
int LED2 = 10; // signal sent LED
int button = 9; //disable button
int delay1 = 1;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(thermistor, INPUT);
pinMode(button, INPUT);
pinMode(accelerometer, INPUT);
}
void loop() {
// read the value from the sensor:
int acc = analogRead(accelerometer);
int therm = analogRead(thermistor);
// Can convert to volts if easier using: analogRead(thermistor) * (5/1023)
Serial.begin(9600);
Serial.print(acc); Serial.println(therm);
while (acc > 10) digitalWrite(LED1, HIGH); //this value can be upto 1023 (this is the nalog input converted to digital signal)
while (acc < 1) digitalWrite(LED1, HIGH);
while (therm > 10) digitalWrite(LED1, HIGH);
while (therm < 1) digitalWrite(LED1, HIGH);
if (delay1 < 3000) ;
if (button == HIGH) ;
digitalWrite(LED1, LOW); //PRESS DIABLE BUTTON TO DEACTIVATE
if (delay1 > 6000);
{ digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH); }
delay1 = delay1 + 1;
}
Many thanks
Joe
(moderatore update: added code tags)