Won’t miss sensor state change

Hello,

For example, I want to add a hall sensor to my arduino project. As I see code samples, I have to read the sensor continuously and check whether it’s state changed or not

What if I use other modules with that arduino? So will I miss hall sensor state changes while I send data via gprs module within the same arduino? How to avoid it?

Thanks,

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in https://forum.arduino.cc/c/using-arduino/uncategorized/184.

if you awaitig a very short pulse, that may disapear while GPRS module send something, then you need bi-stable latch element, that wil set by sensor and after arduino notice new state, the latch will be resetted.
using interrupt probably may corrupt GPRS transmission, test needed.

What if I use a second arduino to control the hall sensor and then connect it with the first one? So the first arduino is not interrupted while sending data via gprs module

Is it a solution for my task?

Thanks,

Usually using two Arduinos is not a solution; it complicates things. How do you visualise that you will not miss a pulse (I assume that the sensor data has to go in the GPRS message) in the Arduino that is sending the gprs messages.

Your question is to broad; if you're more specific about your current project and how the addition of a hall sensor fits in, it will help.

How many pulses per second do you expect to get from the hall sensor?
What else is involved in your project?
How long are the GPRS messages? How often do you send them
Which board are you using?

Just to give you some background information for e.g. Uno. If you send data to a GPRS module over Serial, that data is buffered (read: stored somewhere in RAM).

  1. The first byte will be fetched from the buffer and transmitted.
  2. Once the byte is transmitted, an interrupt routine will read the next byte from that buffer and transmit it.
  3. The above step (2) repeats till all byes of the data are transmitted.

The mentioned buffer does not have an unlimited size (it's 64 bytes for an Uno). Once the buffer is full your code will hang till there is space in that buffer to add a new byte of the data to it. So sending e.g. a 40 byte message immediately followed by e.g. another 40 byte message (or e.g. sending one 70 byte message) will halt the processing of the rest of your code.

Regarding the hall sensor the question is how accurate you need to know the pulses. Let's say that you get 100 pulses per second for a speedometer; does it really matter if the indicated speed is e.g. 20 km/h or occasionally is indicated as 19.9 km/h?

If you don't want to miss any pulses from the hall sensor, I would use an interrupt for the hall sensor. You can use it to e.g. count pulses or just to set a flag indicating that a pulse was detected.

Interrupts have a priority and while an interrupt service routine (ISR) is in progress other interrupts are blocked; so routines that handle interrupts need to be short. But while an ISR is in progress, the fact that another interrupt occurred is recorded so as soon as the current ISR is finished the next needed ISR will do it's job.

I do not think that your gprs cares too much if a byte is not immediately received after the previous byte; to my knowledge they react on the endmarker ('\n' and/or '\r') and maybe have a timeout.

My project is a wheather station

My current arduino has 3 temp sensors and send its data to my server by interval

Now I would want to add a rain meter, so hall sensor ticks and counter adds on. These ticks would be sent to the server as well.. Every tick is 0,1mm of rain approx. Not fast tick at all, but I wouldn’t want design it so it can miss them

That’s it..
Thanks a lot for all your replies

The only thing I can give you is arduino hall sensor example interrupt - Google Search.

At 9600 baud, the transmission of a byte takes roughly 1 millisecond. Now it depends a little on the processor that you use; you will need to check the datasheet.

For a 328P (as used on an Uno or Nano) and the 2560n (Mega), external interrupts and pin change interrupts have a higher priority so between the transmission of the bytes to the gprs these interrupts will be honoured (as said, they are latched).

So every 1 millisecond an interrupt can be honoured. That means a theoretical rain measurement of 0.1mm / millisecond (10cm / second).

If your board has a spare UART (and you use that for communication with the gprs) you can use external interrupts or pin change interrupts. If you use a board based on the 328P and you're using SoftwareSerial, pin change interrupts will be slightly problematic as SoftwareSerial claims all of them by default; so you either need to hack the SoftwareSerial library or are use to use pins 2 or 3.

if you have interval you can in this time do the measurments, and at all the whole thing is not big deal bc wether not changing every microseconds

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.