Advertisement
microrobotics

C 220V Line Sensor, Isolated, 24V Output

May 10th, 2023
1,874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 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.
  3.  
  4. 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.
  5.  
  6. 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.
  7.  
  8. Here is a simple example code for Arduino:
  9. */
  10.  
  11. #define SENSOR_PIN 2 // Connect the sensor output to Arduino digital pin 2
  12.  
  13. void setup() {
  14.   pinMode(SENSOR_PIN, INPUT);
  15.   Serial.begin(9600); // Start the serial communication with the baud rate of 9600
  16. }
  17.  
  18. void loop() {
  19.   int sensorValue = digitalRead(SENSOR_PIN); // Read the value from the sensor
  20.  
  21.   if (sensorValue == HIGH) {
  22.     Serial.println("220V AC present");
  23.   } else {
  24.     Serial.println("No 220V AC detected");
  25.   }
  26.  
  27.   delay(1000); // Delay a bit to make it more readable
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement