0% found this document useful (0 votes)
21 views5 pages

AC Motor Speed Control Code

This document contains the source code for a project that controls the speed of an AC motor using an Arduino. The code initializes an LCD display to show the motor status and speed. It reads the position of a switch and potentiometer to turn the motor on and off and adjust its speed, which is displayed on the LCD. When the switch is closed, an interrupt is attached to pulse the triac at a rate corresponding to the potentiometer reading to control motor speed.

Uploaded by

ya vika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

AC Motor Speed Control Code

This document contains the source code for a project that controls the speed of an AC motor using an Arduino. The code initializes an LCD display to show the motor status and speed. It reads the position of a switch and potentiometer to turn the motor on and off and adjust its speed, which is displayed on the LCD. When the switch is closed, an interrupt is attached to pulse the triac at a rate corresponding to the potentiometer reading to control motor speed.

Uploaded by

ya vika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Project Source Code

###

//Program to

#include <LiquidCrystal.h>//import the LCD library

LiquidCrystal lcd(13, 12, 6, 5, 4, 3);// Pins used for RS,E,D4,D5,D6,D7

#define triacPulse 10

#define SW 7

int x=0;

void setup() {

[Link](9600);

[Link](16,2);//LCD 16x2 initialization

pinMode(2, INPUT);

digitalWrite(2, HIGH); // pull up

pinMode(triacPulse, OUTPUT);

pinMode(SW, INPUT);
digitalWrite(SW, HIGH);

[Link](0,0); //Initially set the cursor position of LCD to 1st Columb 1st row.

[Link]("Engineers Garage");//After initialising print data

[Link](0,1); //Initially set the cursor position of LCD to 1st Columb 2nd row.

[Link](" "); //print blank to clear all the data on LCD

delay(3000);

[Link](0,0);

[Link](" SPEED CONTROL ");

[Link](0,1);

[Link](" AC MOTOR ");

delay(3000);

[Link](0,1);

[Link](" ");

void loop() {
[Link](0,0);

[Link](" AC MOTOR ");

// check for SW closed

if (!digitalRead(SW)) {

x=analogRead(A0);

// enable power

attachInterrupt(0, acon, FALLING);

[Link](11,0);

[Link]("ON ");

[Link](6,1);

[Link]((analogRead(A0) * 7) + 200);

} // end if

else if (digitalRead(SW)) {

detachInterrupt(0); // disable power


[Link](11,0);

[Link]("OFF ");

[Link](0,1);

[Link](" ");

} // else

} // end loop

// begin ac int routine

// delay() will not work!

void acon()

delayMicroseconds((analogRead(A0) * 7) + 200); // read AD1

digitalWrite(triacPulse, HIGH);

delayMicroseconds(50);
// delay 50 uSec on output pulse to turn on triac

digitalWrite(triacPulse, LOW);

###

Common questions

Powered by AI

The setup function incorporates delays using `delay(3000)` to display introductory messages such as 'Engineers Garage', 'SPEED CONTROL', and 'AC MOTOR' on the LCD for 3 seconds each. These deliberate delays serve to communicate the purpose and current readiness of the device to the user, enhancing user experience by making clear system status before regular operation. Such intro messaging establishes user confidence in the device readiness, reducing operational errors by providing immediate feedback, though it temporarily delays immediate access to the main functionality .

The code employs `attachInterrupt()` function to enable an interrupt on pin 2 that triggers the `acon()` function upon a falling edge signal. This interrupt service routine (`acon`) controls the timing of the triac pulse. Within `acon()`, `delayMicroseconds((analogRead(A0) * 7) + 200)` calculates a delay based on the analog value, which sets the delay for firing the triac. This allows precise control over the timing of triac activation, adjusting the motor speed. The timing is critical as `delay()` cannot be used inside interrupt routines, hence `delayMicroseconds()` is suitable for the necessary precision .

The use of `digitalWrite()` is pivotal for setting initial states of input and output pins, especially for configuring the triac control and switch inputs. In `setup()`, `digitalWrite(SW, HIGH)` enables the internal pull-up resistor for the switch input to ensure a default high state, preventing floating input states. Similarly, during triac control within `acon()`, `digitalWrite(triacPulse, HIGH)` and `digitalWrite(triacPulse, LOW)` are used to generate a pulse necessary to trigger the triac, marking the start and end of a pulse period. This ensures reliable operational states for subsequent operations .

The `detachInterrupt()` function is used to disable the interrupt associated with the `acon()` function whenever the switch SW is not pressed, ensuring that triac firing is only active when required. This function is invoked in the `loop()` when the condition `digitalRead(SW)` evaluates to true, indicating the switch is open, resulting in no need for continuous triac control. By disabling the interrupt, unnecessary processing is avoided thus reducing power consumption and avoiding undesired motor operation when the system is not engaged .

In the initial `setup()` process, the code configures several components for operation. It begins serial communication with `Serial.begin(9600)` and sets up the LCD with `lcd.begin(16,2)`. Input pins for the switch and triac pulse are configured using `pinMode()` and `digitalWrite()` for pull-up configurations. Initial messages are displayed on the LCD for 3 seconds each to signify readiness and the purpose of the system ('SPEED CONTROL' and 'AC MOTOR'). This setup prepares the pins and displays relevant information, setting a foundation for the main loop execution where monitoring and control occur .

Using `attachInterrupt()` without implementing debounce techniques could lead to unpredictable behavior due to multiple triggerings caused by switch bounce or noise on the line, potentially resulting in multiple, rapid unwanted executions of the `acon()` interrupt service routine. This could lead to inconsistent triac firing causing irregular motor speed control and potential wear. In this application, ensuring precise and stable operation is crucial, thus necessitating debounce logic or hardware to avoid erroneous interrupts, particularly when managing sensitive components like triacs in speed control systems .

The code reads from an analog pin A0 to obtain a value that is proportionally used to determine the firing angle of the triac by modulating the delay in the `acon()` function. This delay is calculated as `delayMicroseconds((analogRead(A0) * 7) + 200)`, where the analog value dictates the time prior to the triac pulse's issuance, thereby controlling its firing angle. By adjusting the firing angle, the power delivered to the AC motor is modulated, effectively controlling its speed. This dynamic adjustment allows for precise motor speed control based on analog input .

The code uses the LiquidCrystal library to interface with a 16x2 LCD module by first including the library with `#include <LiquidCrystal.h>`. It initializes the LCD in the `setup` function with `lcd.begin(16,2)`, specifying a 16x2 display. The LCD is then controlled using the `lcd` object's methods, such as `lcd.setCursor()` to position the cursor and `lcd.print()` to display messages. The pins used for the LCD are defined during the creation of the `LiquidCrystal lcd` object with specific pin designations for RS, E, D4, D5, D6, and D7 .

The LiquidCrystal LCD is used to convey system status by displaying messages on its two lines. Under normal operation, the message 'AC MOTOR' is shown on the first line. When the switch SW is closed, the second line displays 'ON' along with the calculated speed value, derived from the analog reading. Conversely, if the switch is open, the second line displays 'OFF', indicating the system is not controlling the motor. This allows a quick visual reference for users to understand the current status and operational parameters of the system .

The mechanism employed involves using the `analogRead()` function to read an analog signal from pin A0, which is presumed to be connected to a control device like a potentiometer. This value is used to calculate the pulse delay required to trigger the triac, affecting the firing angle and hence the power supplied to the motor. This is performed in the `acon()` function, where `delayMicroseconds((analogRead(A0) * 7) + 200)` calculates the delay based on the analog input. The `attachInterrupt()` on pin 2 enables the `acon` interrupt function useful for precise timing required for the triac triggering .

You might also like