HC-SR04 For Doll house elevator problems

Hi Guys,

I have been working on a Doll house for my kids with a working elevator, 3 levels. After finally getting a program working with the HC-SR04, I decided to build it into the doll house. Unfortunately it seems the sensors is detecting the sides of the elevator shaft instead of the elevator itself. It reads 6-8cm if the elevator is above 13cm. I also think that the elevator will not stay at 90deg in the shaft with kids playing with it. When I tested outside of the doll house the sensor had no obstakels but my hand.

Do you guys have any advice? Another distance sensor, use switches or another form of detection?

See attached images

Thanks!

Lift_Definitief.ino (7.23 KB)

The HC-SR04 indeed will see the first object in its 30° cone, and that can very well be your lift shaft. It also has an error of about 2 cm, so you won't be able to get the lift to line up where it should.

A break beam sensor or microswitch at each level will be MUCH more accurate.