Modelling of Motors : 649479

Question:

We will be modelling the motors (or rather, the switches for the motors) using a set of 3 LEDs – one red, one yellow and one green. So turning an LED on represents the corresponding motor being turned on-Our task is to control the 3 motors.

Inputs via a 12-key keypad that will allow users to select one of a series of preset programs. Each program has a different sequence and timing for the ‘motors’ as described below.

Safety Constraints:

1) Only one motor can be turned on at a time.

2) To minimise current surges during motor switching, there should be a 1 sec delay between one motor turning off and the next being turned on.

3) Emergency stop switch: This will be a push button switch to stop the motors in the event of an emergency. • Motors will not run until the emergency has been cleared by pressing the ‘*’ key on the keypad. • The system will ignore all other inputs while in this ‘emergency’ state. • When resuming normal operation, previous program selection is cleared.

Users should be able to select a new program at any point during the normal operation sequence and the system should switch to the new program, but still comply with the safety constraints above. Even though the ‘user interface’ is limited to the LCD screen and keypad, consider making this as ‘user-friendly’ as possible and extend to include the following and any others of your choice:

  1. User calls up the user defined option by selecting ‘0’.
  2. User enters how long the RED ‘motor’ should be on in minutes and seconds (up to 80 minutes).
  3. User starts program by pressing ‘#’. The appropriate motor is turned on and a ‘countdown timer’ is displayed on LCD showing how long is left before motor turns off.
  4. If the user presses ‘#’ before countdown reaches zero, the program is ‘paused’. The motor is turned off, and the countdown timer stops. Pressing ‘#’ again causes program to resume – motor is turned on and countdown continues.
  5. When countdown reaches zero (0 mins and 0 secs), the motor will stop and system comes out of user program mode. Note: The system still has to comply with all safety constraints stated above.

Answer:

// led_blink.c- Motor Program 1

 

 

#define F_CPU 14745600

 

#include <avr/io.h>

#include <inttypes.h>

 

#include “../libnerdkits/delay.h”

#include “../libnerdkits/lcd.h”

 

// PIN DEFINITIONS:

//

// PC4 — LED anode

 

int main() {

// Port C bit 3,4 and 5 as output

DDRC |= (1<<PC4) | (1<<PC3) |(1<<PC2) ;

 

// loop keeps looking forever

while(1) {

// turn on green Motor (PC2) and turn off others

PORTC |= (1<<PC2);

PORTC &= ~((1<<PC4) | (1<<PC3) );

 

//delay for 4000 milliseconds to let the Motor stay on

delay_ms(4000);

 

// turn on amber Motor (PC3) and turn off others

PORTC &= ~((1<<PC4) | (1<<PC2) );

PORTC |= (1<<PC3);

 

 

//delay for 2000 milliseconds to let the Motor stay on

delay_ms(2000);

 

// turn on red Motor (PC4) and turn off others

PORTC &= ~((1<<PC3) | (1<<PC2) );

PORTC |= (1<<PC4);

 

//delay for 3000 milliseconds to let the Motor stay on

delay_ms(3000);

 

// switch of all Motors

PORTC &= ~((1<<PC4) | (1<<PC3) | (1<<PC2) );

 

}

 

return 0;

}

 

 

// led_blink.c- Motor Program 2

 

#define F_CPU 14745600

 

#include <avr/io.h>

#include <inttypes.h>

 

#include “../libnerdkits/delay.h”

#include “../libnerdkits/lcd.h”

 

// PIN DEFINITIONS:

//

// PC4 — LED anode

 

int main() {

// Port C bit 2,3 and 4 as output

DDRC |= (1<<PC4) | (1<<PC3) |(1<<PC2) ;

 

// loop keeps looking forever

while(1) {

// turn on red motor (PC4) and turn off others

PORTC |= (1<<PC4);

PORTC &= ~((1<<PC2) | (1<<PC3) );

 

//delay for 3000 milliseconds to let the red motor to stay on

delay_ms(3000);

 

//  turn off all motors for 1 sec

 

PORTC &= ~((1<<PC2) | (1<<PC3) | (1<<PC4));

 

//delay for 1000 milliseconds to let all motors off

delay_ms(1000);

 

// turn on green Motor (PC2) and turn off others

PORTC &= ~((1<<PC4) | (1<<PC3) );

PORTC |= (1<<PC2);

 

 

//delay for 3000 milliseconds to let motor stay on

delay_ms(3000);

 

// turn on red LED (PC4) and turn off others

PORTC &= ~((1<<PC3) | (1<<PC2) | (1<<PC4));

 

 

//delay for 2000 milliseconds to let the motor stay on

delay_ms(2000);

 

 

}

 

return 0;

}

 

 

 

// led_blink.c- Motor Program 4

 

#define F_CPU 14745600

 

#include <avr/io.h>

#include <inttypes.h>

 

#include “../libnerdkits/delay.h”

#include “../libnerdkits/lcd.h”

 

/

 

int main() {

// Port C bit 3,4 and 5 as output

DDRC |= (1<<PC4) | (1<<PC3) |(1<<PC2) ;

//switch on the red LED

#include <avr/io.h>

#include <inttypes.h>

 

#include “../libnerdkits/delay.h”

#include “../libnerdkits/lcd.h”

 

  • include <LiquidCrystal.h>
    LiquidCrystal lcd(12,11,5,4,3,2); //pin lcd

const int button1 = 6;            // + Setpoint button
const int button2 = 5;              // – Setpoint button

int setpoint = 0;
int buttonAState = 0;              // Store state of Button1
int buttonBState = 0;              // Store state of Button2
int prss; //value of psi
float prsss; //value of kpa
int motor_start = 13; //dc motor
int prssPin = A0;
int setLimit1 = 100;              // Set limit setpoint KPA = 100
int setLimit2 = 0;                // Set limit setpoint KPA = 0
int pwm = 6;
void setup()
{
{
pinMode (button1, INPUT_PULLUP); // set the button1 pin 10 up as an input.
pinMode (button2, INPUT_PULLUP); // set the button2 pin 9 up as an input.
pinMode(motor_start, OUTPUT); //dc motor as output
}
{
lcd.begin(14,2);
lcd.print(“Smart Pump”);
lcd.setCursor(8,1);
lcd.print(“Portable”);
lcd.display();
delay(2000);
lcd.begin(16,2);
lcd.print(” “);
lcd.setCursor(6,1);
lcd.print(” “);
delay(500); //lcd display for 2 seconds and blink for 0.5 seconds
prss = analogRead(prssPin); //pressure sensor read value of psi
prss = prss / 4.6;
lcd.begin(18,2);
lcd.print(“PSI “);
lcd.print(prss);
lcd.println();
prsss = analogRead(prssPin); //pressure sensor read value of kpa
lcd.setCursor(0,1);
lcd.print(“KPA “);
lcd.print(prsss);
lcd.println();
delay(4000); //display value on 5 seconds
lcd.noDisplay();
delay(300);
}
}
void loop()
{
{
button1State = digitalRead(button1);
if (button1State == 0 && setpoint < setLimit1)
setpoint ++;

button2State = digitalRead(button2);
if (button2State == 0 && setpoint > setLimit2)
setpoint–;

lcd.begin(16,2);
lcd.print(“Setpoint= “);
lcd.print(setpoint);
lcd.display();
delay(100);
prss = analogRead(prssPin);
if (prsss < setpoint)
{
digitalWrite(motor_start, HIGH);
}
else
{
digitalWrite(motor_start, LOW)

I have used the circuit and program that was posted can the website
But it is showing error,
Sketch uses 1074 bytes, max is 32256 bytes.
Global variables use 9 bytes of dynamic memory, leaving 2039 bytes
For local variables, max is 2048 byte

Bottom of Form

 

 

}

 

 

// loop keeps looking forever

 

PORTC |= (1<<PC2);

 

delay_ms(1000);

 

 

PORTC &= ~((1<<PC4) | (1<<PC2) );

 

while(1) {

 

 

 

}

 

return 0;

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO.Ports;

 

 

#define F_CPU 14745600

 

#include <avr/io.h>

#include <inttypes.h>

 

#include “../libnerdkits/delay.h”

#include “../libnerdkits/lcd.h”

namespace Servo_motor

{

public partial class Form1 : Form

{

public Form1()

{

 

InitializeComponent();

 

 

}

 

private void button1_Click(object sender, EventArgs e)

{

 

serialPort1.PortName = comboBox1.Text;

serialPort1.Open();

 

}

 

private void Form1_Load(object sender, EventArgs e)

{

comboBox1.DataSource = SerialPort.GetPortNames();

}

 

private void trackBar1_Scroll(object sender, EventArgs e)

{

 

if (serialPort1.IsOpen == true

{

 

int PWM = trackBar1.Value;

label2.Text = trackBar1.Value.ToString();

 

byte[] b = BitConverter.GetBytes(PWM);

serialPort1.Write(b, 0, 4);

 

}

}

}

}

 

//aurdino part:

 

#include <Servo.h>

 

Servo servoMotor;

int servoPin=13;

int value=0;

int angle;

int x;

 

void setup(){

Serial.begin(9600);

servoMotor.attach(servoPin);

}

 

void loop(){

if(Serial.available() >0)

{

value = Serial.read();

if(value>0){

x=value;

}

}

else if (x>=0 && x<=180){

angle=x;

servoMotor.write(angle);

}

}

//most of the code is aurdino made of.

//regulating the LEDs only one is on at a time

//electric surge taken care of.