Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- It has an isolated output and will give a logic HIGH (TTL Level or 3.3-5V) when 220V AC is present and logic LOW when it's not. Therefore, you can simply read the output pin with a digital input pin on your microcontroller.
- This code will continuously read the sensor output and print a message on the serial monitor indicating whether the 220V AC is detected or not.
- Please be extremely careful when working with AC mains voltage. It is potentially lethal and should be handled only by experienced individuals who understand the risks. Always disconnect power before working on a circuit and double-check everything before applying power.
- Here is a simple example code for Arduino:
- */
- #define SENSOR_PIN 2 // Connect the sensor output to Arduino digital pin 2
- void setup() {
- pinMode(SENSOR_PIN, INPUT);
- Serial.begin(9600); // Start the serial communication with the baud rate of 9600
- }
- void loop() {
- int sensorValue = digitalRead(SENSOR_PIN); // Read the value from the sensor
- if (sensorValue == HIGH) {
- Serial.println("220V AC present");
- } else {
- Serial.println("No 220V AC detected");
- }
- delay(1000); // Delay a bit to make it more readable
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement