In this tutorial, you will learn how to control a 220V light bulb from 5V Arduino using a relay.
Parts Required
- Arduino
- Relay
- Jumper wires
- Light Bulb
- Breadboard
Circuit
Code
void setup() {
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
delay(2000);
digitalWrite(2, LOW);
delay(2000);
}
The code shown will turn the light on and off at 2-second intervals, if you want to put a button to control it just add a digital input.
References
[1] https://forum.arduino.cc/t/arduino-hangs-when-connecting-220v-to-relay-board/609411