I want to connect one ultrasonic sensor to a servo motor and I want the servo rotate from 0 degree to 180 degree continuously when ultrasonic detects no body the servo has to continue its motion.
And After the ultrasonic detected someone so then it stops the servo and play a sound.
One sound for the morning time and one for afternoon and one for evening time.
Thanks in advance
maybe hes blind.
poor guy. I can t help without a pice of code or pictures.
Make a screenshot or more details please
Although it seems easy, this is actually a pretty complicated program.
You will likely have trouble getting distance readings if you ping while servo is moving your range-finder, so for starters, you will need to decide how far to move the servo for each check, move the servo, check range, check result, move servo another “step”, repeat. In order to perform steps in order & change what is done based off distance sensor, you are going to need to understand using pulses to control program flow. https://xod.io/docs/guide/simple-traffic-light/ provides an introduction to this. https://xod.io/libs/gweimer/traffic-light-advanced/ provides a deeper-dive, including use of branch nodes to change what action is taken.
In order to determine morning/afternoon/evening, you are either going to need an RTC (Real Time Clock), or you will have to guestimate what time it is based off time since boot, or maybe a light sensor.
Trying to play sounds is a whole other topic. You can use additional hardware to play back recorded sounds, or just use a speaker to play single notes using PWM. There are probably plenty of examples for the latter if you do a web search.