As an Amazon Associate we earn from qualifying purchases.
This project simulates an AC motor whose speed and direction change automatically in response to two environmental inputs: gas concentration and temperature. It is the kind of logic used in ventilation and exhaust fans, where the fan should run harder when the air is hot or contaminated, and sometimes reverse to push air in the other direction.
The video below shows the simulation. The rest of this article explains how a system like this is normally built, what each part does and what to check when you build or simulate your own version.
What bidirectional speed control means
“Bidirectional” here means the motor can turn clockwise or anticlockwise. “Speed control” means the motor does not simply switch on and off; it runs at different speeds depending on a condition. Combining the two gives a motor that can change both how fast it turns and which way it turns.
In this design the condition comes from sensors. Temperature normally sets the speed, while the gas reading acts as a higher-priority input that can force the motor to full speed or change its direction.
Block diagram of the system
Most versions of this project share the same building blocks:
- Temperature sensor: a device such as the LM35 gives an analog voltage that rises with temperature (10 mV per °C for the LM35).
- Gas sensor: an MQ-type sensor gives an output that rises as gas concentration increases. In a simulation, a variable source or a pot often stands in for it.
- Microcontroller: reads both signals through its analog inputs, compares them to set thresholds and decides speed and direction.
- Direction switching: relays (or a relay module) reverse the connection of the motor winding.
- Speed control stage: a triac with a zero-crossing detector, or a variable frequency drive, changes the power delivered to the motor.
- Display and indicators: an LCD, LEDs or a buzzer show the readings and the current state.
How the control logic works
Temperature sets the speed
The microcontroller converts the sensor voltage to a temperature value. A simple approach divides the range into steps. Below the first threshold the motor stays off, between the thresholds it runs at low or medium speed, and above the highest threshold it runs at full speed. Stepped control is easier to test than a continuous curve, and it avoids the motor constantly hunting up and down around one value.
Gas level overrides the temperature
Gas detection is a safety input, so it should take priority. When the gas reading passes its limit, the program can ignore the temperature, drive the motor at full speed and switch on a buzzer. If the design uses direction reversal, this is also the point where the fan can be turned to exhaust mode.
Direction changes need a safe sequence
Reversing a running AC motor directly can cause high current and mechanical stress. A safer sequence is:
- Reduce the speed command to zero.
- Wait until the motor has slowed or stopped.
- Switch the direction relays.
- Ramp the speed back up.
Never energize the forward and reverse relays at the same time. In code, this means turning one off before the other turns on. In hardware, many builders add an interlock for extra protection.
How the motor is reversed and slowed
The method depends on the motor type. Single-phase capacitor motors, such as a permanent split capacitor (PSC) motor, reverse by changing which winding the capacitor is in series with. This is why a relay pair works well for them. You can see this principle in a separate article on the direction control of a PSC AC motor. For a three-phase induction motor, reversal is done by swapping two of the phase connections, as described in an article on the bidirectional rotation of an induction motor.
For speed, the common low-cost method for fans and similar loads is phase-angle control with a triac. The microcontroller detects each zero crossing of the mains waveform and delays the triac firing pulse by a set time. A longer delay means less power and lower speed. If you want to see how that is done in practice, read about triac based speed control of a home fan. Keep in mind that phase control suits fans and blowers well, but not every AC motor, so check the motor type first.
Simulation tips
Simulating before building lets you test the logic without touching mains voltage. Some practical points:
- Test the sensors alone first. Vary the temperature and gas inputs and confirm the microcontroller reads sensible values.
- Use LEDs or a lamp to represent relay states before connecting the full motor model.
- Check the threshold behavior at both sides of each limit, and add a small hysteresis so the output does not flicker.
- Verify that the direction change never happens while the speed output is high.
If you want to practice the sensor side on its own, a gas sensor simulation in Proteus is a good starting point. To compare with a simpler controller, see this example of speed control of AC motor using Arduino.
Limits of a simulation
A simulation shows that the logic works, but it does not capture everything. Real gas sensors need warm-up time and calibration, and their readings drift with humidity and age. Real motors draw a high starting current, and relays and triacs need proper ratings and snubbers. A simulated gas sensor also cannot replace a certified gas detector in any real safety application.
Safety when moving to hardware
- Isolate the microcontroller from mains using optocouplers or relay modules with isolation.
- Choose relays and triacs rated well above the motor’s running and starting current.
- Fit a fuse and use an enclosed, insulated build.
- Do not work on the circuit while it is connected to mains power.
FAQ
Why use both gas and temperature sensors?
Temperature gives a gradual reason to change speed, while gas gives an urgent one. Using both lets the motor respond smoothly in normal conditions and aggressively when air quality becomes a problem.
Can any AC motor be controlled this way?
No. Triac phase control works for fans and some single-phase motors. Three-phase induction motors normally need a variable frequency drive for speed control. Always match the method to the motor type.
How is the motor direction reversed?
Usually with relays. For a single-phase capacitor motor, the relays change the winding the capacitor connects to. For a three-phase motor, they swap two phases.
Is it safe to build this on mains power?
Only with proper isolation, correctly rated parts and care. If you are not experienced with mains wiring, stay with the simulation or use a low-voltage motor for testing.