Need to trigger timer relay only once per action using a Magnet Ring Sensor

I am attempting to setup a program using the Arduino Uno paired with a Sunfounder Magnet-ring Sensor (Pin 2) and a 12v home automation type Timer Relay (Pin 8) to trigger an LED change on a display. The trigger for the action is a basket with magnet on bottom being set on the surface of the counter in a particular position. This would then trigger the Relay only once until the basket is removed from the counter. Due to the demonstration that this project is being created for the time the basket is on the magnet sensor may vary between 30 sec to 5 min. In my research I am not finding a good code line to accomplish this. Any help would be appreciated.

I tried to follow this, but the parts do not seem to jump out at me.

you have a basket with magnet you have a metal detector (magnet ring)

set the basket with magnet down on the counter ( is that a table surface or is that an increment thing) in addition to the counter, you are using the magnet ring. so, you set the basket on the counter and the LED lights.

there is a timer relay that gets triggered, and the relay start timing.......

someone comes along between 30 seconds and 5 minutes and moves the basket on the magnet sensor......

nope, not able to follow what you are trying to do.

it sounds like the programming is simple

if the basket is on the counter, then light the LED

if the basket is removed, turn the LED off.

My apologies for the confusion. Let me break this down better.

Hardware: - arduino uno - sun founder magnet-ring sensor (pin 2) - home automation style 12v relay timer (pin 8)

Setup: - Cabinet with magnet-ring sensor embedded into the counter top. - Plastic shopping basket with magnetic tape placed around perimeter. - (2) separate LED lights. - (1) hooked to the NO side of the relay - (1) hooked to the NC side of the relay.

Desired results: 1. Basket is placed on cabinet top triggering the magnetic sensor. 2. Relay triggers for 3 seconds switching one set of LED lights on while turning a second set of led lights off to indicate an action is taking place. This should only happen once each time the basket is place on the cabinet top.

Issues: - Basket may remain on cabinet for variable length of time. This keeps triggering the relay timer in simple code that I have tried based on a few books and research I have done on this site.

jeashwor: Basket may remain on cabinet for variable length of time. This keeps triggering the relay timer in simple code that I have tried based on a few books and research I have done on this site.

Which code you have failed to follow the first rule of posting here by not revealing, so nothing else can be done for you. Before proceeding further, read the "How to" sticky at the top of the listing page.

read button.

it shows how you see if the button is high then if the value was high last scan

if (switch == high){ if (switch != switchLastTime){ switchChanged=HIGH; } } switchLastTime=switch

that will keep switchLastTime to be equal to the value of the switch. on the very first scan that the switch changed, the two will not be equal and only one time. then you can set switchChanged to HIGH

now, layer that with an additional line

if (switch == high){ if (switch != switchLastTime){ switchChanged=HIGH; ** snapshot=millis();** ** digitalWrite(relay,HIGH){** } } switchLastTime=switch

so now, you have set three things.

if (switch==HIGH){ if (millis()-snapshot > 3000 ){ // 3 seconds digitalWrite(relay, LOW); } }

if the switch is high AND snapshot is greater than 3 seconds, then it will turn the relay off.

this will require that the switch goes low to reset the *switchLastTime * to LOW then the next time the switch goes HIGH, it all stars over.