It's tough to imagine God sending trouble, but the Bible presents a God who sometimes uses hardship not out of anger, but out of love and a desire for restoration.
The calamities mentioned – no rain, locusts, pestilence – are not arbitrary punishments. In the context of the covenant (explained more fully in Deuteronomy), these are forms of discipline.
God's Heart for His People
God's discipline is corrective. It's meant to get our attention, to show us the consequences of straying from Him, and to drive us back to repentance and reliance on Him. It's like a loving parent who has to discipline a child to guide them back to safety and health.
It's crucial to distinguish this from divine abandonment. The very fact that God speaks of these as actions He might take, rather than things He allows to happen out of His hands, shows His continued engagement with His people.