Fly Behavior Simulation System


Concept: When you try to swat a housefly, it detects your hand coming towards it and moves out of the way. How does it know? A hypothesis: It detects the rapidly decreasing brightness of the ambient light, and considers that decrease an indication of danger.

Can we simulate that with electronics? Certainly. We need a light sensor, a motor, and some brains. I also added some lights to show us what’s on the fly’s mind.

Circuit Design:


Integrate physical electrical system:

Test each LED with the power supply only.

Connect the Arduino to the computer.

Set the Board: Tools, Board, Arduino Genuino Uno.

Set the Port: Tools, Port, /dev/cu.usbmodem….. (or COM…. in Windows)

Load the Blink Example Code: File, Examples, Basics, Blink

Upload the Blink Code the the Arduino: Sketch, Upload (or click on the right-arrow)

Check that upload was successful, and that the amber LED on the Uno board is blinking.


Test the outputs:


Test the inputs:


Run the threshold code. A fly that is afraid of the dark.


Notice the light sensor signal is very unsteady. Could be that the servo motor, which takes a lot of power, causes the external 5V supply to change. Try unplugging the servo motor to see if that improves stability of the light sensor value.

Improve the circuit by powering the critical sensor separately.

Improve the code to better show the fly’s agitation on the green LED pair.