# jump values ?

Hi friends. how can I writing program for jumping values? for example " if analog A1 values jumps from 100 to 400 then turn on LED " ?

thanks.

The basic idea is going to be read A1, save the value then read A1 again and check the new value against the saved value.

But it depends what you mean by "jump". E.g. does it have to be exactly 100 then go to exactly 400 without reading any other values in between? How fast must it go from 100 to 400? Or do you mean it reads up to 100 and at least 400? All of these will affect how you write the code.

Steve

slipstick:
The basic idea is going to be read A1, save the value then read A1 again and check the new value against the saved value.

But it depends what you mean by "jump". E.g. does it have to be exactly 100 then go to exactly 400 without reading any other values in between? How fast must it go from 100 to 400? Or do you mean it reads up to 100 and at least 400? All of these will affect how you write the code.

Steve

thanks for reply. I need this code for EMF detector the A1 normal values is between 100 to 150. now when EMF becomes more than 400 turning ON the LED.

Post your code that reads those values you quoted. What have you tried so far to switch the LED on?

You've said when the LED switches on. Does it ever switch off again? If so what causes that?

Steve

slipstick:
Post your code that reads those values you quoted. What have you tried so far to switch the LED on?

You’ve said when the LED switches on. Does it ever switch off again? If so what causes that?

Steve

the LED is turned ON for 30 sec,

the sketch:

``````void loop() {
if (val >= 1) {
val = constrain(val, 1, senseLimit);
val = map(val, 1, senseLimit, 1, 1023);
index = (index + 1);
index = 0;
//Serial.println(average);
if ((average >= 100) && (average <= 400)) {
digitalWrite(LED1, HIGH);
delay(30000);
reboot();
}
}
}
``````

Hi,
What is reboot?
Why can you just turn the LED off after 30 seconds and restart your count.
What is the application, what will this code eventually do, control,display for what purpose?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks... Tom..

TomGeorge:
Hi,
What is reboot?
Why can you just turn the LED off after 30 seconds and restart your count.
What is the application, what will this code eventually do, control,display for what purpose?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom…

I attached the circuit. there is no LED in my circuit the LED is MOSFET
this circuit sensing the EMF and when EMF reached to 400 then turning ON the MOSFET ( mosfet connected to SIM800L and ATMEGA328 ) for 30 seconds then rebooting the code just for stability. the bluetooth is for serial monitoring.

here the full code:

``````#include <avr/wdt.h>

int senseLimit = 5;
int probePin = A2;
int val = 0;
int LED1 = 1;
int LED2 = 0;
int LED3 = 2;
int LED4 = 3;
int ANT = 4;
int index = 0;
int total = 0;
int average = 0;

void setup() {
wdt_disable();
//Serial.begin(9600);
digitalWrite(LED1, LOW);
pinMode(ANT, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
for (int i = 0; i < NUMREADINGS; i++)
}
void loop() {
if (val >= 1) {
val = constrain(val, 1, senseLimit);
val = map(val, 1, senseLimit, 1, 1023);
index = (index + 1);
index = 0;
//Serial.println(average);
if ((average >= 100) && (average <= 400)) {
digitalWrite(LED1, HIGH);
delay(30000);
analogWrite(A2, 1);
delay(1000);
reboot();
}
}
}

void reboot() {
cli();
WDTCR = 0xD8 | WDTO_1S;
sei();
wdt_reset();
while (1) {}
}
``````

Hi,
OPs circuit.

Is that really your component content or are you using a UNO?
Where is the EMF sense wire and what are the pins on the 328?
Why are you using pins 0 and 1 in your code, they are the programming pins?

Tom...

TomGeorge:
Hi,
OPs circuit.

Is that really your component content or are you using a UNO?
Where is the EMF sense wire and what are the pins on the 328?
Why are you using pins 0 and 1 in your code, they are the programming pins?

Tom...

it's my real circuit :)) EMF sense is ATTINY pin 4 ( yellow wire )
the pin 0 is for serial monitor and pin 1 for MOSFET switch.
the 328P sending SMS with sim800L

TomGeorge:
Hi,
OPs circuit.

Is that really your component content or are you using a UNO?
Where is the EMF sense wire and what are the pins on the 328?
Why are you using pins 0 and 1 in your code, they are the programming pins?

Tom...

thanks you answers my question, with questions

Hi,

I need this code for EMF detector the A1 normal values is between 100 to 150. now when EMF becomes more than 400 turning ON the LED.

If you need this response then this will not do it.

``````if ((average >= 100) && (average <= 400))
``````

This will;

``````if (average >=400)
``````

Tom…

TomGeorge:
Hi, If you need this response then this will not do it.

``````if ((average >= 100) && (average <= 400))
``````

This will;

``````if (average >=400)
``````

Tom…

thanks for help. is any way to do it when the values jumping ? for example in normal mode Values from 100 to 400 are slowly changing but the LED must be keep OFF and when the values suddenly jump from 100 to 400 then turn ON LED ?

Hi,
You will need to store your previous value and compare it to your new value, to see if you have jumped from <100 to >400.

Tom…

TomGeorge:
Hi,
You will need to store your previous value and compare it to your new value, to see if you have jumped from <100 to >400.

Tom…

can you tell me how ? I don’t know how to store the values

What you want to do is shown in the state change detect tutorial, except that instead of high and low there, you are concerned with >400 and under 100.

So if previousValue (which in the example they have as lastButtonState or something, since it’s about buttons there) is <100 and currentValue > 400, it jumped in one shot so do your thing.