How to turn off a sensor for 1 hour and turn back on for 5 mins and repeat?

Hi, I am wanting to use my sensor for 5 mins and then turn off for an hour so that the sensor is not running for too long . The sensor can't run for continuous power so I am wanting to turn it off. I have looked everywhere online for help but I am not able to find any websites that show me how this can be done. So a link to a website or a short example will be very helpful. Thank you.

Look for examples of using a relay to turn something on and off.

What sensor? How is it powered? Provide a link if possible.

Do you also want to sleep the microcontroller as well or just the sensor?

It is a chemical sensor, here is the link:

I am using an arduino uno and i just want the sensor to sleep.

Since you must power the sensor for some time period before using it, Just turn off the heat element power and it will go to sleep. What is your application?

Here is an Idea for you

You could have a MOSFET that connected the sensor to the analog or digital pin. To make the connection you would supply voltage to the middle pin for 5 mins then after that set the middle pin of the MOSFET to low and the gate will be closed and the sensor will be turned off for an hour then you open the gate of the MOSFET to allow the sensor to be activated again.

How would i do this with a code?

I am hoping to just work with what i have, which is the arduino and sensor.

Depends what else your code needs to do... bit hard to tell cos you haven't shared it.

ugly but simple...

void loop()
{
  [turn on sensor] 
  delay (5 * 60 * 1000);  // 5 minutes

  [turn off sensor]
  delay(60 * 60 * 1000); // 60 minutes
}

How to turn it ON and OFF, depends on how much power it uses. The UNO can't supply much at all so typically you use something else to switch things on and off... like a transistor, or a relay module.

@red_car Thank you! This is closer to what I am wanting. I also have a keypad so I was thinking that if I press a button like "*" on the keypad then the sensor will start and when i press it again then it will stop. Would this be something that can be done? If so, would you be able to show a sample code for it?

The problem with the original code I suggested is the the "delay" statements block the code.. so effectively nothing else can happen. There are better ways to do this type of time based logic using millis(). If you look as the example sketches Blink (uses delay) and BlinkWithoutDelay (uses millis) you can see the different techniques.

If you are using some kind of button or keypad then you can use digitalRead to see if an input pin is HIGH or LOW, and use that to turn your sensor on or off.

Suggest having a look at the example Button sketch.

Examples sketches can be found in the IDE under menu "File" > "Examples"

Ok Thank you! This was very helpful!

OK, so the "long and short" of this is that to advise you, we need the actual datasheet for this device.

I cannot find it. Do you actually have a datasheet? Do you know how to connect and operate it? If so, how do you know?

You must realise that the sensor takes some time to stabilise once turned on. How does the original device arrange this? How do you propose to take this into account?

Hi I was wondering If you had access to any other electrical components

if so what are they

No, this will overflow int calculations. You need to force long int calculations:

  delay(60L * 60 * 1000); // 60 minutes

That part is somthing else. Bacharach is a sensor manufacturer but type number in the AD is wrong.

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