LV-MAXSONAR-EZ

Hi everyone,i have the circuit you can see at the attachment.
i would like to help me with the code please.
i have a nano , a sonar and a load .
i need,whenever the sonar detects distance between 50 cm to 3 meters to turn the load on for 2 seconds and then off till the next time that the sonar detects that distance .
Thank you very much

I've deleted your other cross-post @giannakou.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.