Many insects are very helpful in a garden. These beneficial insects include parasitic wasps and ladybugs. Predatory insects are important in a garden because they prey on the insects that damage and kill your primary crops. Flowers; such as daisies, marigolds, zinnias and black-eyed Susans; attract beneficial insects.
Some flowers are repellent to bugs. Some of these same flowers form the basis for certain organic pesticides. Some gardeners grow repellent flowers, and then use them to make their own organic sprays. Different types of plants repel different types of insects, so choose your flowers based on prevalent pests in your area. Lavender is useful for keeping ants away from the garden. If you have an aphid problem, or if your fruit trees are attacked by borers, grow nasturtiums.
Pollinators are critical for a healthy crop. Flowers attracting a wide variety of pollinators, such as bees, are good for your garden. Opt for a variety of flowers. Bright colors like red, blue and yellow attract pollinating insects that are active during the day. Nighttime pollinators don't notice colors, but flowers that smell strongly are attractive at night. Bees are a good pollinator, and are attracted by flowers like sunflowers, poppies and roses.
Another way to protect your garden with flowers is to plant a trap crop. Trap crops are flowers that attract insects that kill vegetables. By planting a heavy crop of trap flowers, the harmful insects will attack the sacrificial flowers rather than the vegetables that you want to protect. Nasturtium and nicotiana are two useful trap plants for aphids. Four o' clocks work on Japanese beetles.